-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathCMakeLists.txt
135 lines (109 loc) · 5.45 KB
/
CMakeLists.txt
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
add_subdirectory(tools)
ucm_add_flags(${ha_compiler_flags})
include_directories("./")
if(${WITH_PLUGINS})
add_definitions(-DHA_WITH_PLUGINS)
endif()
# == GAME ==========================================================================================
# sadly I need to duplicate these - emscripten (and I think gcc) have trouble building the pch - it does not use the PUBLIC/INTERFACE properties of the targets
include_directories("../third_party/dynamix/include")
include_directories("../third_party/ppk_assert")
include_directories("../third_party/")
include_directories("../third_party/imgui")
include_directories("../third_party/doctest/doctest")
include_directories("../third_party/tinygizmo")
if(WIN32)
include_directories("../third_party/nativefiledialog/src/include")
endif()
add_definitions(-DDOCTEST_CONFIG_IMPLEMENTATION_IN_DLL) # imported doctest symbols - test runner in a separate dll
ucm_add_dirs(TO registry_src "core/registry" FILTER_POP 2)
# added here so the custom_command is executed on it and it gets parsed before compiling the registry
list(APPEND registry_src core/Object.h)
add_library(registry STATIC ${registry_src})
target_link_libraries(registry sajson dynamix)
target_add_fPIC(registry)
target_parse_sources(registry)
ucm_add_files(TO SOURCES "precompiled.h")
ucm_add_files(TO SOURCES "main.cpp")
ucm_add_dirs(TO SOURCES "core")
ucm_add_dirs(TO SOURCES "core/imgui")
ucm_add_dirs(TO SOURCES "core/serialization")
ucm_add_dirs(TO SOURCES "core/messages")
ucm_add_dirs(TO SOURCES "utils")
ucm_add_dirs(TO SOURCES "utils/base64")
ucm_add_dirs(TO SOURCES "utils/aabb")
ucm_add_dirs(TO SOURCES "core/rendering")
# this cannot go inside the game executable because the doctest header is included by the precompiled header in all source files
add_library(doctest_runner SHARED utils/doctest/doctest_runner.cpp utils/doctest/doctest_proxy.h)
# ========= PLUGINS =============
ucm_add_dirs(TO plugin_src "plugins/common" FILTER_POP 1)
ucm_add_dirs(TO plugin_src "plugins/editor" FILTER_POP 1)
add_plugin(NAME plugin ${plugin_src})
ucm_add_dirs(TO plugin_camera "plugins/camera" FILTER_POP 1)
add_plugin(NAME camera ${plugin_camera})
# ========= PLUGINS END =========
if(MSVC AND ${WITH_PLUGINS})
# add the sources to the game project
ucm_add_dirs(TO SOURCES "rcrl")
endif()
add_executable(game "${SOURCES};${PLUGIN_SOURCES}")
add_precompiled_header(game "${CMAKE_CURRENT_SOURCE_DIR}/precompiled.h")
if(NOT MSVC)
# not sure if this has any effect... should test it
target_compile_options(game PRIVATE -Wl,--no-undefined)
endif()
target_parse_sources(game)
if(${WITH_PLUGINS})
set_target_properties(game PROPERTIES ENABLE_EXPORTS ON) # so plugins can link to the executable
target_compile_definitions(game PRIVATE "HAPI=${ha_symbol_export}")
endif()
target_link_libraries(game dynamix)
target_link_libraries(game ppk_assert)
target_link_libraries(game tinygizmo)
target_link_libraries(game imgui)
target_link_libraries(game registry)
target_link_libraries(game doctest_runner)
target_link_libraries(game ImGuiColorTextEdit)
target_link_libraries(game tiny-process-library)
if(WIN32)
target_link_libraries(game nativefiledialog)
endif()
# ========= REPL =============
if(MSVC AND ${WITH_PLUGINS})
# the file that will
set(plugin_file ${PROJECT_BINARY_DIR}/plugin.cpp)
# touch the file so it exists
file(WRITE ${plugin_file} "")
# defines needed for RCRL integration
target_compile_definitions(game PRIVATE "RCRL_PLUGIN_FILE=\"${plugin_file}\"")
target_compile_definitions(game PRIVATE "RCRL_PLUGIN_NAME=\"plugin\"")
target_compile_definitions(game PRIVATE "RCRL_BUILD_FOLDER=\"${PROJECT_BINARY_DIR}\"")
target_compile_definitions(game PRIVATE "RCRL_BIN_FOLDER=\"$<TARGET_FILE_DIR:game>/\"")
target_compile_definitions(game PRIVATE "RCRL_EXTENSION=\"${CMAKE_SHARED_LIBRARY_SUFFIX}\"")
if(${CMAKE_GENERATOR} MATCHES "Visual Studio" OR ${CMAKE_GENERATOR} MATCHES "Xcode")
target_compile_definitions(game PRIVATE "RCRL_CONFIG=\"$<CONFIG>\"")
endif()
# the plugin target that will be recompiled and loaded by RCRL
add_library(repl_plugin SHARED EXCLUDE_FROM_ALL ${plugin_file})
# link the RCRL plugin with the host app so we can call stuff from it
target_link_libraries(repl_plugin game)
# exclude it even for Visual Studio when building the whole solution (EXCLUDE_FROM_ALL is not enough)
set_target_properties(repl_plugin PROPERTIES EXCLUDE_FROM_DEFAULT_BUILD 1)
# no 'lib' prefix for some compilers/platforms - simplifies my code
set_target_properties(repl_plugin PROPERTIES PREFIX "")
# we don't want .pdb files for the plugin because when we are within Visual Studio and debugging the application it locks
# the .pdb for the original .dll and subsequent compiles fail even though we have loaded copies of the original .dll
# can also use /PDBALTPATH - https://blog.molecular-matters.com/2014/05/10/using-runtime-compiled-c-code-as-a-scripting-language-under-the-hood/
set_target_properties(repl_plugin PROPERTIES LINK_FLAGS /DEBUG:NONE)
# add a precompiled header
add_precompiled_header(repl_plugin "${CMAKE_CURRENT_SOURCE_DIR}/precompiled.h")
endif()
# ========= REPL END =========
if(TOOLCHAIN STREQUAL "js")
set_target_properties(game PROPERTIES SUFFIX ".html")
else()
target_include_directories(game PRIVATE ../third_party/glfw/include)
target_link_libraries(game glew)
target_link_libraries(game glfw)
target_link_libraries(game file_watcher)
endif()