-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
429 lines (359 loc) · 13.6 KB
/
Copy pathCMakeLists.txt
File metadata and controls
429 lines (359 loc) · 13.6 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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
# Minimum CMake version
cmake_minimum_required(VERSION 3.15)
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
project(hello_worlds)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
if($ENV{ROS_VERSION} AND $ENV{ROS_VERSION} STREQUAL "2")
find_package(ament_cmake)
message(STATUS "Configuring for ROS 2 using ament_cmake...")
set(ROS_BUILD_TYPE "ROS2")
elseif($ENV{ROS_VERSION} AND $ENV{ROS_VERSION} STREQUAL "1")
find_package(catkin COMPONENTS)
message(STATUS "Configuring for ROS 1 using catkin...")
set(ROS_BUILD_TYPE "ROS1")
catkin_package(
# We don't need to specify LIBRARIES, CATKIN_DEPENDS, or DEPENDS
# since your library doesn't depend on other ROS packages
)
else()
message(STATUS "Configuring for Standalone (No ROS) build...")
set(ROS_BUILD_TYPE "STANDALONE")
include(GNUInstallDirs)
endif()
find_package(glm CONFIG REQUIRED)
find_package(Freetype REQUIRED)
find_package(PkgConfig REQUIRED)
find_package(assimp REQUIRED)
find_package(Threads REQUIRED)
pkg_check_modules(TINYXML2 REQUIRED tinyxml2)
include(FetchContent)
include(CheckLanguage)
include(GNUInstallDirs)
set(CAD_FILES
models/basic_shapes/cube.obj
models/basic_shapes/cylinder.obj
models/basic_shapes/sphere.obj
)
set(SHADER_FILES
shaders/color_shader.fs
shaders/color_shader.vs
shaders/depth_prepass.fs
shaders/depth_prepass.vs
shaders/depth_shader.fs
shaders/depth_shader.gs
shaders/depth_shader.vs
shaders/depthcube_shader.fs
shaders/depthcube_shader.gs
shaders/depthcube_shader.vs
shaders/geometry.fs
shaders/geometry.vs
shaders/light_shader.fs
shaders/light_shader.vs
shaders/lighting.fs
shaders/lighting.vs
shaders/screen_shader.fs
shaders/screen_shader.vs
shaders/sky_shader.fs
shaders/sky_shader.vs
shaders/ssao_blur.fs
shaders/ssao_blur.vs
shaders/ssao.fs
shaders/ssao.vs
shaders/text_shader.fs
shaders/text_shader.vs
)
# --- Embeded files ---
set(EMBEDDED_SUBDIR "hello_worlds_embedded")
set(EMBEDDED_DIR "${CMAKE_CURRENT_BINARY_DIR}/${EMBEDDED_SUBDIR}")
file(MAKE_DIRECTORY "${EMBEDDED_DIR}")
set(CAD_HEADERS "")
set(SHADER_HEADERS "")
function(embed_file_list file_list output_header_list_name)
foreach(RESOURCE_PATH ${${file_list}})
get_filename_component(BASE_NAME "${RESOURCE_PATH}" NAME)
string(REPLACE "." "_" VAR_NAME "${BASE_NAME}")
set(GENERATED_HEADER "${EMBEDDED_DIR}/embedded_${BASE_NAME}.h")
add_custom_command(
OUTPUT ${GENERATED_HEADER}
COMMAND ${CMAKE_COMMAND} -DINPUT_FILE="${CMAKE_CURRENT_SOURCE_DIR}/${RESOURCE_PATH}"
-DOUTPUT_HEADER=${GENERATED_HEADER}
-DVAR_NAME=${VAR_NAME}
-P "${CMAKE_CURRENT_SOURCE_DIR}/ResourceEmbed.cmake"
DEPENDS "${RESOURCE_PATH}"
COMMENT "Embedding resource: ${BASE_NAME}"
)
list(APPEND ${output_header_list_name} ${GENERATED_HEADER})
endforeach()
set(${output_header_list_name} ${${output_header_list_name}} PARENT_SCOPE)
endfunction()
embed_file_list(CAD_FILES CAD_HEADERS)
embed_file_list(SHADER_FILES SHADER_HEADERS)
# --- Registry file generation ---
set(REGISTRY_FILE "${EMBEDDED_DIR}/resource_registry.cpp")
set(REGISTRY_CONTENT "#include <vector>\n#include <string>\n#include <cstddef>\n")
foreach(HEADER ${CAD_HEADERS} ${SHADER_HEADERS})
get_filename_component(FNAME ${HEADER} NAME)
string(APPEND REGISTRY_CONTENT "#include \"${FNAME}\"\n")
endforeach()
string(APPEND REGISTRY_CONTENT "\nstruct ResourceEntry_t { std::string name; const char* data; size_t size; };\n")
string(APPEND REGISTRY_CONTENT "std::vector<ResourceEntry_t> getAllResources() {\n return {\n")
foreach(FILE_PATH ${CAD_FILES} ${SHADER_FILES})
get_filename_component(FNAME ${FILE_PATH} NAME)
string(MAKE_C_IDENTIFIER ${FNAME} VAR_NAME)
string(APPEND REGISTRY_CONTENT " {\"${FNAME}\", resources::${VAR_NAME}_data, resources::${VAR_NAME}_size},\n")
endforeach()
string(APPEND REGISTRY_CONTENT " };\n}\n")
file(WRITE ${REGISTRY_FILE} "${REGISTRY_CONTENT}")
# --- Libraries Compilation ---
function(hws_add_library TARGET)
if(NOT TARGET)
message(FATAL_ERROR "Expected the target name as first argument")
endif()
if(NOT ARGN)
message(FATAL_ERROR "Expected source file list after target name")
endif()
add_library(${TARGET} ${ARGN})
target_include_directories(${TARGET}
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/External>
$<INSTALL_INTERFACE:include>)
target_compile_options(${TARGET}
PRIVATE
-Wall -Wextra)
endfunction(hws_add_library)
# ------ utils and external libraries ------
hws_add_library(hello_worlds_SolarAzEl External/SolarAzEl/SolarAzEl.cpp)
hws_add_library(hello_worlds_glad External/glad/glad.c)
hws_add_library(hello_worlds_utility_lib
src/Utils/AssetResolver.cpp
src/Utils/XmlTokenize.cpp)
# ------ hello_worlds_engine_common ------
hws_add_library(hello_worlds_engine_common
src/Common/Camera/Camera.cpp
src/Common/Camera/CameraUpdater.cpp
src/Common/Camera/VirtualCamera.cpp
src/Common/Debug/DebugLine.cpp
src/Common/Lights/AmbientLight.cpp
src/Common/Lights/PointLights.cpp
src/Common/Models/Loaders/ColladaLoader.cpp
src/Common/Models/Loaders/ObjLoader.cpp
src/Common/Models/Loaders/StlLoader.cpp
src/Common/Models/Loaders/TinyObjReader.cpp
src/Common/Models/Loaders/ModelLoader.cpp
src/Common/Models/Mesh.cpp
src/Common/Models/Model.cpp
src/Common/Models/ModelManager.cpp
src/Common/Urdf/UrdfLoader.cpp
src/Common/Urdf/Urdf.cpp
src/Common/Urdf/Actor.cpp
src/Common/Urdf/VisualActor.cpp
src/Common/Urdf/Joint.cpp
src/Common/World.cpp
${CAD_HEADERS})
target_link_libraries(hello_worlds_engine_common PUBLIC
hello_worlds_utility_lib
hello_worlds_SolarAzEl
PRIVATE
${TINYXML2_LIBRARIES})
target_include_directories(hello_worlds_engine_common PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
# ------ hello_worlds_graphics ------
hws_add_library(hello_worlds_graphics
src/Graphics/OpenGL/Buffers/GeometryBuffer.cpp
src/Graphics/OpenGL/Buffers/SSAOManager.cpp
src/Graphics/OpenGL/Shaders/Shader.cpp
src/Graphics/OpenGL/Shaders/DefaultShader.cpp
src/Graphics/OpenGL/Shaders/ModelShader.cpp
src/Graphics/OpenGL/Shaders/SsaoShader.cpp
src/Graphics/GLFW/Window.cpp
src/Graphics/OpenGL/Cubemap.cpp
src/Graphics/OpenGL/LinesHandle.cpp
src/Graphics/OpenGL/MeshHandle.cpp
src/Graphics/OpenGL/OffScreen.cpp
src/Graphics/OpenGL/PointShadow.cpp
src/Graphics/OpenGL/Renderer.cpp
src/Graphics/OpenGL/Screen.cpp
src/Graphics/OpenGL/TextRenderer.cpp
src/Graphics/OpenGL/AmbientShadow.cpp
src/Graphics/OpenGL/Texture2D.cpp
${SHADER_HEADERS})
target_link_libraries(hello_worlds_graphics PUBLIC
hello_worlds_engine_common
hello_worlds_glad
assimp
glfw
${FREETYPE_LIBRARIES})
target_include_directories(hello_worlds_graphics PRIVATE ${FREETYPE_INCLUDE_DIRS} ${CMAKE_CURRENT_BINARY_DIR})
target_compile_options(hello_worlds_graphics PRIVATE $<$<CXX_COMPILER_ID:Clang>:-Wno-unused-function>)
# ------ hello_worlds_physics ------
set(PHYSX_ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/External/PhysX/physx/install/linux/PhysX")
set(PHYSX_INCLUDE_DIR "${PHYSX_ROOT_DIR}/include")
# Order matters: High-level libs first, low-level dependencies last
set(PHYSX_COMPONENTS
PhysXExtensions
PhysX
PhysXPvdSDK
PhysXCooking
PhysXCommon
PhysXFoundation
)
if(CMAKE_BUILD_TYPE AND CMAKE_BUILD_TYPE STREQUAL "Debug")
message(VERBOSE "Building with PhysX in debug configuration")
add_compile_definitions(_DEBUG)
set(PHYSX_BIN_PATH "${PHYSX_ROOT_DIR}/bin/linux.x86_64/release")
else()
message(VERBOSE "Building with PhysX in release configuration")
add_compile_definitions(NDEBUG)
set(PHYSX_BIN_PATH "${PHYSX_ROOT_DIR}/bin/linux.x86_64/release")
endif()
hws_add_library(hello_worlds_physics
src/Physics/PhysX/Actors/Actor.cpp
src/Physics/PhysX/Actors/DynamicActor.cpp
src/Physics/PhysX/Actors/LinkActor.cpp
src/Physics/PhysX/Actors/StaticActor.cpp
src/Physics/PhysX/Joint.cpp
src/Physics/PhysX/Urdf.cpp
src/Physics/PhysX/Context.cpp
src/Physics/PhysX/SharedContext.cpp
src/Physics/PhysX/World.cpp)
target_include_directories(hello_worlds_physics PUBLIC
$<BUILD_INTERFACE:${PHYSX_INCLUDE_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/PhysXExternal>
)
target_link_libraries(hello_worlds_physics PUBLIC hello_worlds_engine_common Threads::Threads)
foreach(LIB_NAME ${PHYSX_COMPONENTS})
set(LIB_FILE "lib${LIB_NAME}_static_64.a")
target_link_libraries(hello_worlds_physics PUBLIC
# For own build: use the absolute path to the External folder
$<BUILD_INTERFACE:${PHYSX_BIN_PATH}/${LIB_FILE}>
# For the consumer: use the relative path in the install directory
$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_LIBDIR}/${LIB_FILE}>
)
# Install the static library so the third-party linker can find it
install(FILES "${PHYSX_BIN_PATH}/${LIB_FILE}" DESTINATION ${CMAKE_INSTALL_LIBDIR})
endforeach()
# ------ hello_worlds main library ------
hws_add_library(hello_worlds src/Engine.cpp)
target_link_libraries(hello_worlds PUBLIC hello_worlds_physics hello_worlds_graphics)
# --- Demo executables ---
add_executable(demo_light examples/light_demo.cpp)
target_link_libraries(demo_light PRIVATE hello_worlds)
target_include_directories(demo_light PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/generated)
add_executable(instance_test examples/instance_test.cpp)
target_link_libraries(instance_test PRIVATE hello_worlds)
target_include_directories(instance_test PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/generated)
add_executable(demo_physics examples/physics_demo.cpp)
target_link_libraries(demo_physics PRIVATE hello_worlds)
target_include_directories(demo_physics PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/generated)
# --- Testing ---
option(BUILD_TESTING "Build tests" ON)
if(BUILD_TESTING)
# 1. Find GTest
if(ROS_BUILD_TYPE STREQUAL "ROS1")
# ROS 1 handles GTest through catkin
find_package(GTest REQUIRED)
elseif(ROS_BUILD_TYPE STREQUAL "ROS2")
# ROS 2 uses ament_cmake_gtest
find_package(ament_cmake_gtest REQUIRED)
else()
# Standalone: Try to find installed GTest or use FetchContent as a backup
find_package(GTest QUIET)
if(NOT GTest_FOUND)
include(FetchContent)
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/refs/heads/main.zip
)
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)
endif()
endif()
# 2. Configure test config
configure_file(
tests/test_config.h.in
${CMAKE_CURRENT_BINARY_DIR}/generated/test_config.hpp
@ONLY
)
# 3. Test registry function
function(hws_add_test TEST_NAME SOURCES)
if(ROS_BUILD_TYPE STREQUAL "ROS1")
catkin_add_gtest(${TEST_NAME} ${SOURCES})
target_link_libraries(${TEST_NAME} hello_worlds)
elseif(ROS_BUILD_TYPE STREQUAL "ROS2")
ament_add_gtest(${TEST_NAME} ${SOURCES})
target_link_libraries(${TEST_NAME} hello_worlds)
else()
add_executable(${TEST_NAME} ${SOURCES})
if(TARGET GTest::gtest_main)
target_link_libraries(${TEST_NAME} PRIVATE GTest::gtest_main hello_worlds)
else()
target_link_libraries(${TEST_NAME} PRIVATE gtest_main hello_worlds)
endif()
gtest_discover_tests(${TEST_NAME})
endif()
target_include_directories(${TEST_NAME} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/generated)
if(ROS_BUILD_TYPE STREQUAL "STANDALONE")
gtest_discover_tests(${TEST_NAME})
endif()
endfunction()
# 4. Register the Test
if(ROS_BUILD_TYPE STREQUAL "ROS1")
# This macro creates the executable and registers it with catkin/ctest
catkin_add_gtest(ResourceTests tests/resource_embedding.cpp ${REGISTRY_FILE} ${CAD_HEADERS} ${SHADER_HEADERS})
target_include_directories(ResourceTests PRIVATE "${EMBEDDED_DIR}")
elseif(ROS_BUILD_TYPE STREQUAL "ROS2")
# This macro handles the ament-specific test registration
ament_add_gtest(ResourceTests tests/resource_embedding.cpp ${REGISTRY_FILE} ${CAD_HEADERS} ${SHADER_HEADERS})
target_include_directories(ResourceTests PRIVATE "${EMBEDDED_DIR}")
else()
# Standalone standard CMake
enable_testing()
include(GoogleTest)
add_executable(ResourceTests tests/resource_embedding.cpp ${REGISTRY_FILE} ${CAD_HEADERS} ${SHADER_HEADERS})
target_link_libraries(ResourceTests PRIVATE GTest::gtest_main)
target_include_directories(ResourceTests PRIVATE "${EMBEDDED_DIR}")
gtest_discover_tests(ResourceTests)
endif()
hws_add_test(ModelLoaderTests tests/ModelLoaderTest.cpp)
hws_add_test(ModelManagerTests tests/ModelManagerTest.cpp)
hws_add_test(CameraUpdaterTests tests/CameraUpdaterTest.cpp)
hws_add_test(AssetResolverTests tests/AssetResolverTest.cpp)
hws_add_test(UrdfLoaderTests tests/UrdfLoaderTest.cpp)
endif()
# --- ROS-Specific Installation/Setup ---
install(DIRECTORY include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
install(DIRECTORY "${PHYSX_INCLUDE_DIR}"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/PhysXExternal"
)
install(TARGETS
hello_worlds_SolarAzEl
hello_worlds_utility_lib
hello_worlds_engine_common
hello_worlds_glad
hello_worlds_graphics
hello_worlds_physics
hello_worlds
EXPORT ${PROJECT_NAME}Targets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
# ROS 2 Specific Exports
if(ROS_BUILD_TYPE STREQUAL "ROS2")
ament_export_targets(${PROJECT_NAME}Targets HAS_LIBRARY_TARGET)
endif()
# Standalone Specific Exports
if(ROS_BUILD_TYPE STREQUAL "STANDALONE")
install(EXPORT ${PROJECT_NAME}Targets
FILE ${PROJECT_NAME}Config.cmake
NAMESPACE ${PROJECT_NAME}::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
)
endif()
if(ROS_BUILD_TYPE STREQUAL "ROS2")
ament_package()
endif()