-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
131 lines (110 loc) · 4.44 KB
/
CMakeLists.txt
File metadata and controls
131 lines (110 loc) · 4.44 KB
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
cmake_minimum_required(VERSION 3.6)
cmake_policy(SET CMP0069 NEW)
project(transmute)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
set(CMAKE_EXPORT_COMPILECOMMANDS ON)
set(CMAKE_SKIP_BUILD_RPATH FALSE)
set(CMAKE_SKIP_INSTALL_RPATH FALSE)
set(TR_VERSION_MAJOR 1)
set(TR_VERSION_MINOR 0)
set(TR_VERSION_PATCH 0)
execute_process(
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
COMMAND git rev-parse --short HEAD
RESULT_VARIABLE SHORT_HASH_RESULT
OUTPUT_VARIABLE TR_COMMIT_SHORT_HASH)
execute_process(
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
COMMAND git rev-parse HEAD
RESULT_VARIABLE SHORT_HASH_RESULT
OUTPUT_VARIABLE TR_COMMIT_HASH)
string(STRIP ${TR_COMMIT_HASH} TR_COMMIT_HASH)
string(STRIP ${TR_COMMIT_SHORT_HASH} TR_COMMIT_SHORT_HASH)
message("Transmute Version ${TR_VERSION_MAJOR}.${TR_VERSION_MINOR}.${TR_VERSION_PATCH}")
message(" Commit ${TR_COMMIT_HASH}")
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING
"Choose the type of build, options are: Debug Release
RelWithDebInfo MinSizeRel."
FORCE)
endif(NOT CMAKE_BUILD_TYPE)
if (WIN32)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake/")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_ROOT}/Modules")
else ()
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake/")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_ROOT}/Modules")
endif ()
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/build")
find_program(CCACHE_PROGRAM ccache)
if(CCACHE_PROGRAM)
set(CMAKE_CXX_COMPILER_LAUNCHER "${CCACHE_PROGRAM}")
endif()
# This compiles all the libraries with -fPIC, which is critical to link a static
# library into a shared lib.
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
option(USE_LLD "Use lld (from llvm) linker" OFF)
option(USE_MOLD "Use mold (A Modern Linker)" OFF)
option(TR_ENABLE_INSPECTOR "Enable Inspector" OFF)
if(LINUX OR APPLE)
if (NOT IOS)
# (penguinliong) Not compatible with -fembed-bitcode. Not sure where it
# comes from; probably a XCode preset?
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ffunction-sections -fdata-sections")
endif()
endif()
# Configure the default compiler options
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang|AppleClang|GNU")
add_compile_options(-Wno-unused-variable)
add_compile_options(-Wno-vla)
elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
add_compile_options(/W4 /WX)
add_compile_options(/wd4101)
endif()
if(USE_LLD)
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fuse-ld=lld")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -fuse-ld=lld")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=lld")
if(WIN32)
if(CMAKE_BUILD_TYPE EQUAL "RelWithDebInfo")
# -debug for LLD generates PDB files
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-debug")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,-debug")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-debug")
endif()
endif()
endif()
if(USE_MOLD)
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fuse-ld=mold")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -fuse-ld=mold")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=mold")
endif()
if(WIN32)
# For `Debug` configs MSVC links to a debuggable runtime by default which has
# symbol conflicts with the prebuilt LLVM in `Release`. We should be providing
# prebuilt LLVMs for both `Debug` and `Release` but LLVM 10 cannot be built by
# MSVC in `Debug` config because MSVC would try to fill uninitialize memory
# with `0xCC` but it too breaks `LLVMTableGen` which is depended on by almost
# every component in LLVM.
message("CMAKE_MSVC_RUNTIME_LIBRARY: ${CMAKE_MSVC_RUNTIME_LIBRARY}")
endif()
if(APPLE)
# Build Universal Binary for Apple Silicon that works for intel and silicon.
# set(CMAKE_OSX_ARCHITECTURES "arm64;x86_64")
message("CMAKE_OSX_ARCHITECTURES: ${CMAKE_OSX_ARCHITECTURES}")
endif()
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON)
if(APPLE)
set(TR_BUILD_TESTS ON)
elseif(ANDROID)
set(TR_BUILD_TESTS OFF)
endif()
include(cmake/TransmuteCXXFlags.cmake)
include(cmake/TransmuteCommon.cmake)
include(cmake/TransmuteCore.cmake)
include(cmake/TransmuteHTTPParser.cmake)
include(cmake/TransmuteClient.cmake)
include(cmake/TransmuteTests.cmake)
message("C++ Flags: ${CMAKE_CXX_FLAGS}")
message("Build type: ${CMAKE_BUILD_TYPE}")