Reputation: 96556
If I do FILE (GLOB "*.cpp")
where does it look? What is the working directory of the search? Is it the current source directory? This doesn't seem to be documented anywhere (although it is for FILE (COPY
).
Upvotes: 2
Views: 7132
Reputation: 537
You can also specify a RELATIVE path. I'm not sure when the RELATIVE
option was added, but it appears to be available from at least v3.0.2.
Upvotes: 3
Reputation: 2825
The FILE(GLOB globbing expression)
accepts paths in the globbing expression to. Thus you can include any path into the expression. The following example finds all files with extension dat in subfolder testdata:
file(GLOB files "${CMAKE_CURRENT_SOURCE_DIR}/testdata/*.dat")
Note: The usage of predefined path variables like CMAKE_CURRENT_SOURCE_DIR avoids any thinking about relative paths and made CMakeLists.txt more reusable and platform independent.
Bad:
file(GLOB generatedSources "../build-arm/autocode/*.c")
Good:
file(GLOB generatedSources "${PROJECT_BINARY_DIR}/autocode/*.c")
Upvotes: 2
Reputation: 5547
The search occurs in the current source directory, i.e. the directory of your CMakeLists.txt
.
As a side remark regarding what you want to achieve with this, I would emphasize the following:
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.
Upvotes: 0