-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
139 lines (112 loc) · 3.86 KB
/
CMakeLists.txt
File metadata and controls
139 lines (112 loc) · 3.86 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
cmake_minimum_required (VERSION 3.16)
project (gobot)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_PREFIX_PATH ${CMAKE_BINARY_DIR})
set(CMAKE_MODULE_PATH ${CMAKE_BINARY_DIR})
set(GOBOT_ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
option(GOB_BUILD_EXPERIMENT "using imgui and glfw" OFF)
option(GOB_BUILD_TESTS "build tests" OFF)
if(UNIX AND NOT APPLE)
set(LINUX TRUE)
endif()
include(cmake/CPM.cmake)
if(PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR)
message(
FATAL_ERROR
"In-source builds not allowed. Please make a new directory (called a build directory) and run CMake from there."
)
endif()
find_package(Eigen3 REQUIRED)
find_package(spdlog REQUIRED)
find_package(magic_enum REQUIRED)
find_package(nlohmann_json REQUIRED)
find_package(PNG REQUIRED)
find_package(cxxopts REQUIRED)
INCLUDE(GenerateExportHeader)
add_subdirectory(3rdparty)
file(GLOB_RECURSE SOURCE_CORE CONFIGURE_DEPENDS "src/gobot/core/*.cpp")
file(GLOB_RECURSE SOURCE_SCENE CONFIGURE_DEPENDS "src/gobot/scene/*.cpp")
file(GLOB_RECURSE SOURCE_DRIVERS CONFIGURE_DEPENDS "src/gobot/drivers/*.cpp")
file(GLOB_RECURSE SOURCE_RENDERING CONFIGURE_DEPENDS "src/gobot/rendering/*.cpp")
file(GLOB_RECURSE SOURCE_EDITOR CONFIGURE_DEPENDS "src/gobot/editor/*.cpp")
file(GLOB_RECURSE SOURCE_MAIN CONFIGURE_DEPENDS "src/gobot/main/*.cpp")
# https://github.com/bincrafters/community/issues/466#issuecomment-426265654
add_library(gobot SHARED ${SOURCE_DRIVERS} ${SOURCE_MAIN} ${SOURCE_CORE} ${SOURCE_RENDERING} ${SOURCE_SCENE} ${SOURCE_EDITOR})
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
set(GOBOT_COMPILE_OPTIONS "/Zc:preprocessor,__cplusplus" "/bigobj")
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(GOBOT_COMPILE_OPTIONS "-fno-gnu-unique")
endif ()
target_compile_options(gobot PUBLIC "${GOBOT_COMPILE_OPTIONS}")
# https://forum.qt.io/topic/97296/export-qobject-based-class-from-dll/2
GENERATE_EXPORT_HEADER(gobot)
target_include_directories(gobot
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/include
${PROJECT_BINARY_DIR}
)
target_link_libraries(gobot
PUBLIC
RTTR::Core
imgui-gobot
glad
SDL2::SDL2
stb
gli
spdlog::spdlog
PNG::PNG
Eigen3::Eigen
magic_enum::magic_enum
nlohmann_json::nlohmann_json
cxxopts::cxxopts
)
# copy icon to bin
add_custom_command(
TARGET gobot POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_SOURCE_DIR}/icon.svg
${CMAKE_BINARY_DIR}/bin/icon.svg)
set_target_properties(gobot
PROPERTIES
CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
)
set(SHADER_COMPILE_TARGET GobotShaderCompile)
add_subdirectory(shader)
# Why doesn't work for include
add_dependencies(gobot ${SHADER_COMPILE_TARGET})
target_include_directories(gobot
PUBLIC
shader/generated
)
if (MSVC)
file(GLOB_RECURSE SOURCE_PLATFORM CONFIGURE_DEPENDS "src/gobot/platform/windows/*.cpp")
add_executable(gobot_editor ${SOURCE_PLATFORM})
target_compile_options(gobot_editor PUBLIC "/Zc:preprocessor")
elseif(LINUX)
file(GLOB_RECURSE SOURCE_PLATFORM CONFIGURE_DEPENDS "src/gobot/platform/linux/*.cpp")
add_executable(gobot_editor ${SOURCE_PLATFORM})
endif ()
target_link_libraries(gobot_editor
PRIVATE
gobot
)
if (GOB_BUILD_EXPERIMENT)
add_subdirectory(experiment)
endif ()
if (GOB_BUILD_TESTS)
enable_testing()
include(GoogleTest)
add_subdirectory(tests)
endif ()
if (MSVC)
add_custom_command(TARGET gobot POST_BUILD
COMMAND "${CMAKE_COMMAND}" -E copy_directory
"$<TARGET_FILE_DIR:RTTR::Core>"
"$<TARGET_FILE_DIR:gobot>"
COMMENT "Copying RTTR files..."
)
endif ()