-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
178 lines (159 loc) · 5.45 KB
/
Copy pathCMakeLists.txt
File metadata and controls
178 lines (159 loc) · 5.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
cmake_minimum_required(VERSION 3.20)
project(CPhysics LANGUAGES CXX C)
if(NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type" FORCE)
endif()
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
enable_testing()
option(CPHYSICS_WARNINGS_AS_ERRORS "Treat warnings as errors" OFF)
# ---- Engine ---------------------------------------------------------------
set(CPHYSICS_ENGINE_SOURCES
src/Arbiter.cpp
src/Body.cpp
src/Circle.cpp
src/Joint.cpp
src/JointToBody.cpp
src/JointToPoint.cpp
src/ParticleExplosion.cpp
src/Polygon.cpp
src/ProximityExplosion.cpp
src/Ray.cpp
src/RaycastExplosion.cpp
src/Rayscatter.cpp
src/Shadowcast.cpp
src/Slice.cpp
src/World.cpp
)
add_library(cphysics STATIC ${CPHYSICS_ENGINE_SOURCES})
target_include_directories(cphysics
PUBLIC
"${CMAKE_CURRENT_SOURCE_DIR}/include"
)
target_compile_features(cphysics PUBLIC cxx_std_17)
target_compile_options(cphysics
PRIVATE
$<$<CXX_COMPILER_ID:MSVC>:/W3 /permissive->
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wall -Wextra>
)
if(CPHYSICS_WARNINGS_AS_ERRORS)
target_compile_options(cphysics
PRIVATE
$<$<CXX_COMPILER_ID:MSVC>:/WX>
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Werror>
)
endif()
# ---- Window/GL system deps (resolved once, used by imgui + testbed) -------
find_package(OpenGL REQUIRED)
find_package(glfw3 CONFIG QUIET)
if(NOT TARGET glfw AND NOT TARGET glfw3)
include(FetchContent)
set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
FetchContent_Declare(
glfw
GIT_REPOSITORY https://github.com/glfw/glfw.git
GIT_TAG 3.4
)
FetchContent_MakeAvailable(glfw)
endif()
# Normalize: some packagers expose the target as `glfw3`, FetchContent uses `glfw`.
if(TARGET glfw)
set(CPHYSICS_GLFW_TARGET glfw)
else()
set(CPHYSICS_GLFW_TARGET glfw3)
endif()
# ---- Vendored third-party (no -Werror, no -Wall) --------------------------
#
# These targets compile vendored code that we do not maintain. They are
# intentionally excluded from the project's warning discipline so warnings
# in upstream sources cannot break the build.
add_library(cphysics_glad STATIC third_party/GLAD/src/glad.c)
target_include_directories(cphysics_glad
PUBLIC
"${CMAKE_CURRENT_SOURCE_DIR}/third_party/GLAD/include"
)
add_library(cphysics_imgui STATIC
third_party/imgui/imgui.cpp
third_party/imgui/imgui_draw.cpp
third_party/imgui/imgui_widgets.cpp
third_party/imgui/imgui_impl_glfw.cpp
third_party/imgui/imgui_impl_opengl3.cpp
)
target_include_directories(cphysics_imgui
PUBLIC
"${CMAKE_CURRENT_SOURCE_DIR}/third_party"
"${CMAKE_CURRENT_SOURCE_DIR}/third_party/imgui"
)
# imgui_impl_opengl3.h auto-detects the GL loader from headers on the include
# path; expose GLAD publicly so consumers including that header pick it up.
target_link_libraries(cphysics_imgui PUBLIC ${CPHYSICS_GLFW_TARGET} cphysics_glad)
# ---- Testbed --------------------------------------------------------------
add_executable(cphysics_testbed
testbed/Main.cpp
testbed/Render.cpp
testbed/Test.cpp
testbed/Tests/BouncingBall.cpp
testbed/Tests/Chains.cpp
testbed/Tests/Drag.cpp
testbed/Tests/Friction.cpp
testbed/Tests/LineOfSight.cpp
testbed/Tests/MixedShapes.cpp
testbed/Tests/NewtonsCradle.cpp
testbed/Tests/ParticleExplosionTest.cpp
testbed/Tests/ProximityExplosionTest.cpp
testbed/Tests/Raycast.cpp
testbed/Tests/RaycastExplosionTest.cpp
testbed/Tests/Restitution.cpp
testbed/Tests/SliceObjects.cpp
testbed/Tests/StackedObjects.cpp
testbed/Tests/Trebuchet.cpp
testbed/Tests/Wreckingball.cpp
)
target_compile_features(cphysics_testbed PRIVATE cxx_std_17)
target_compile_options(cphysics_testbed
PRIVATE
$<$<CXX_COMPILER_ID:MSVC>:/W3 /permissive->
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wall -Wextra>
)
if(CPHYSICS_WARNINGS_AS_ERRORS)
target_compile_options(cphysics_testbed
PRIVATE
$<$<CXX_COMPILER_ID:MSVC>:/WX>
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Werror>
)
endif()
target_include_directories(cphysics_testbed
PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/third_party" # cereal
"${CMAKE_CURRENT_SOURCE_DIR}/testbed" # Settings.h, Colour.h, Tests/...
)
target_link_libraries(cphysics_testbed
PRIVATE
cphysics
cphysics_glad
cphysics_imgui
${CPHYSICS_GLFW_TARGET}
OpenGL::GL
)
set_target_properties(cphysics_testbed
PROPERTIES
VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/testbed"
)
# ---- Tests ----------------------------------------------------------------
add_executable(cphysics_geometry_regression tests/GeometryRegression.cpp)
target_compile_features(cphysics_geometry_regression PRIVATE cxx_std_17)
target_compile_options(cphysics_geometry_regression
PRIVATE
$<$<CXX_COMPILER_ID:MSVC>:/W3 /permissive->
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wall -Wextra>
)
if(CPHYSICS_WARNINGS_AS_ERRORS)
target_compile_options(cphysics_geometry_regression
PRIVATE
$<$<CXX_COMPILER_ID:MSVC>:/WX>
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Werror>
)
endif()
target_link_libraries(cphysics_geometry_regression PRIVATE cphysics)
add_test(NAME geometry_regression COMMAND cphysics_geometry_regression)