-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
124 lines (101 loc) · 3.92 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
cmake_minimum_required(VERSION 3.7)
project(WizEngine)
set(SFML_COMMIT 8f6903d00853fd3db395a557733ae65a14f37c01)
set(SFML_SWITCH_COMMIT master)
set(BOX2D_CMAKE_COMMIT master)
set(GTEST_COMMIT e2239ee6043f73722e7aa812a459f54a28552929) # Version 1.11.0
if(CMAKE_COMPILER_IS_GNUCXX AND NOT WIN32)
# Not for windows because windres.exe doesn't support those
add_definitions(-frtti -Wall -ansi -Wno-deprecated -pthread -Wpedantic)
endif()
# applies OS type C++ macro
if(WIN32)
add_compile_definitions(OS_WINDOWS)
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
add_compile_definitions(OS_MAC)
elseif(UNIX)
add_compile_definitions(OS_UNIX)
elseif(CMAKE_TOOLCHAIN_FILE MATCHES ".*DevkitA64Libnx.cmake")
add_compile_definitions(OS_SWITCH)
set(CMAKE_USER_MAKE_RULES_OVERRIDE "${CMAKE_CURRENT_SOURCE_DIR}/cmake/CompilerOptionsOverride.cmake")
endif()
#
# Set C++ version
#
set(CMAKE_CXX_STANDARD 20)
#
# The following if-else chain makes the different platform output at different
# paths:
#
# bin/
# windows64/
# windows32/
# mac/
# linux64/
# linux32/
#
if(WIN32)
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin/windows64/)
else()
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin/windows32/)
endif()
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin/mac/)
elseif(UNIX)
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin/linux64/)
else()
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin/linux32/)
endif()
elseif(CMAKE_TOOLCHAIN_FILE MATCHES ".*DevkitA64Libnx.cmake")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin/switch/)
endif()
# Fetches SFML dependency and loads its CMakeLists.txt
include(FetchContent)
if(CMAKE_TOOLCHAIN_FILE MATCHES ".*DevkitA64Libnx.cmake")
FetchContent_Declare(sfml
GIT_REPOSITORY https://github.com/WheezyWiseWizards/SFML-switch.git
GIT_TAG ${SFML_SWITCH_COMMIT})
else()
FetchContent_Declare(sfml
GIT_REPOSITORY https://github.com/SFML/SFML.git
GIT_TAG ${SFML_COMMIT})
endif()
FetchContent_MakeAvailable(sfml)
# this creates the variables SFML_SOURCE_DIR, SFML_BINARY_DIR and SFML_POPULATED
# then SFML_SOURCE_DIR is used below to include the header files
FetchContent_GetProperties(SFML)
# Fetches Box2D dependency and loads its CMakeLists.txt
FetchContent_Declare(Box2D
GIT_REPOSITORY https://github.com/WheezyWiseWizards/Box2D-cmake.git
GIT_TAG ${BOX2D_CMAKE_COMMIT})
FetchContent_MakeAvailable(Box2D)
FetchContent_GetProperties(Box2D SOURCE_DIR Box2D_SOURCE_DIR)
# Other dependencies
set(OpenGL_GL_PREFERENCE GLVND)
find_package(OpenGL)
find_package(Threads REQUIRED)
# include and source files
include_directories(include ${SFML_SOURCE_DIR}/include ${Box2D_SOURCE_DIR}/Box2D ${Box2D_SOURCE_DIR}/Box2D/Box2D)
if(CMAKE_TOOLCHAIN_FILE MATCHES ".*DevkitA64Libnx.cmake")
include_directories(${LIBNX_INCLUDE_DIR})
endif()
file(GLOB_RECURSE SOURCE_FILES "${PROJECT_SOURCE_DIR}/src/*.cpp" "${PROJECT_SOURCE_DIR}/include/*.h" "${PROJECT_SOURCE_DIR}/include/*.inl" "${PROJECT_SOURCE_DIR}/include/*.hpp")
add_library(${PROJECT_NAME} STATIC ${SOURCE_FILES})
if(NOT CMAKE_TOOLCHAIN_FILE MATCHES ".*DevkitA64Libnx.cmake" AND NOT ANDROID)
FetchContent_Declare(googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG ${GTEST_COMMIT})
set(GTEST_FORCE_SHARED_CRT ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)
enable_testing()
file(GLOB TEST_SRC_FILES ${PROJECT_SOURCE_DIR}/tests/*.cpp)
add_executable(${PROJECT_NAME}_tests ${TEST_SRC_FILES})
target_link_libraries(${PROJECT_NAME}_tests
gtest_main
${PROJECT_NAME}
WIZ::Box2D)
include(GoogleTest)
gtest_discover_tests(${PROJECT_NAME}_tests)
endif()