![]() target_sources(): All The Advantages Without The Drawbacks Nevertheless, it is often used by developers new to CMake until they experience first hand the problems the technique introduces. While at first this may seem very attractive for its simplicity, this technique has a number of drawbacks and is actively discouraged by the CMake documentation. It also keeps the top level CMakeLists.txt file quite small and the CMakeLists.txt in each subdirectory also tends to be reasonably uncomplicated and focussed just on the things in that directory.Īs an alternative to explicitly building up a list of source files in a variable, some developers instead choose to let CMake find the source files and generate the contents of that variable automatically with the file(GLOB_RECURSE. This allows each subdirectory to define just the sources it provides and to delegate any further nested subdirectories with another include(). With the subdirectory files structured something like this: list(APPEND myApp_SOURCES # it doesn't have to be called CMakeLists.txt The top level CMakeLists.txt file then looks something like this: # The name of the included file could be anything, Then after all the subdirectories have been included, add_executable() or add_library() is called, but this time passing just the variable instead of an explicit list of files. ![]() The logical improvement many developers then make is to build up the list of source files in a variable as each subdirectory is pulled in via include(). It also results in having to repeat the directory structure, which reduces the benefit of structuring source files into directories in the first place. When the number of source files grows large and they get distributed over a number of subdirectories, possibly nested to multiple levels, this quickly becomes unwieldly. Eg: add_executable(myApp src1.cpp src2.cpp) ![]() Typically, developers first learn CMake in a very simple manner, defining a target by listing the source files directly in the add_executable() or add_library() command itself.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |