-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
175 lines (121 loc) · 5.58 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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
cmake_minimum_required (VERSION 3.5)
project("winter")
set(CURRENT_TARGET winter)
set(WINTER_USE_OPENCL OFF CACHE BOOL "Enable OpenCL support, currently just used for test execution.")
set(WINTER_INCLUDE_TESTS TRUE)
SET(GLARE_CORE_TRUNK_DIR "../glare-core" CACHE PATH "Path to glare-core repo trunk dir.")
if(GLARE_CORE_TRUNK_DIR STREQUAL "")
MESSAGE(FATAL_ERROR "ERROR: Please set GLARE_CORE_TRUNK_DIR to the path to glare-core repo trunk dir, e.g. -DGLARE_CORE_TRUNK_DIR=path/to/glare/core")
endif()
SET(LIBS_DIR "" CACHE PATH "Path to libraries dir. llvm builds should be in this dir, for example LIBS_DIR/llvm/llvm_11_0_0_install_vs2022_64")
if(LIBS_DIR STREQUAL "")
MESSAGE(FATAL_ERROR "ERROR: Please set LIBS_DIR to the path to llvm builds can be found in, e.g. -DLIBS_DIR=c:/libs")
endif()
SET(WINTER_LLVM_VERSION "15.0.7" CACHE STRING "LLVM version to use")
MESSAGE("Building with OpenCL support: ${WINTER_USE_OPENCL} (-DWINTER_USE_OPENCL=OFF/ON))")
MESSAGE("Libraries dir: ${LIBS_DIR} (-DLIBS_DIR)")
MESSAGE("Glare-core trunk dir: ${GLARE_CORE_TRUNK_DIR} (-DGLARE_CORE_TRUNK_DIR)")
MESSAGE("Winter LLVM version: ${WINTER_LLVM_VERSION} (-DWINTER_LLVM_VERSION)")
# Work out WINTER_LLVM_DIR
# The llvm dirs use the version seperator "_" instead of "."
string(REPLACE "." "_" LLVM_VERSION_PATH ${WINTER_LLVM_VERSION})
if(WIN32)
if(MSVC_VERSION EQUAL 1900)
set(WINTER_VS_VER 2015)
elseif(MSVC_VERSION EQUAL 1911 OR MSVC_VERSION EQUAL 1912)
set(WINTER_VS_VER 2017)
elseif(MSVC_VERSION GREATER_EQUAL 1920 AND MSVC_VERSION LESS 1930)
set(WINTER_VS_VER 2019)
elseif(MSVC_VERSION GREATER_EQUAL 1930 AND MSVC_VERSION LESS 1940)
set(WINTER_VS_VER 2022)
else()
message(FATAL_ERROR "Unhandled MSVC version")
endif()
set(WINTER_LLVM_DIR "${LIBS_DIR}/llvm/llvm_${LLVM_VERSION_PATH}_install_vs${WINTER_VS_VER}_64")
elseif(APPLE)
set(WINTER_LLVM_DIR "${LIBS_DIR}/llvm/llvm_${LLVM_VERSION_PATH}_install")
else() # else Linux.
set(WINTER_LLVM_DIR "${LIBS_DIR}/llvm/llvm_${LLVM_VERSION_PATH}_dylib_install")
endif()
MESSAGE("LLVM dir: ${WINTER_LLVM_DIR}")
SET(WINTER_DIR ".")
# defines WINTER_FILES, WINTER_LLVM_LIBS
include(embed_winter.cmake)
SET(WINTER_FILES
winter.cpp
${WINTER_FILES}
)
SOURCE_GROUP(winter FILES ${WINTER_FILES})
SOURCE_GROUP(utils FILES ${WINTER_UTIL_FILES})
SOURCE_GROUP(double_conversion FILES ${WINTER_DOUBLE_CONVERSION_FILES})
SOURCE_GROUP(opencl FILES ${WINTER_OPENCL_FILES})
SOURCE_GROUP(xxhash FILES ${WINTER_XXHASH_FILES})
include_directories(${WINTER_INCLUDE_DIRECTORIES})
add_executable("winter"
${WINTER_FILES}
${WINTER_OTHER_FILES}
)
set_target_properties(${CURRENT_TARGET} PROPERTIES
CXX_STANDARD 17 # Needed for LLVM 16.0.0
)
add_definitions("-DBUILD_TESTS=1")
if(WIN32)
add_definitions(-DUNICODE -D_UNICODE)
add_definitions(/MP) # Build with multiple processes
add_definitions(/W4) # Set warning level to 4
# Ignore some warnings
add_definitions(/wd4127) # 'conditional expression is constant' - don't want this warning as we tend to turn off code with 'if(false) {}'
add_definitions(/wd4100) # 'unreferenced formal parameter'
#add_definitions(/GS- /fp:fast)
add_definitions(-D__SSE__ -D__SSE2__ -D__SSE3__ -D__SSSE3__ -D__SSE4_1__)
# Append optimisation flags.
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ")
SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /O2 -D_SECURE_SCL=0 -DNDEBUG")
SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /O2 -D_SECURE_SCL=0 -DNDEBUG /Zi") # /Zi to produce a PDB file
elseif(APPLE)
else() # Linux
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -mssse3 -msse4.1 -Wno-reorder")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -mssse3 -msse4.1")
endif()
add_definitions("${WINTER_PREPROCESSOR_DEFINITIONS}")
# LLVM include path and compiler settings.
if(WIN32)
# Append LLVM paths for the configurations
SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /I\"${WINTER_LLVM_DIR}/include\"")
SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /I\"${WINTER_LLVM_DIR}/include\"")
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /I\"${WINTER_LLVM_DIR}_debug/include\"")
else()
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I${WINTER_LLVM_DIR}/include -I/usr/local/include")
endif()
# LLVM linker settings.
if(WIN32)
SET(LLVM_LINK_FLAGS_RELEASE "/LIBPATH:\"${WINTER_LLVM_DIR}/lib\"")
SET(LLVM_LINK_FLAGS_RELWITHDEBINFO "/LIBPATH:\"${WINTER_LLVM_DIR}/lib\"")
SET(LLVM_LINK_FLAGS_DEBUG "/LIBPATH:\"${WINTER_LLVM_DIR}_debug/lib\"")
SET(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} ${LLVM_LINK_FLAGS_RELEASE}")
SET(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO} ${LLVM_LINK_FLAGS_RELWITHDEBINFO}")
SET(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} ${LLVM_LINK_FLAGS_DEBUG}")
SET(CMAKE_MODULE_LINKER_FLAGS_RELEASE "${CMAKE_MODULE_LINKER_FLAGS_RELEASE} ${LLVM_LINK_FLAGS_RELEASE}")
SET(CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO} ${LLVM_LINK_FLAGS_RELWITHDEBINFO}")
SET(CMAKE_MODULE_LINKER_FLAGS_DEBUG "${CMAKE_MODULE_LINKER_FLAGS_DEBUG} ${LLVM_LINK_FLAGS_DEBUG}")
target_link_libraries(${CURRENT_TARGET}
${WINTER_LLVM_LIBS}
)
elseif(APPLE)
target_link_libraries(${CURRENT_TARGET}
${WINTER_LLVM_LIBS}
dl
pthread
curses # used by LLVM
z # Used by llvm
"-framework Foundation"
"-framework Carbon"
)
else()
target_link_libraries(${CURRENT_TARGET}
${WINTER_LLVM_LIBS}
dl
pthread
z # Used by llvm
)
endif()