Skip to content
This repository was archived by the owner on Oct 22, 2025. It is now read-only.

Commit ce35185

Browse files
authored
Refactor CMake configurations and improve project structure (#159)
- Refactor CMake configurations and improve project structure - Updated CMake recipes for third-party libraries to set appropriate folder properties for IDE organization. - Changed the CPMAddPackage references for scalable-ccd to a more recent commit. - Enhanced logging functionality by adding a new `log_and_throw_error` function to improve error handling. - Improved documentation in the style guide for naming conventions. - Move generated `config.hpp` file from `src/ipc` to `build/include/src/ipc` - Update CUDA builds in `CMakePresets.json` - Remove `virtual` tag from BroadPhase::detect_collision_candidates
1 parent 050aae8 commit ce35185

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+222
-160
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ CMakeUserPresets.json
491491

492492

493493
## Build
494-
build*
494+
build/
495495
bin*
496496

497497
## IDES
@@ -658,6 +658,7 @@ ipctk
658658

659659
IPCToolkitOptions.cmake
660660

661+
# Generated HPP files
661662
src/ipc/config.hpp
662663
tests/src/tests/config.hpp
663664

CMakeLists.txt

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ if(IPC_TOOLKIT_WITH_CCACHE AND CCACHE_PROGRAM)
4444
endforeach()
4545
endif()
4646

47+
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
48+
4749
################################################################################
4850
# CMake Policies
4951
################################################################################
@@ -53,6 +55,7 @@ cmake_policy(SET CMP0076 NEW) # target_sources() command converts relative paths
5355
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.24")
5456
cmake_policy(SET CMP0135 NEW) # Set the timestamps of all extracted contents to the time of the extraction.
5557
endif()
58+
cmake_policy(SET CMP0114 NEW) # Support the Xcode "new build system"
5659

5760
################################################################################
5861

@@ -64,8 +67,16 @@ project(IPCToolkit
6467
include(CheckLanguage)
6568
check_language(CUDA)
6669

67-
option(IPC_TOOLKIT_BUILD_TESTS "Build unit-tests" ${IPC_TOOLKIT_TOPLEVEL_PROJECT})
68-
option(IPC_TOOLKIT_BUILD_PYTHON "Build Python bindings" OFF)
70+
if(IPC_TOOLKIT_TOPLEVEL_PROJECT)
71+
option(IPC_TOOLKIT_BUILD_TESTS "Build unit-tests" ON)
72+
option(IPC_TOOLKIT_BUILD_PYTHON "Build Python bindings" OFF)
73+
else()
74+
# If this is not the top-level project, we don't want to build tests or Python
75+
# bindings. This is useful for projects that use IPC Toolkit as a submodule.
76+
set(IPC_TOOLKIT_BUILD_TESTS OFF CACHE INTERNAL BOOL "Build unit-tests" FORCE)
77+
set(IPC_TOOLKIT_BUILD_PYTHON OFF CACHE INTERNAL BOOL "Build Python bindings" FORCE)
78+
endif()
79+
6980
if(CMAKE_CUDA_COMPILER)
7081
option(IPC_TOOLKIT_WITH_CUDA "Enable CUDA CCD" ON)
7182
else()
@@ -117,13 +128,21 @@ add_library(ipc::toolkit ALIAS ipc_toolkit)
117128
# Fill in configuration options
118129
configure_file(
119130
"${IPC_TOOLKIT_SOURCE_DIR}/config.hpp.in"
120-
"${IPC_TOOLKIT_SOURCE_DIR}/config.hpp")
131+
"${PROJECT_BINARY_DIR}/include/ipc/config.hpp")
121132

122133
# Add source and header files to ipc_toolkit
123134
add_subdirectory("${IPC_TOOLKIT_SOURCE_DIR}")
124135

125136
# Public include directory for IPC Toolkit
126-
target_include_directories(ipc_toolkit PUBLIC "${IPC_TOOLKIT_INCLUDE_DIR}")
137+
target_include_directories(ipc_toolkit PUBLIC
138+
"${IPC_TOOLKIT_INCLUDE_DIR}" # public headers
139+
"${PROJECT_BINARY_DIR}/include" # generated config.hpp
140+
)
141+
142+
# Folder name for IDE
143+
set_target_properties(ipc_toolkit PROPERTIES FOLDER "SRC")
144+
get_target_property(IPC_TOOLKIT_SOURCES ipc_toolkit SOURCES)
145+
source_group(TREE "${PROJECT_SOURCE_DIR}" FILES ${IPC_TOOLKIT_SOURCES})
127146

128147
################################################################################
129148
# Dependencies
@@ -243,7 +262,7 @@ endif()
243262
################################################################################
244263

245264
# Enable unit testing at the root level
246-
if(IPC_TOOLKIT_TOPLEVEL_PROJECT AND IPC_TOOLKIT_BUILD_TESTS)
265+
if(IPC_TOOLKIT_BUILD_TESTS)
247266
include(CTest)
248267
enable_testing()
249268
add_subdirectory(tests)
@@ -270,6 +289,21 @@ endif()
270289
# Python bindings
271290
################################################################################
272291

273-
if(IPC_TOOLKIT_TOPLEVEL_PROJECT AND IPC_TOOLKIT_BUILD_PYTHON)
292+
if(IPC_TOOLKIT_BUILD_PYTHON)
274293
add_subdirectory(python)
275294
endif()
295+
296+
################################################################################
297+
# Xcode
298+
################################################################################
299+
300+
if (CMAKE_GENERATOR STREQUAL "Xcode")
301+
set(CMAKE_XCODE_SCHEME_LAUNCH_CONFIGURATION "${CMAKE_BUILD_TYPE}")
302+
set_target_properties(ipc_toolkit PROPERTIES XCODE_GENERATE_SCHEME ON)
303+
if(IPC_TOOLKIT_BUILD_TESTS)
304+
set_target_properties(ipc_toolkit_tests PROPERTIES XCODE_GENERATE_SCHEME ON)
305+
endif()
306+
if(IPC_TOOLKIT_BUILD_PYTHON)
307+
set_target_properties(ipctk PROPERTIES XCODE_GENERATE_SCHEME ON)
308+
endif()
309+
endif()

CMakePresets.json

Lines changed: 39 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
"major": 3,
55
"minor": 18
66
},
7-
"configurePresets": [
8-
{
7+
"configurePresets": [{
98
"name": "release",
109
"displayName": "Release Build",
1110
"description": "Base preset for release builds",
@@ -33,11 +32,21 @@
3332
"binaryDir": "${sourceDir}/build/default"
3433
},
3534
{
36-
"name": "cuda",
35+
"name": "cuda-release",
3736
"inherits": "release",
38-
"displayName": "CUDA Enabled",
39-
"description": "Build with CUDA support",
40-
"binaryDir": "${sourceDir}/build/cuda",
37+
"displayName": "CUDA (Release)",
38+
"description": "Release build with CUDA support",
39+
"binaryDir": "${sourceDir}/build/cuda-release",
40+
"cacheVariables": {
41+
"IPC_TOOLKIT_WITH_CUDA": "ON"
42+
}
43+
},
44+
{
45+
"name": "cuda-debug",
46+
"inherits": "debug",
47+
"displayName": "CUDA (Debug)",
48+
"description": "Debug build with CUDA support",
49+
"binaryDir": "${sourceDir}/build/cuda-debug",
4150
"cacheVariables": {
4251
"IPC_TOOLKIT_WITH_CUDA": "ON"
4352
}
@@ -55,7 +64,7 @@
5564
{
5665
"name": "test",
5766
"inherits": "debug",
58-
"displayName": "Build for Testing",
67+
"displayName": "Unit Tests",
5968
"description": "Build with unit tests enabled",
6069
"binaryDir": "${sourceDir}/build/test",
6170
"cacheVariables": {
@@ -87,54 +96,52 @@
8796
"IPC_TOOLKIT_WITH_CODE_COVERAGE": "ON",
8897
"IPC_TOOLKIT_BUILD_TESTS": "ON"
8998
}
90-
},
91-
{
92-
"name": "debug-cuda",
93-
"inherits": [ "debug", "cuda" ],
94-
"displayName": "CUDA Debug",
95-
"description": "Debug build with CUDA support",
96-
"binaryDir": "${sourceDir}/build/debug-cuda"
9799
}
98100
],
99-
"buildPresets": [
100-
{
101+
"buildPresets": [{
101102
"name": "release",
102103
"configurePreset": "release",
104+
"displayName": "Release Build",
103105
"description": "Base preset for release builds"
104106
},
105107
{
106108
"name": "debug",
107109
"configurePreset": "debug",
110+
"displayName": "Debug Build",
108111
"description": "Base preset for debug builds"
109112
},
110113
{
111114
"name": "default-build",
112115
"configurePreset": "default",
116+
"displayName": "Default Configuration",
113117
"description": "Build using default configuration"
114118
},
115119
{
116-
"name": "cuda-build",
117-
"configurePreset": "cuda",
120+
"name": "cuda-release",
121+
"configurePreset": "cuda-release",
122+
"displayName": "CUDA (Release)",
118123
"description": "Build with CUDA support"
119124
},
125+
{
126+
"name": "cuda-debug",
127+
"configurePreset": "cuda-debug",
128+
"displayName": "CUDA (Debug)",
129+
"description": "Debug build with CUDA support"
130+
},
120131
{
121132
"name": "test-build",
122133
"configurePreset": "test",
134+
"displayName": "Unit Tests",
123135
"description": "Build for running tests"
124136
},
125137
{
126138
"name": "python-build",
127139
"configurePreset": "python",
140+
"displayName": "Python Bindings",
128141
"description": "Build with Python bindings enabled"
129-
},
130-
{
131-
"name": "debug-cuda-build",
132-
"configurePreset": "debug-cuda",
133-
"description": "Debug build with CUDA support"
134142
}
135143
],
136-
"testPresets": [
137-
{
144+
"testPresets": [{
138145
"name": "default-tests",
139146
"description": "Run default tests",
140147
"configurePreset": "test",
@@ -143,20 +150,20 @@
143150
}
144151
},
145152
{
146-
"name": "cuda-tests",
147-
"description": "Run tests with CUDA enabled",
148-
"configurePreset": "cuda",
153+
"name": "cuda-tests-release",
154+
"description": "Run tests with CUDA (Release) enabled",
155+
"configurePreset": "cuda-release",
149156
"execution": {
150157
"stopOnFailure": true
151158
}
152159
},
153160
{
154-
"name": "debug-cuda-tests",
155-
"description": "Run tests with CUDA Debug configuration",
156-
"configurePreset": "debug-cuda",
161+
"name": "cuda-tests-debug",
162+
"description": "Run tests with CUDA (Debug) enabled",
163+
"configurePreset": "cuda-debug",
157164
"execution": {
158165
"stopOnFailure": true
159166
}
160167
}
161168
]
162-
}
169+
}

cmake/recipes/abseil.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ message(STATUS "Third-party: creating target 'absl::flat_hash_map'")
99
option(ABSL_PROPAGATE_CXX_STD "Use CMake C++ standard meta features (e.g. cxx_std_11) that propagate to targets that link to Abseil" ON)
1010
option(ABSL_USE_SYSTEM_INCLUDES "Silence warnings in Abseil headers by marking them as SYSTEM includes" ON)
1111
option(ABSL_BUILD_TESTING "If ON, Abseil will build all of Abseil's own tests." OFF)
12+
set(ABSL_IDE_FOLDER "ThirdParty/Abseil")
1213

1314
include(CPM)
1415
CPMAddPackage("gh:abseil/abseil-cpp#20230125.3")

cmake/recipes/catch2.cmake

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,8 @@ option(CATCH_INSTALL_DOCS "Install documentation alongside library" OFF)
1111
option(CATCH_INSTALL_EXTRAS "Install extras alongside library" OFF)
1212

1313
include(CPM)
14-
CPMAddPackage("gh:catchorg/[email protected]")
14+
CPMAddPackage("gh:catchorg/[email protected]")
15+
16+
# Folder name for IDE
17+
set_target_properties(Catch2 PROPERTIES FOLDER "ThirdParty/Catch2")
18+
set_target_properties(Catch2WithMain PROPERTIES FOLDER "ThirdParty/Catch2")

cmake/recipes/evouga_ccd.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,6 @@ target_link_libraries(evouga_ccd PUBLIC Eigen3::Eigen)
2727

2828
# Turn off floating point contraction for CCD robustness
2929
target_compile_options(evouga_ccd PRIVATE "-ffp-contract=off")
30+
31+
# Folder name for IDE
32+
set_target_properties(evouga_ccd PROPERTIES FOLDER "ThirdParty")

cmake/recipes/filib.cmake

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,7 @@ message(STATUS "Third-party: creating target 'filib::filib'")
1212
option(FILIB_BUILD_SHARED_LIB "Build shared library" OFF)
1313

1414
include(CPM)
15-
CPMAddPackage("gh:zfergus/filib#7cf13519b0db72df2493c9c8997a8bef9e372848")
15+
CPMAddPackage("gh:zfergus/filib#7cf13519b0db72df2493c9c8997a8bef9e372848")
16+
17+
# Folder name for IDE
18+
set_target_properties(filib PROPERTIES FOLDER "ThirdParty")

cmake/recipes/finite_diff.cmake

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,7 @@ endif()
77
message(STATUS "Third-party: creating target 'finitediff::finitediff'")
88

99
include(CPM)
10-
CPMAddPackage("gh:zfergus/[email protected]")
10+
CPMAddPackage("gh:zfergus/[email protected]")
11+
12+
# Folder name for IDE
13+
set_target_properties(finitediff_finitediff PROPERTIES FOLDER "ThirdParty")

cmake/recipes/libigl.cmake

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,9 @@ set(LIBIGL_PREDICATES ON CACHE BOOL "Use exact predicates" FORCE)
1111
include(eigen)
1212

1313
include(CPM)
14-
CPMAddPackage("gh:libigl/libigl#89267b4a80b1904de3f6f2812a2053e5e9332b7e")
14+
CPMAddPackage("gh:libigl/libigl#89267b4a80b1904de3f6f2812a2053e5e9332b7e")
15+
16+
# Folder name for IDE
17+
foreach(target_name IN ITEMS core predicates)
18+
set_target_properties(igl_${target_name} PROPERTIES FOLDER "ThirdParty/libigl")
19+
endforeach()

cmake/recipes/onetbb.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ endif()
6767
foreach(name IN ITEMS tbb tbbmalloc tbbmalloc_proxy)
6868
if(TARGET ${name})
6969
# Folder name for IDE
70-
set_target_properties(${name} PROPERTIES FOLDER "third_party//tbb")
70+
set_target_properties(${name} PROPERTIES FOLDER "ThirdParty/tbb")
7171

7272
# Force debug postfix for library name. Our pre-compiled MKL library expects "tbb12.dll" (without postfix).
7373
set_target_properties(${name} PROPERTIES DEBUG_POSTFIX "")

0 commit comments

Comments
 (0)