-
Notifications
You must be signed in to change notification settings - Fork 9
/
CMakeLists.txt
158 lines (136 loc) · 4.68 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
148
149
150
151
152
153
154
155
156
157
158
cmake_minimum_required (VERSION 3.15)
# Disable adding MSVC CRT to CMAKE_<LANG>_FLAGS_<CONFIG> by default.
cmake_policy(SET CMP0091 NEW)
# Disable adding MSVC warning flags to CMAKE_<LANG>_FLAGS by default.
cmake_policy(SET CMP0092 NEW)
option(BUILD_SHARED_LIBS "Build libs as shared libraries." OFF)
option(DEBUG_UI "Enable the debug UI." ON)
option(BUILD_TESTS "Build tests." OFF)
# Attempt to set VCPKG_TARGET_TRIPLET on Windows to use static libs.
# This is currently required by certain packages like ImGui.
if(WIN32 AND NOT VCPKG_TARGET_TRIPLET)
set(VCPKG_ARCH x64) # Default to x64
# VS's open folder/CMake support sets CMAKE_INSTALL_PREFIX
if(CMAKE_INSTALL_PREFIX MATCHES "x86-")
set(VCPKG_ARCH x86)
# Otherwise see if user set the arch via -A
elseif(CMAKE_GENERATOR_PLATFORM STREQUAL Win32)
set(VCPKG_ARCH x86)
endif()
set(VCPKG_TARGET_TRIPLET ${VCPKG_ARCH}-windows-static)
unset(VCPKG_ARCH)
message(STATUS "VCPKG_TARGET_TRIPLET set to: ${VCPKG_TARGET_TRIPLET}")
endif()
# Setup vcpkg manifest mode. This will automatically bootstrap and download/update
# packages listed in vcpkg.json.
# https://github.com/microsoft/vcpkg/blob/master/docs/users/manifests.md
if(BUILD_TESTS)
list(APPEND VCPKG_MANIFEST_FEATURES "tests")
endif()
set(CMAKE_TOOLCHAIN_FILE ${CMAKE_SOURCE_DIR}/external/vcpkg/scripts/buildsystems/vcpkg.cmake CACHE STRING "Vcpkg toolchain file")
project(vectrexy
DESCRIPTION "A Vectrexy emulator by Antonio Maiorano"
HOMEPAGE_URL https://github.com/amaiorano/vectrexy
)
set(ENGINE_TYPE sdl CACHE STRING "Engine Type")
set_property(CACHE ENGINE_TYPE PROPERTY STRINGS sdl null)
string(TOLOWER ${ENGINE_TYPE} ENGINE_TYPE)
if(ENGINE_TYPE STREQUAL null)
set(USE_NULL_ENGINE On)
elseif(ENGINE_TYPE STREQUAL sdl)
set(USE_SDL_ENGINE On)
else()
message(FATAL_ERROR "Unknown engine type")
endif()
if(NOT BUILD_SHARED_LIBS)
set(BUILD_STATIC_LIBS ON)
else()
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
endif()
if(UNIX AND NOT APPLE)
set(LINUX true)
endif()
# Force exes/libs to output in the build/ folder, rather than have each output
# in its own build/[module]/ folder. This is especially useful for shared lib
# builds so that DLLs end up in the same directory as the EXE. Note that for
# multi-config generators (VS, Xcode), sub-directories for each config will
# still be created (e.g. build/Release/, build/Debug/, etc.).
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
# Make sure MinSizeRel and RelWithDebInfo use Release libs instead of Debug libs from vcpkg
set(CMAKE_MAP_IMPORTED_CONFIG_MINSIZEREL Release)
set(CMAKE_MAP_IMPORTED_CONFIG_RELWITHDEBINFO Release)
# Set module path to local cmake folder so find_package looks there first
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
# Set C++ standard and disable extensions
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
if(USE_SDL_ENGINE)
add_compile_definitions(PLATFORM_SDL)
endif()
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
add_compile_definitions(
_CRT_SECURE_NO_WARNINGS
_SCL_SECURE_NO_WARNINGS
)
add_compile_options(/MP /W4 /WX)
# Use dynamic CRT for shared lib builds to avoid issues with allocations in one DLL
# being freed in another. For static buids, use static CRT so the user doesn't have to
# install the right CRT.
if (BUILD_SHARED_LIBS)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
else()
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif()
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
if("x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC") # clang-cl
add_compile_definitions(
_CRT_SECURE_NO_WARNINGS
_SCL_SECURE_NO_WARNINGS
)
endif()
add_compile_options(
-Wno-deprecated-declarations
-Wno-format-security
-Wno-nonportable-include-path
-Wno-pragma-pack
-Wno-unused-function
-Wno-unused-const-variable
)
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
add_compile_options(
-Wno-format-security
)
endif()
if(USE_NULL_ENGINE)
add_definitions(-DENGINE_NULL)
elseif(USE_SDL_ENGINE)
add_definitions(-DENGINE_SDL)
endif()
if(DEBUG_UI)
add_definitions(-DDEBUG_UI_ENABLED)
endif()
# Add externals
if(LINUX)
add_subdirectory(external/linenoise)
endif()
add_subdirectory(external/noc)
add_subdirectory(external/cppdap)
# Add libs
add_subdirectory(libs/core)
add_subdirectory(libs/engine)
add_subdirectory(libs/emulator)
add_subdirectory(libs/debugger)
if(USE_NULL_ENGINE)
add_subdirectory(libs/null_engine)
endif()
if(USE_SDL_ENGINE)
add_subdirectory(libs/sdl_engine)
endif()
add_subdirectory(libs/vectrexy)
if(BUILD_TESTS)
find_package(GTest CONFIG REQUIRED)
add_subdirectory(external/subprocess)
add_subdirectory(tests/debugger_tests)
endif()