Bug 309687

Summary: Variables defined in the CMakeLists.txt of a parent directory are not propagated to the CMakeLists.txt of the subdirectories
Product: [Applications] kdevelop Reporter: Daniel Calviño Sánchez <danxuliu>
Component: Build tools: CMakeAssignee: kdevelop-bugs-null
Status: RESOLVED FIXED    
Severity: normal    
Priority: NOR    
Version: git master   
Target Milestone: 4.3.0   
Platform: unspecified   
OS: Linux   
Latest Commit: Version Fixed In:
Attachments: Unit test for CMakeManagerTest showing the bug

Description Daniel Calviño Sánchez 2012-11-07 11:05:26 UTC
Created attachment 75073 [details]
Unit test for CMakeManagerTest showing the bug

This is a regression introduced in revision 3cdae4ad (https://projects.kde.org/projects/extragear/kdevelop/kdevelop/repository/revisions/3cdae4ad96a3a67ca1fd426509fbe161f38b4ead).

Variables defined in the CMakeLists.txt of a parent directory are not propagated to the CMakeLists.txt of the subdirectories.

Take, for example, a project with just a single subdirectory. The CMakeLists.txt from the root directory calls "find_package(XXX)", which defines the variable XXX_FOUND if XXX was found. Then, in the subdirectory, an executable is added only if XXX was found. The current CMakeManager doesn't add a target for the executable in the subdirectory even if XXX was found, whereas CMake (2.8.7) and CMakeManager before the revision 3cdae4ad do.

I have attached a unit test for CMakeManager that shows the problem. It adds a project to "projectmanagers/cmake/tests/manual/", which contains a root directory and a subdirectory. Both the CMakeLists.txt of the root directory and the CMakeLists.txt of the subdirectory add three executables: one without any condition, one if a custom variable is true, and another one if the QT4_FOUND variable is true. The source file for the three executables in each directory is the foo.cpp file of that directory. The custom variable is set in the CMakeLists.txt of the root directory, and the call to "find_package(QT4)" is also made in the CMakeLists.txt of the root directory (both before calling to add_subdirectory).

The unit test checks that there are four project items for foo.cpp and four project items for subdirectory/foo.cpp. Those four project items should be one item for the foo.cpp file itself, and three items for the targets (given that the unit tests belong to KDevelop, it is assumed that Qt4 is found).

The unit test fails. The four project items for foo.cpp are found, but only two project items are found for subdirectory/foo.cpp (the file itself and the executable without conditions). However, if the project is manually built with CMake, the three executables are added to the subdirectory. The unit test passes too if KDevelop is reverted to the parent commit of the one given above.

This bug could be somehow related to https://bugs.kde.org/show_bug.cgi?id=238455
Comment 1 Aleix Pol 2012-11-15 02:51:06 UTC
Git commit df00d058fcce0d4026704aeffbb6802dd9582433 by Aleix Pol.
Committed on 15/11/2012 at 03:48.
Pushed by apol into branch 'master'.

Fix subdirectory scoping in cmake projects

Don't pop the scope until all the subdirectories have been processed.

Thanks to Daniel Calviño Sánchez for such a helpful bug report :)
Related: bug 238455

M  +6    -3    projectmanagers/cmake/cmakemanager.cpp
M  +27   -0    projectmanagers/cmake/tests/cmakemanagertest.cpp
M  +1    -0    projectmanagers/cmake/tests/cmakemanagertest.h

http://commits.kde.org/kdevelop/df00d058fcce0d4026704aeffbb6802dd9582433
Comment 2 Daniel Calviño Sánchez 2012-11-15 10:58:22 UTC
(In reply to comment #1)
> Thanks to Daniel Calviño Sánchez for such a helpful bug report :)

Glad to help :)

> M  +6    -3    projectmanagers/cmake/cmakemanager.cpp
> M  +27   -0    projectmanagers/cmake/tests/cmakemanagertest.cpp
> M  +1    -0    projectmanagers/cmake/tests/cmakemanagertest.h
> 
> http://commits.kde.org/kdevelop/df00d058fcce0d4026704aeffbb6802dd9582433

It looks like you missed to add "projectmanagers/cmake/tests/manual/conditions_in_subdirectory_based_on_root_variables". The unit test fails without it even if the bug was fixed ;)
Comment 3 Aleix Pol 2012-11-16 01:49:07 UTC
Git commit b4772e0493cc3442871d0f6779053ca03745689e by Aleix Pol.
Committed on 16/11/2012 at 02:48.
Pushed by apol into branch '4.4'.

Forgot to add the unit test input!

A  +19   -0    projectmanagers/cmake/tests/manual/conditions_in_subdirectory_based_on_root_variables/CMakeLists.txt
A  +3    -0    projectmanagers/cmake/tests/manual/conditions_in_subdirectory_based_on_root_variables/conditions_in_subdirectory_based_on_root_variables.kdev4
A  +2    -0    projectmanagers/cmake/tests/manual/conditions_in_subdirectory_based_on_root_variables/foo.cpp     [License: UNKNOWN]  *
A  +9    -0    projectmanagers/cmake/tests/manual/conditions_in_subdirectory_based_on_root_variables/subdirectory/CMakeLists.txt
A  +2    -0    projectmanagers/cmake/tests/manual/conditions_in_subdirectory_based_on_root_variables/subdirectory/foo.cpp     [License: UNKNOWN]  *

The files marked with a * at the end have a non valid license. Please read: http://techbase.kde.org/Policies/Licensing_Policy and use the headers which are listed at that page.


http://commits.kde.org/kdevelop/b4772e0493cc3442871d0f6779053ca03745689e
Comment 4 Aleix Pol 2012-11-16 02:41:04 UTC
Git commit aef8dfad6b8e397ca645a2d0e97dce087a23bbfa by Aleix Pol.
Committed on 16/11/2012 at 02:48.
Pushed by apol into branch 'master'.

Forgot to add the unit test input!

A  +19   -0    projectmanagers/cmake/tests/manual/conditions_in_subdirectory_based_on_root_variables/CMakeLists.txt
A  +3    -0    projectmanagers/cmake/tests/manual/conditions_in_subdirectory_based_on_root_variables/conditions_in_subdirectory_based_on_root_variables.kdev4
A  +2    -0    projectmanagers/cmake/tests/manual/conditions_in_subdirectory_based_on_root_variables/foo.cpp     [License: UNKNOWN]  *
A  +9    -0    projectmanagers/cmake/tests/manual/conditions_in_subdirectory_based_on_root_variables/subdirectory/CMakeLists.txt
A  +2    -0    projectmanagers/cmake/tests/manual/conditions_in_subdirectory_based_on_root_variables/subdirectory/foo.cpp     [License: UNKNOWN]  *

The files marked with a * at the end have a non valid license. Please read: http://techbase.kde.org/Policies/Licensing_Policy and use the headers which are listed at that page.


http://commits.kde.org/kdevelop/aef8dfad6b8e397ca645a2d0e97dce087a23bbfa