forked from cat-in-the-dark/cpp_game_template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
88 lines (69 loc) · 2.82 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
cmake_minimum_required(VERSION 3.16)
project(Game CXX)
set(CMAKE_C_STANDARD 17)
set(CMAKE_CXX_STANDARD 17)
option(SANITIZE "Build project with Address & UB sanitizers" OFF)
option(EMSCRIPTEN "Build project for web" OFF)
file(GLOB_RECURSE SOURCES src/*.cpp)
file(GLOB_RECURSE HEADERS src/*.h)
set(THIRDPARTY_DIR ${CMAKE_SOURCE_DIR}/vendor)
add_executable(${PROJECT_NAME} ${SOURCES} ${HEADERS})
# warning level
if(MSVC)
target_compile_options(${PROJECT_NAME} PRIVATE /W4 /WX /wd4244)
else()
target_compile_options(${PROJECT_NAME} PRIVATE
-pedantic
-pedantic-errors
-Wall
-Werror
-Wextra
-Wno-unused-parameter
-Wno-unused-command-line-argument
)
endif()
# sanitizers
if(SANITIZE)
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
message("Building with sanitizers")
target_compile_options(${PROJECT_NAME} PRIVATE
-fsanitize=address,undefined
-fno-sanitize-recover=all
)
target_link_libraries(${PROJECT_NAME} -fsanitize=address,undefined)
else()
message(FATAL_ERROR "Sanitizers are supported only on Clang!")
endif()
endif()
if (MSVC)
set_target_properties(${PROJECT_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set_target_properties(${PROJECT_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR})
set_target_properties(${PROJECT_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR})
# etc for the other available configuration types (MinSizeRel, RelWithDebInfo)
endif (MSVC)
file(COPY assets DESTINATION ${CMAKE_BINARY_DIR}/)
if(EMSCRIPTEN)
message("WAVE: Building for web")
set(PLATFORM Web)
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE BOTH)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
add_definitions(-DPLATFORM_WEB)
add_definitions(-DUSE_WASM)
set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS "-Os -s ASSERTIONS=1 -s ALLOW_MEMORY_GROWTH=1 --no-heap-copy -s GL_ENABLE_GET_PROC_ADDRESS -s USE_GLFW=3 --embed-file assets/ --shell-file ${CMAKE_SOURCE_DIR}/src/index.html")
string(REPLACE "-rdynamic" "" CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS}")
set(CMAKE_EXECUTABLE_SUFFIX ".html")
endif()
add_subdirectory(${THIRDPARTY_DIR}/raylib)
target_include_directories(${PROJECT_NAME} PRIVATE
src
)
target_include_directories(${PROJECT_NAME} PUBLIC SYSTEM vendor/raylib/src)
target_link_libraries(${PROJECT_NAME} raylib)
# Checks if OSX and links appropriate frameworks (Only required on MacOS)
if(APPLE)
target_link_libraries(${PROJECT_NAME} "-framework IOKit")
target_link_libraries(${PROJECT_NAME} "-framework Cocoa")
target_link_libraries(${PROJECT_NAME} "-framework OpenGL")
endif()