0

I have a directory tree like this:

libs support db csv patterns support_qt helpers dialogs 

etc.

Now when I do the add_subdirectory in the support level, I can add db and patterns and the files are collected. However in db I added another add_subdirectory referencing the csv, but somehow this is ignored.

In support

set(SUPPORT_SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/support_defs.h ${CMAKE_CURRENT_SOURCE_DIR}/support_dll_api.h ${CMAKE_CURRENT_SOURCE_DIR}/supportlib_namespace.h ${CMAKE_CURRENT_SOURCE_DIR}/dll_main.cpp ) add_subdirectory (db) add_subdirectory (patterns) 

In db

set(SUPPORT_SOURCE ${SUPPORT_SOURCE} ${CMAKE_CURRENT_SOURCE_DIR}/column_types.h ${CMAKE_CURRENT_SOURCE_DIR}/dbcolumn.h ${CMAKE_CURRENT_SOURCE_DIR}/database_login.h ${CMAKE_CURRENT_SOURCE_DIR}/database_login.cpp ${CMAKE_CURRENT_SOURCE_DIR}/type_helper.h ${CMAKE_CURRENT_SOURCE_DIR}/type_helper.cpp PARENT_SCOPE ) add_subdirectory(csv) 

The above works fine but in csv

set(SUPPORT_SOURCE ${SUPPORT_SOURCE} ${CMAKE_CURRENT_SOURCE_DIR}/csv.h ${CMAKE_CURRENT_SOURCE_DIR}/csv.cpp PARENT_SCOPE ) 

But these files are not included in the build. So do I have to put the add_subdirectory calls all into the root file?

1
  • 1
    The PARENT_SCOPE goes only one level up. I think you are better off with a CACHE INTERNAL, global variable, like this set(SUPPORT_SOURCE ${SUPPORT_SOURCE} ${CMAKE_CURRENT_SOURCE_DIR}/dbcolumn.h [...] CACHE INTERNAL "") But I am not sure how it works with a variable set multiple times. Commented Jun 4, 2015 at 12:04

1 Answer 1

0

Just found the solution. I have to put the add_subdirectory before the set command.

add_subdirectory(csv) set(SUPPORT_SOURCE ${SUPPORT_SOURCE} ${CMAKE_CURRENT_SOURCE_DIR}/column_types.h ${CMAKE_CURRENT_SOURCE_DIR}/dbcolumn.h ${CMAKE_CURRENT_SOURCE_DIR}/database_login.h ${CMAKE_CURRENT_SOURCE_DIR}/database_login.cpp ${CMAKE_CURRENT_SOURCE_DIR}/type_helper.h ${CMAKE_CURRENT_SOURCE_DIR}/type_helper.cpp PARENT_SCOPE ) 
Sign up to request clarification or add additional context in comments.

5 Comments

For big projects, it's usually fine to use globbing expressions.
But with globbing it would also find generated files, right? Also I have some files which are not included in the lib, but are still in that directory tree.
@Antonio I personally avoid globbing, see stackoverflow.com/a/18538444/678093
@m.s. Globbing saves a lot of tedious and uninformative cmake code. It has to be done carefully though, on this I agree. For example, we use git hooks to trigger cmake to run at the next build after pulling from the repository. Let's link also the other, more popular, answer :)
@Devolus Sure, it will find anything your globbing expression matches. You can decide to have a very wide globbing expression, and exclude the rare extra files (there are plenty of Q/A in this sense: stackoverflow.com/q/16449676/2436175 stackoverflow.com/q/15550777/2436175 stackoverflow.com/q/13114680/2436175). Or you can use a more specific globbing function to get only get the files/directories you need.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.