Skip to content
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

Open
schuhschuh opened this issue Dec 12, 2015 · 5 comments
Open

Do not use file(GLOB) to add files to build configuration #4

schuhschuh opened this issue Dec 12, 2015 · 5 comments

Comments

@schuhschuh
Copy link
Member

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.

@schuhschuh
Copy link
Member Author

From the CMake documentation of file(GLOB):

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.

@ghisvail
Copy link
Member

We already discussed this indeed. That being said, globbing, or install directory, is super common to use for header files in many cmake projects. I agree that source files should be explicitly listed (and they are), since there are some conditional implementation of the public API defined in the headers due to the (non-)availability of certain dependencies.

@ghisvail
Copy link
Member

I agree that source files should be explicitly listed (and they are)

I stand corrected, I do use globbing on the PolyData module source files. The other modules have explicit listing of the source files.

@schuhschuh
Copy link
Member Author

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...

@schuhschuh
Copy link
Member Author

PR #33 also gets rid of the .cc file glob in the PolyData module. Still remains the issue that generally header files are globed and missing from the target dependencies (#13).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants