-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
CMakeLists.txt
147 lines (106 loc) · 4.26 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
145
146
147
#project config
# May God have mercy on your soul.
# Windows: Download SDL2, put the libraries in lib/windows/
# MacOS: brew install sdl2
cmake_minimum_required(VERSION 3.14)
project(purpuri)
set(DEBUGGER False)
# ******************************************
# CMAKE defines
set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED True)
# CMAKE dependencies
find_package(Threads REQUIRED)
add_compile_options(
# gcc and clang: debugging symbols
"$<$<CXX_COMPILER_ID:AppleClang,Clang,GNU>:-g>"
# gcc and clang: warnings become errors
"$<$<CXX_COMPILER_ID:AppleClang,Clang,GNU>:-Werror>"
# msvc: warnings are fatal
"$<$<CXX_COMPILER_ID:MSVC>:/WX>"
# gcc and clang: show all warnings
"$<$<CXX_COMPILER_ID:AppleClang,Clang,GNU>:-Wall>"
# gcc and clang: show extra warnings
"$<$<CXX_COMPILER_ID:AppleClang,Clang,GNU>:-Wextra>"
# msvc: show all warnings
"$<$<CXX_COMPILER_ID:MSVC>:/Wall>"
# gcc and clang: enable pedantic mode when compiling
"$<$<CXX_COMPILER_ID:AppleClang,Clang,GNU>:-pedantic>"
# msvc: enable permissive mode
"$<$<CXX_COMPILER_ID:MSVC>:/permissive->"
# clang: ambiguous-reversed-operator; workaround for a C++ standard bug.
"$<$<CXX_COMPILER_ID:AppleClang,Clang>:-Wno-error=ambiguous-reversed-operator>"
# clang: bad-function-cast; workaround for an Imgui bug.
"$<$<CXX_COMPILER_ID:AppleClang,Clang>:-Wno-error=bad-function-cast>"
# gcc: cast-function-type; workaround for an Imgui bug.
"$<$<CXX_COMPILER_ID:GNU>:-Wno-error=cast-function-type>"
# clang and gcc: disable all optimizations.
"$<$<CXX_COMPILER_ID:AppleClang,Clang,GNU>:-O0>"
# windows: mingw and msys; use ANSI compatible printf, workaround a gcc bug.
"$<$<PLATFORM_ID:Windows>:-D__USE_MINGW_ANSI_STDIO>"
)
# ******************************************
# Source files
file(GLOB vm_src CONFIGURE_DEPENDS
"source/vm/*.cpp"
"source/vm/class/*.cpp"
"source/vm/native/*.cpp"
"source/vm/debug/*.cpp"
)
file(GLOB lib_src CONFIGURE_DEPENDS
"source/lib/*.cpp"
)
include_directories("inc")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)
# ******************************************
# If the debugger is enabled, compile necessary code inside the repos.
if (DEFINED debugger)
add_compile_definitions(VISUAL_DEBUGGER)
endif()
# ******************************************
# Setup the Purpuri executable.
# It's compiled with ENABLE_EXPORTS so that we can read VM functions from native code.
add_executable(purpuri)
target_sources(purpuri PRIVATE ${vm_src})
set_target_properties(purpuri PROPERTIES ENABLE_EXPORTS ON)
target_compile_definitions(purpuri PRIVATE VM_BUILDING)
target_link_libraries(purpuri PRIVATE Threads::Threads)
# Linux needs to compile against -ldl
if (UNIX)
target_link_libraries(purpuri PRIVATE dl)
endif()
# ******************************************
# Setup the native library.
add_library(native MODULE ${lib_src})
target_link_libraries(native PRIVATE purpuri)
# ******************************************
# Setup the visual debugger, if enabled
# ******************************************
if (DEFINED debugger)
file(GLOB imgui_src CONFIGURE_DEPENDS
"source/vm/debug/imgui/*.cpp"
)
target_sources(purpuri PRIVATE ${imgui_src})
# windows: manually link against sdl because there's no standard location
if(WIN32)
add_library(sdl IMPORTED SHARED)
set_target_properties(sdl PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/lib/windows/SDL2.dll IMPORTED_IMPLIB ${CMAKE_SOURCE_DIR}/lib/windows/libSDL2.dll.a)
target_link_libraries(purpuri PRIVATE sdl)
else()
# macos and linux: just look for sdl where it is expected to be.
find_package(SDL2 REQUIRED)
target_link_libraries(purpuri PRIVATE ${SDL2_LIBRARIES})
endif()
find_package(OpenGL)
# windows and linux: use -lopengl32
if(WIN32 OR LINUX)
target_link_libraries(purpuri PRIVATE opengl32)
endif()
# macos: use the special bunny command line argument that apple wants
if(APPLE)
target_link_libraries(purpuri PRIVATE "-framework OpenGL")
endif()
endif()