-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Do not use file(GLOB) to add files to build configuration #4
Comments
From the CMake documentation of Note: We do not recommend using GLOB to collect a list of source files from your source tree. If no CMakeLists.txt file changes when a source is added or removed then the generated build system cannot know when to ask CMake to regenerate. |
We already discussed this indeed. That being said, |
I stand corrected, I do use globbing on the PolyData module source files. The other modules have explicit listing of the source files. |
I can see the argument for using globbing for header files, but I still don't think it's good practice no matter how many examples there may be of projects wrongly using it. What speaks against it is what I commented in #13, that header files must be listed as target dependencies or else the target will not be rebuild when a header file is modified. But every source file that is declared as target dependency should be listed explicitly and not be globbed as also recommended by the CMake developers. You can use some custom auxiliary target as I've done in CMake BASIS to work around the limitations in CMake and render globbing a valid option. But without this, globbing should be shamed... |
The use of CMake's
file(GLOB)
is highly discouraged for globbing source files to be added to a build target. The main reason being that CMake will not notice that files have been added/removed/renamed after the last configuration of the build tree and thus not automatically re-run. A developer must remember to manually run CMake again whenever such file change took place.The basis_add_glob_target CMake function and related files/functions from my CMake BASIS project could be copied which indeed allows to glob for source files, but adds a custom target which ensures during each build run that the set of files matching the glob expression has not changed.
The text was updated successfully, but these errors were encountered: