Skip to content

Commit

Permalink
CMake: Fix new FLAMEGPU source_group rules when build is not a child …
Browse files Browse the repository at this point in the history
…of FLAMEGPU_ROOT

Due to the dynamic version.cpp file, which is placed in the build directory, source_group TREE could fail when the build directory was not a child of FLAMEGPU_ROOT.
I.e. when FLAMEGPU/FLAMEGPU2 is fetched via CMake FetchContent.

This applies similar filtering to examples, where source_group(TREE) is only used when appropriate.
  • Loading branch information
ptheywood committed Sep 22, 2023
1 parent dd86e00 commit 1269658
Showing 1 changed file with 39 additions and 2 deletions.
41 changes: 39 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -408,16 +408,53 @@ SET(ALL_SRC
SET(FLAMEGPU_INCLUDE ${SRC_INCLUDE} CACHE INTERNAL "Include files required by FLAMEGPU RTC")

# Setup Visual Studio (and eclipse) filters, using the TREE variant separating header and source files.
set(SRC_GROUP_TREE_COMPATIBLE_HEADERS "${ALL_SRC}")
# Potentially the build directory is not a child of the repository,
# in which case dynamic files (version.cpp) cannot use the tree component, so we must account for that still.

# Get a regex escaped represenatation of the FLAMEGPU_ROOT dir, for paths containg + etc.
escape_regex("${FLAMEGPU_ROOT}" FLAMEGPU_ROOT_ESCAPE)

# Convert all paths to abs paths, to remove any ../ components
set(ABS_ALL_SRC "")
foreach(FILEPATH IN LISTS ALL_SRC)
get_filename_component(ABS_FILEPATH ${FILEPATH} REALPATH)
list(APPEND ABS_ALL_SRC ${ABS_FILEPATH})
unset(ABS_FILEPATH)
endforeach()

# Filter files which cannot be used with sourge_group(TREE) into separate lists.
set(SRC_GROUP_TREE_COMPATIBLE "${ABS_ALL_SRC}")
set(SRC_GROUP_MANUAL "${ABS_ALL_SRC}")
list(FILTER SRC_GROUP_TREE_COMPATIBLE INCLUDE REGEX "^${FLAMEGPU_ROOT_ESCAPE}/")
list(FILTER SRC_GROUP_MANUAL EXCLUDE REGEX "^${FLAMEGPU_ROOT_ESCAPE}/")
unset(ABS_ALL_SRC)

# Filter out header and source files separately for those which can use TREE
set(SRC_GROUP_TREE_COMPATIBLE_HEADERS "${SRC_GROUP_TREE_COMPATIBLE}")
list(FILTER SRC_GROUP_TREE_COMPATIBLE_HEADERS INCLUDE REGEX ".*\.(h|hpp|cuh)$")
set(SRC_GROUP_TREE_COMPATIBLE_SOURCES "${ALL_SRC}")
set(SRC_GROUP_TREE_COMPATIBLE_SOURCES "${SRC_GROUP_TREE_COMPATIBLE}")
list(FILTER SRC_GROUP_TREE_COMPATIBLE_SOURCES EXCLUDE REGEX ".*\.(h|hpp|cuh)$")
# Apply source group filters with TREE, using CMake's default "Header Files" and "Source Files" for consistency
source_group(TREE ${FLAMEGPU_ROOT} PREFIX "Header Files" FILES ${SRC_GROUP_TREE_COMPATIBLE_HEADERS})
source_group(TREE ${FLAMEGPU_ROOT} PREFIX "Source Files" FILES ${SRC_GROUP_TREE_COMPATIBLE_SOURCES})
# Clean up variables
unset(SRC_GROUP_TREE_COMPATIBLE_HEADERS)
unset(SRC_GROUP_TREE_COMPATIBLE_SOURCES)
unset(SRC_GROUP_TREE_COMPATIBLE)

# Filter out header and source files which CANNOT use TREE (dynamic files if build is not a child of the repo, i.e. model template)
set(SRC_GROUP_MANUAL_HEADERS "${SRC_GROUP_MANUAL}")
list(FILTER SRC_GROUP_MANUAL_HEADERS INCLUDE REGEX ".*\.(h|hpp|cuh)$")
set(SRC_GROUP_MANUAL_SOURCES "${SRC_GROUP_MANUAL}")
list(FILTER SRC_GROUP_MANUAL_SOURCES EXCLUDE REGEX ".*\.(h|hpp|cuh)$")
# Apply source group filters WITHOUT TREE, using CMake's default "Header Files" and "Source Files" for consistency
# These will just be placed in the root of the folder, as we cannot have a ../ type setup in sources, so no point bothering with directories
source_group("Header Files" FILES ${SRC_GROUP_MANUAL_HEADERS})
source_group("Source Files" FILES ${SRC_GROUP_MANUAL_SOURCES})
# Clean up variables
unset(SRC_GROUP_MANUAL_HEADERS)
unset(SRC_GROUP_MANUAL_SOURCES)
unset(SRC_GROUP_MANUAL)

# Create the library target and set various properties

Expand Down

0 comments on commit 1269658

Please sign in to comment.