-
Notifications
You must be signed in to change notification settings - Fork 93
Expand file tree
/
Copy pathAddExample.cmake
More file actions
85 lines (66 loc) · 3.17 KB
/
Copy pathAddExample.cmake
File metadata and controls
85 lines (66 loc) · 3.17 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
function(add_example)
set(flags LINK_IMGUI LINK_ASSIMP LINK_XML LINK_PHYSX LINK_MESHOPT WEB)
set(oneValueArgs NAME)
set(multiValueArgs SOURCES WEB_EMBED)
cmake_parse_arguments(arg "${flags}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
if (EMSCRIPTEN AND NOT arg_WEB)
return()
endif ()
if (arg_LINK_ASSIMP AND (NOT TARGET assimp::assimp))
message(AUTHOR_WARNING "assimp not found, skipping '${arg_NAME}' example..")
return()
endif ()
if (arg_LINK_PHYSX AND (NOT TARGET unofficial::omniverse-physx-sdk::sdk))
message(AUTHOR_WARNING "physx not found, skipping '${arg_NAME}' example..")
return()
endif ()
if (NOT arg_SOURCES)
add_executable("${arg_NAME}" "${arg_NAME}.cpp")
else ()
add_executable("${arg_NAME}" "${arg_SOURCES}")
endif ()
target_link_libraries("${arg_NAME}" PRIVATE threepp)
target_include_directories("${arg_NAME}" PRIVATE "${PROJECT_SOURCE_DIR}/examples/libs")
if (arg_LINK_IMGUI)
target_link_libraries("${arg_NAME}" PRIVATE imgui::imgui)
endif ()
if (arg_LINK_ASSIMP)
target_link_libraries("${arg_NAME}" PRIVATE assimp::assimp)
endif ()
if (arg_LINK_PHYSX)
target_link_libraries("${arg_NAME}" PRIVATE unofficial::omniverse-physx-sdk::sdk)
if (WIN32 AND TARGET unofficial::omniverse-physx-sdk::gpu-library)
add_custom_command(TARGET "${arg_NAME}" POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
$<TARGET_FILE:unofficial::omniverse-physx-sdk::gpu-library>
$<TARGET_FILE_DIR:${arg_NAME}>)
endif ()
if (WIN32 AND TARGET unofficial::omniverse-physx-sdk::gpu-device-library)
add_custom_command(TARGET "${arg_NAME}" POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
$<TARGET_FILE:unofficial::omniverse-physx-sdk::gpu-device-library>
$<TARGET_FILE_DIR:${arg_NAME}>)
endif ()
endif ()
if (DEFINED EMSCRIPTEN)
target_compile_definitions(${arg_NAME} PRIVATE DATA_FOLDER="data")
set(LINK_FLAGS " --bind -sUSE_GLFW=3 -sASSERTIONS -sALLOW_MEMORY_GROWTH -sNO_DISABLE_EXCEPTION_CATCHING -sWASM=1 -sEXPORTED_RUNTIME_METHODS=[requestFullscreen]")
if (THREEPP_WITH_WGPU)
set(LINK_FLAGS "${LINK_FLAGS} --use-port=emdawnwebgpu -sASYNCIFY")
else ()
set(LINK_FLAGS "${LINK_FLAGS} -sGL_DEBUG=1 -sMIN_WEBGL_VERSION=2 -sMAX_WEBGL_VERSION=2 -sFULL_ES3")
endif ()
set(LINK_FLAGS "${LINK_FLAGS} --shell-file \"${PROJECT_SOURCE_DIR}/examples/emshell.html\"")
if (arg_WEB_EMBED)
foreach (path ${arg_WEB_EMBED})
set(LINK_FLAGS "${LINK_FLAGS} --embed-file \"${path}\"")
endforeach ()
endif ()
set_target_properties("${arg_NAME}"
PROPERTIES SUFFIX ".html"
LINK_FLAGS "${LINK_FLAGS}")
else ()
target_compile_definitions(${arg_NAME} PRIVATE DATA_FOLDER="${THREEPP_DATA_DIR}")
target_compile_definitions(${arg_NAME} PRIVATE PROJECT_FOLDER="${PROJECT_SOURCE_DIR}")
endif (DEFINED EMSCRIPTEN)
endfunction()