11/6/2023 0 Comments Cmake glob sources with exceptions![]() ![]() What we do instead is, when you yourself add, remove, or rename source files locally, just touch CMakeLists.txt to trigger CMake to rerun. So instead of banning GLOB, you could just require developers to change one character in a CMakeLists.txt file whenever they add, remove, or rename a source file! ![]() So ban GLOB, problem solved!īut really any modification to CMakeLists.txt accomplishes the same goal of triggering CMake to rerun. Banning GLOB thus forces developers to modify the CMakeLists.txt file whenever they add, remove, or rename a source file, which triggers a new build. What makes GLOB problematic is that the build system has no way to know when source files are added, removed, or renamed, so it doesn't know to rerun CMake when that happens. No source files in the source tree that aren't actually getting built distracting developers, who wonder "how can this old code still work.?" only to eventually realize that it's not being compiled.No more issues where a Windows developer adds a file to CMakeLists.txt with the wrong case, breaking the Linux build.Much shorter/easier to maintain CMakeLists.txt files.We use GLOB in our CMake files and it works great. Note: If the daemon is shutdown (system reboot) then the state is now unknown and all glob patterns will need to be re-evaluated. This solution offloads the overhead of continuous glob evaluation to a background process and will have the best of both worlds at the cost of increased complexity for the systems engineer. Monitor Filesystem Changes - A build system can spin up a background daemon to listen for file system changes that would impact the results of previous glob evaluations.This design has better incremental build performance, but can no longer guarantee an incremental build is equivalent to a full build. A build may detect deleted files, but will miss new files unless a user remembers to "force" a rebuild by touching the build definition. Cache globbed evaluation - The build will evaluate the glob patterns only when the build definition changes.This adds overhead to incremental builds and slows down the inner development loop for every invocation. Glob Source always evaluated - The build will re-evaluate ALL glob patterns for ALL incremental build to determine if the file system has changed since the last build.The big downside is large build definitions that increase maintenance costs. Any change to the input file set will invalidate the build definition and force a rebuild. Explicitly define all inputs - Allows for the build to know exactly what it needs to build and allows for very fast incremental build checks.There are four general ways to handle incremental builds: Globbing is amazing from a usability perspective but makes it very hard to have performant incremental builds with guaranteed correctness. Collecting sources *.This is a design decision where build systems must choose between incremental build speed and correctness over usability and CMake has to work toward the least common denominator. Powershell -Command "$path = '%1'.Replace('\','/') $headers = New-Object ls -Name $path/*.%2 | foreach-object/include h HEADERS)ĬMake output: - Collecting sources *.h from C:/Repos/cmake-scanner/includeĬ:/Repos/cmake-scanner/include/IPublicA.hĬ:/Repos/cmake-scanner/include/IPublicB.hĬ:/Repos/cmake-scanner/include/IPublicC.hĬ:/Repos/cmake-scanner/include/IPublicD.h Recieved-batch: C:/Repos/cmake-scanner/src/main.cpp While I still want to know how to achieve the initial intent, I am extremely confused about the reason why totally identical strings compare to false:ĬMake log: - Manually-typed: C:/Repos/cmake-scanner/src/main.cpp The path is (visually) correct: if I manually type it into add_executable, generating will succeed. Though it seems that the output is totally correct, CMake can not find those files. So I though of getting a list of sources via invoking a batch script in CMakeLists.īut something is wrong. One answer from this question suggests to use ls *.cpp into CMakeLists.txt. I don't want to use GLOBbing, and also couldn't find any examples of an approach using only cmake. I want to collect all the source or header files from a specified folder, also matching a curtain naming convention. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |