-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
159 lines (142 loc) · 4.89 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
159
cmake_minimum_required(VERSION 3.13)
project(FCPP LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(TOP_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
set(CMAKE_INSTALL_PREFIX ${TOP_DIR}/install)
if(NOT CMAKE_BUILD_TYPE)
message(STATUS "No build type selected, default to Release")
set(CMAKE_BUILD_TYPE Release CACHE STRING "Build Type" FORCE)
endif()
string(TIMESTAMP DATE_TODAY "%Y-%m-%d")
string(TIMESTAMP DATE_YEAR "%Y")
option(FCPP_SHARED_LIB "build to shared library" OFF)
option(FCPP_IO_WITH_SFML2 "build fcpp io lib with sfml2" OFF)
option(FCPP_IO_WITH_SDL2 "build fcpp io lib with sdl2" ON)
option(FCPP_IO_WITH_RAYLIB "build fcpp io lib with raylib" OFF)
option(FCPP_BUILD_CLI "build tfcpp" ON)
option(FCPP_BUILD_GUI "build qfcpp" ON)
option(FCPP_BUILD_TEST_CORE "build test for core" OFF)
option(FCPP_BUILD_TEST_WASM "build test for wasm" OFF)
option(FCPP_BUILD_TEST_DEBUGGER "build test for debugger" OFF)
option(FCPP_BUILD_C_BINDING "build C bingding" OFF)
option(FCPP_BUILD_PYTHON_BINDING "build Python bingding" OFF)
option(FCPP_BUILD_WASM "build efcpp" OFF)
option(FCPP_BUILD_TOOLS "build fcpp_tools" OFF)
option(FCPP_LTO "enable LTO" OFF)
option(FCPP_DISABLE_RTTI "disable rtti" OFF)
option(FCPP_DISABLE_EXCEPTION "disable exception" OFF)
if(FCPP_PRESET_BENCHMARK)
set(FCPP_BUILD_TEST_CORE ON)
set(FCPP_IO_WITH_RAYLIB OFF)
set(FCPP_IO_WITH_SFML2 OFF)
set(FCPP_IO_WITH_SDL2 OFF)
set(FCPP_BUILD_CLI OFF)
set(FCPP_BUILD_GUI OFF)
endif()
if(FCPP_PRESET_EMSCRIPTEN)
if(NOT EMSCRIPTEN)
message(FATAL_ERROR "This preset must be compiled using Emscripten")
endif()
set(FCPP_BUILD_WASM ON)
set(FCPP_BUILD_TEST_WASM ON)
set(FCPP_IO_WITH_RAYLIB OFF)
set(FCPP_IO_WITH_SFML2 OFF)
set(FCPP_IO_WITH_SDL2 OFF)
set(FCPP_BUILD_CLI OFF)
set(FCPP_BUILD_GUI OFF)
set(FCPP_BUILD_C_BINDING OFF)
set(FCPP_BUILD_PYTHON_BINDING OFF)
endif()
if(FCPP_PRESET_PYFCPP)
set(FCPP_BUILD_PYTHON_BINDING ON)
set(FCPP_IO_WITH_RAYLIB ON)
set(FCPP_IO_WITH_SFML2 OFF)
set(FCPP_IO_WITH_SDL2 OFF)
endif()
if(FCPP_BUILD_TEST_WASM)
set(FCPP_BUILD_WASM ON)
endif()
if(FCPP_BUILD_TEST_DEBUGGER)
set(FCPP_BUILD_TOOLS ON)
endif()
if(FCPP_LTO)
include(CheckIPOSupported)
check_ipo_supported(RESULT LTO_CHECK OUTPUT LTO_ERROR)
if(LTO_CHECK)
message(STATUS "LTO enabled")
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON)
else()
message(STATUS "LTO not supported: ${LTO_ERROR}")
endif()
endif()
# third-party
if(FCPP_IO_WITH_SFML2)
find_package(SFML 2 COMPONENTS graphics audio window REQUIRED)
endif()
if(FCPP_IO_WITH_SDL2 OR (FCPP_BUILD_WASM AND NOT EMSCRIPTEN) OR FCPP_BUILD_TEST_DEBUGGER)
find_package(SDL2 REQUIRED)
endif()
if(FCPP_IO_WITH_RAYLIB)
if(NOT FCPP_PYFCPP_PRESET) # This preset want to build pyfcpp without dependencies, so we build raylib from source
find_package(raylib QUIET)
endif()
if (NOT raylib_FOUND)
if(NOT FCPP_SHARED_LIB)
set(CHECK_NOT_EXPORT_FCPP_IO ON) # We can't export fcpp_io if build fcpp_io as static and build raylib from source
endif()
include(FetchContent)
FetchContent_Declare(
raylib
GIT_REPOSITORY https://github.com/raysan5/raylib
)
FetchContent_GetProperties(raylib)
if (NOT raylib_POPULATED)
FetchContent_Populate(raylib)
set(BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
add_subdirectory(${raylib_SOURCE_DIR} ${raylib_BINARY_DIR})
endif()
endif()
endif()
macro(fcpp_check_disable_flags TARGET)
if(FCPP_DISABLE_RTTI)
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC" OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND CMAKE_CXX_SIMULATE_ID MATCHES "MSVC" AND CMAKE_CXX_COMPILER_FRONTEND_VARIANT MATCHES "MSVC"))
target_compile_options(${TARGET} PUBLIC /GR-)
else()
target_compile_options(${TARGET} PUBLIC -fno-rtti)
endif()
endif()
if(FCPP_DISABLE_EXCEPTION)
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC" OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND CMAKE_CXX_SIMULATE_ID MATCHES "MSVC" AND CMAKE_CXX_COMPILER_FRONTEND_VARIANT MATCHES "MSVC"))
target_compile_options(${TARGET} PUBLIC /EHsc /D_HAS_EXCEPTIONS=0)
else()
target_compile_options(${TARGET} PUBLIC -fno-exceptions)
endif()
endif()
endmacro()
add_subdirectory(core)
add_subdirectory(io)
add_subdirectory(util)
add_subdirectory(bind)
add_subdirectory(test)
if(FCPP_BUILD_CLI)
add_subdirectory(cli)
endif()
if(FCPP_BUILD_GUI)
add_subdirectory(gui)
endif()
if(FCPP_BUILD_WASM)
add_subdirectory(wasm)
endif()
if(FCPP_BUILD_TOOLS)
add_subdirectory(tools)
endif()
install(
EXPORT FCPP
FILE FCPPConfig.cmake
NAMESPACE FCPP::
DESTINATION fcpp/cmake
)