c++ - CMake -- Add all sources in subdirectory to cmake project -


Complying with this question:

What is the best approach (perhaps using the FILE command ?) To select all .cpp and .h files in the subdirectory and add them to the defined SOURCE variable in the root directory?


For example, above the answer to the question:

  set (source $ {source} $ {CMAKE_CURRENT_SOURCE_DIR} /file1.cpp $ {CMAKE_CURRENT_SOURCE_DIR } /file2.cpp PARENT_SCOPE) set (header $ {header} $ {CMAKE_CURRENT_SOURCE_DIR} / file1 .hpp $ {CMAKE_CURRENT_SOURCE_DIR} /file2.hpp PARENT_SCOPE)  

to do something like this possible?

  file (GLOB SUB_SOURCES * CPP) set (source $ {source} $ {CMAKE_CURRENT_SOURCE_DIR} / $ {SUB_SOURCES} PARENT_SCOPE)  

What is the best way

I think what you're looking for is the aux_source_directory command.

aux_source_directory Locate all source files in a directory.

aux_source_directory ()

List of all source files included in the specified directory and the list provided in the store. This order is intended to be used by projects that use clear templates instantly . Template Instant Files can be stored in the "Template" subdirectory and this command can be used automatically to avoid listing these commands manually.

This is the list of source files for the library or the executable goal, though it seems to be working, there is no way to create a build system that knows that when a new source file has been added. Usually the Generated Building System knows that when it needs to run Simmer again because the CMakeLists.txt file has been modified to add a new source. When the source is added to the directory without modifying this file, then one has to do it again to manually create the build system that includes the new file manually.

Your CMakeLists.txt will look like this in the subdirectory:

  set aux_source_directory ($ {CMAKE_CURRENT_SOURCE_DIR} SUB_SOURCES) (source $ {source} $ { SUB_SOURCES} PARENT_SCOPE)  

The recommended method is however, as you see from documentation, change the CMakeLists.txt file to list files individually within CMakeLists.txt The cmake turns on.

I hope it was helpful and at the point.


Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -