This forum has been archived. All content is frozen. Please use KDE Discuss instead.

CMake multiple sub-directories

Tags: None
(comma "," separated)
inktomi
Registered Member
Posts
5
Karma
0

CMake multiple sub-directories

Thu Sep 17, 2009 12:14 am
Hi,

I'm trying to get CMake work with multiple subdirectories for the same target. I'm using add_subdirectory(...) and then I'm using set(...). The problem is that although the value of the variable being set is inherited. at the top level it is not changing. Presently the top level CMakeList looks like this:

Code: Select all
project(TestApp)
cmake_minimum_required(VERSION 2.6)
find_package(Qt4 REQUIRED)

include_directories(${QT_INCLUDES} ${CMAKE_CURRENT_BINARY_DIR})

set(TestApp_SRCS TestApp.cpp main.cpp)

add_subdirectory(ui)

qt4_automoc(${TestApp_SRCS})
add_executable(TestApp ${TestApp_SRCS})
target_link_libraries(TestApp ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY})


In the ui subdirectory, I have another CMakeLists with the following content

Code: Select all
set(TestApp_SRCS ${TestApp_SRCS} mywidget.cpp)


I'm getting linker errors, and using message(${TestApp_SRCS}) after including the ui subdir, shows that mywidget.cpp was not appended to the variable. However at the ui level, mywidget.cpp is being appended properly.

Can anyone please explain how this should be done?
Thank you in advance
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS
add_subdirectory() is only needed when having completely different executables, etc. across directories.

Therefore you should add everything from the top level CMakeLists.txt file, using directory/file in the set() command.


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
inktomi
Registered Member
Posts
5
Karma
0

Re: CMake multiple sub-directories

Fri Sep 18, 2009 7:25 pm
Thank you.

That worked fine.


Bookmarks



Who is online

Registered users: Bing [Bot], claydoh, Google [Bot], rblackwell