-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
67 lines (55 loc) · 2.95 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
cmake_minimum_required (VERSION 3.2...3.27.5)
# default compilers
set(CMAKE_C_COMPILER "gcc")
set(CMAKE_CXX_COMPILER "g++")
# build universal 2 binary on macOS, supporting both, Intel Macs and Silicon (M1/M2)
if(APPLE)
set (CMAKE_OSX_ARCHITECTURES "x86_64;arm64")
endif()
# For CMake versions < 3.25
if(CMAKE_VERSION VERSION_LESS "3.25")
if(UNIX AND NOT APPLE)
set(LINUX TRUE)
message("-- Linux detected")
endif()
endif()
project(XPPL)
# Copy symbol collisions file
configure_file("collisions" "collisions" COPYONLY)
# Global compiler flags
set (GCC_DEFAULT_FLAGS -std=gnu17 -Wall -Wunreachable-code -pipe -Wextra -Wshadow -Wfloat-equal -pedantic -fvisibility=hidden -O2 -fmessage-length=0 -D_FORTIFY_SOURCE=2 -fstack-protector -funwind-tables -fasynchronous-unwind-tables -W)
set (GXX_DEFAULT_FLAGS -std=gnu++17 -Wall -Wunreachable-code -pipe -Wextra -Wshadow -Wfloat-equal -pedantic -fvisibility=hidden -O2 -fmessage-length=0 -D_FORTIFY_SOURCE=2 -fstack-protector -funwind-tables -fasynchronous-unwind-tables -W)
include_directories("./include")
file(GLOB_RECURSE TEST_SOURCES "test/*.c")
file(GLOB_RECURSE XPPL_COMMON_SOURCES "xppl_common/*.c")
file(GLOB_RECURSE XPPL_CONFIG_SOURCES "xppl_config/*.c")
file(GLOB_RECURSE XPPL_MAP_SOURCES "xppl_map/*.c")
file(GLOB_RECURSE XPPL_TEST_SOURCES "xppl_test/*.c")
set(SOURCES ${TEST_SOURCES} ${XPPL_TEST_SOURCES} ${XPPL_COMMON_SOURCES} ${XPPL_CONFIG_SOURCES} ${XPPL_MAP_SOURCES})
if(WIN32)
cmake_policy(SET CMP0015 NEW)
set (CMAKE_C_COMPILER x86_64-w64-mingw32-gcc)
set (CMAKE_CXX_COMPILER x86_64-w64-mingw32-g++)
add_executable(WIN_TEST_64 ${SOURCES})
target_compile_options(WIN_TEST_64 PRIVATE ${GCC_DEFAULT_FLAGS} -D__USE_MINGW_ANSI_STDIO -s -c -fno-stack-protector -static-libgcc -static-libstdc++ -DIBM)
target_link_libraries(WIN_TEST_64 -static-libgcc -static-libstdc++ -static ssp -static wsock32 -static ws2_32)
set_target_properties(WIN_TEST_64 PROPERTIES LINK_FLAGS "-s -Wl,--version-script=collisions")
set_target_properties(WIN_TEST_64 PROPERTIES OUTPUT_NAME "test")
endif()
if(LINUX)
add_executable(LIN_TEST_64 ${SOURCES})
target_compile_options(LIN_TEST_64 PRIVATE ${GCC_DEFAULT_FLAGS} -m64 -fPIC -DLIN)
set_target_properties(LIN_TEST_64 PROPERTIES LINK_FLAGS "-Wl,--version-script=collisions")
set_target_properties(LIN_TEST_64 PROPERTIES OUTPUT_NAME "test")
endif()
if(APPLE)
cmake_policy(SET CMP0042 NEW)
set (CMAKE_SYSTEM_NAME Darwin)
set (CMAKE_CXX_COMPILER g++)
set (CMAKE_OSX_ARCHITECTURES "x86_64;arm64")
add_executable(MAC_TEST_64 SHARED ${SOURCES})
target_compile_options(MAC_TEST_64 PRIVATE ${GCC_DEFAULT_FLAGS} -nostdinc++ -I/Library/Developer/CommandLineTools/usr/include/c++/v1 -DAPL)
target_link_libraries(MAC_TEST_64 "-nodefaultlibs" "-lc++" "-lc++abi" "-lm" "-lc")
set_target_properties(MAC_TEST_64 PROPERTIES LINK_FLAGS "-m64 -fvisibility=hidden")
set_target_properties(MAC_TEST_64 PROPERTIES OUTPUT_NAME "test")
endif()