-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
144 lines (125 loc) · 4.79 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
136
137
138
139
140
141
142
143
144
cmake_minimum_required(VERSION 3.22)
if(APPLE)
# Fix runtime path for installed executables
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH ON)
endif()
project(PTVC_Project_GL)
include(FetchContent)
if(MSVC)
# https://docs.microsoft.com/en-us/previous-versions/958x11bc(v=vs.140)
add_compile_options("$<$<CONFIG:Debug>:/MTd>$<$<CONFIG:Release>:/MT>")
add_compile_options("$<$<CONFIG:Debug>:/ZI>$<$<CONFIG:Release>:/Zi>")
add_compile_options(/FS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP /Qpar")
endif()
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
file(GLOB_RECURSE SOURCES "src/*.cpp" "src/*.h")
set(INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/include")
if(UNIX AND NOT APPLE)
set(LIBRARY_DIR "${CMAKE_CURRENT_SOURCE_DIR}/lib/linux" ".")
elseif(UNIX AND APPLE)
set(LIBRARY_DIR "${CMAKE_CURRENT_SOURCE_DIR}/lib/macos" ".")
elseif(WIN32)
set(LIBRARY_DIR "${CMAKE_CURRENT_SOURCE_DIR}/lib/windows" ".")
endif()
find_package(OpenGL REQUIRED)
# Include Jolt
FetchContent_Declare(
JoltPhysics
GIT_REPOSITORY "https://github.com/jrouwe/JoltPhysics"
GIT_TAG "v5.0.0"
SOURCE_SUBDIR "Build")
FetchContent_MakeAvailable(JoltPhysics)
if (MSVC)
target_compile_options(Jolt PRIVATE /wd4514)
endif()
# Include ImGui
FetchContent_Declare(
imgui
GIT_REPOSITORY https://github.com/ocornut/imgui.git
GIT_TAG v1.90.4
)
FetchContent_MakeAvailable(imgui)
file(GLOB IMGUI_SOURCES ${imgui_SOURCE_DIR}/*.cpp)
add_library(imgui STATIC ${IMGUI_SOURCES})
target_include_directories(imgui PUBLIC ${imgui_SOURCE_DIR})
# Maybe I can get this to work, but it's not really needed right now
# set(IMGUI_USER_CONFIG "${CMAKE_CURRENT_SOURCE_DIR}/src/UI/imconfig.h")
# target_compile_definitions(imgui INTERFACE "-DIMGUI_USER_CONFIG=<${IMGUI_USER_CONFIG}>")
# Include LZ4
FetchContent_Declare(
lz4
GIT_REPOSITORY "https://github.com/lz4/lz4"
GIT_TAG "v1.9.4"
)
FetchContent_MakeAvailable(lz4)
file(GLOB lz4_SOURCES ${lz4_SOURCE_DIR}/lib/*.c)
add_library(lz4 STATIC ${lz4_SOURCES})
target_include_directories(lz4 PUBLIC ${lz4_SOURCE_DIR}/lib)
# Include SoLoud
FetchContent_Declare(
soloud
GIT_REPOSITORY "https://github.com/jarikomppa/soloud"
GIT_TAG "RELEASE_20200207"
)
FetchContent_MakeAvailable(soloud)
add_compile_definitions(WITH_MINIAUDIO)
file(GLOB SOLOUD_SOURCES
${soloud_SOURCE_DIR}/src/core/*.cpp
${soloud_SOURCE_DIR}/src/audiosource/wav/*.cpp
${soloud_SOURCE_DIR}/src/audiosource/wav/*.c
${soloud_SOURCE_DIR}/src/backend/miniaudio/*.cpp
${soloud_SOURCE_DIR}/src/filter/*.cpp)
add_library(soloud STATIC ${SOLOUD_SOURCES})
target_include_directories(soloud PUBLIC ${soloud_SOURCE_DIR}/include)
# Note to self: It is <lowercase_name>_SOURCE_DIR
set(LINK_LIBRARIES
debug glfw3d optimized glfw3
debug glew32sd optimized glew32s
OpenGL::GL
Jolt
imgui
lz4
soloud
)
add_executable(${PROJECT_NAME} ${SOURCES})
target_include_directories(${PROJECT_NAME} PRIVATE ${INCLUDE_DIRS})
target_link_directories(${PROJECT_NAME} PRIVATE ${LIBRARY_DIR})
target_link_libraries(${PROJECT_NAME} PRIVATE ${LINK_LIBRARIES})
# IDE specific settings
if(CMAKE_GENERATOR MATCHES "Visual Studio")
set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS "/ignore:4099")
set_target_properties(${PROJECT_NAME} PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}")
set_property(DIRECTORY "${CMAKE_SOURCE_DIR}" PROPERTY VS_STARTUP_PROJECT ${PROJECT_NAME})
elseif(CMAKE_GENERATOR MATCHES "Xcode")
set_target_properties(${PROJECT_NAME} PROPERTIES XCODE_GENERATE_SCHEME TRUE CMAKE_XCODE_SCHEME_WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}")
set_property(DIRECTORY "${CMAKE_SOURCE_DIR}" PROPERTY XCODE_STARTUP_PROJECT ${PROJECT_NAME})
endif()
if(UNIX AND NOT APPLE)
find_package(X11 REQUIRED)
target_link_libraries(${PROJECT_NAME} PRIVATE ${X11_LIBRARIES})
target_include_directories(${PROJECT_NAME} PRIVATE ${X11_INCLUDE_DIR})
endif()
string(LENGTH "${CMAKE_SOURCE_DIR}/" SOURCE_PATH_SIZE)
add_definitions("-DSOURCE_PATH_SIZE=${SOURCE_PATH_SIZE}")
if(MSVC)
# enable warnings except:
# 'size_t' possible loss of data, 'identifier' hides class member, unused parameter
# disable warnings in external includes
target_compile_options(${PROJECT_NAME} PRIVATE /W4 /wd4267 /wd4458 /wd4100 /external:anglebrackets /external:W0)
else()
string(REGEX MATCH "^([0-9]+)" GCC_VERSION_MAJOR "${CMAKE_CXX_COMPILER_VERSION}")
if(GCC_VERSION_MAJOR LESS 14)
message(FATAL_ERROR "Your GCC version doesn't support required c++23 features. Use GCC 14+")
else()
target_link_libraries(${PROJECT_NAME} PRIVATE stdc++exp)
endif()
endif()
install(
TARGETS ${PROJECT_NAME} CONFIGURATIONS Debug DESTINATION "debug"
)
install(
TARGETS ${PROJECT_NAME} CONFIGURATIONS Release DESTINATION "release"
)