I have a CMakeLists.txt file for a library. It's pretty basic:
set(LIB_FILES source/first.cpp)
add_library(first ${LIB_FILES})
I put the files in a list because I will eventually be adding more source files to the library. The problem is that all of the files will be in the source
directory. And I don't want to constantly have to repeat that.
I also don't want to use the GLOB
pattern matching solution, because I want to have to edit the CMakeLists.txt file when I add a new file. That way, my build will re-build the build solution, and new files will correctly appear (as I understand it. I'm still new with CMake).
I tried adding a CMakeLists.txt file into the source
directory itself, just to build the LIB_FILES
list. That didn't work out very well. Variables in CMake are file scoped. And even when I broke scoping (with PARENT_SCOPE
), I still had to prefix each file with the directory. So that gained nothing.
I don't want to put the actual library definition in the source
directory, as that will generate all the build files in the source
directory. And I don't want that. Also, I will need to include headers that aren't in or under the source
directory.
My directory structure looks like this:
libroot (where the project build files should go)
\-source (where the source code is)
\-include (where the headers that the user of the library includes go)
So how do I tell CMake that all of the source files come from the source
directory, so that I don't have to constantly spell it out?