-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathCMakeLists.txt
199 lines (177 loc) · 6.54 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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
cmake_minimum_required(VERSION 3.16)
include(FetchContent)
if(NOT CMAKE_TOOLCHAIN_FILE)
set(CMAKE_TOOLCHAIN_FILE
"${CMAKE_CURRENT_SOURCE_DIR}/build/emsdk/upstream/emscripten/cmake/Modules/Platform/\
Emscripten.cmake"
)
endif()
# Extract the project name & version from package.json
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/package.json")
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/package.json" CLP_FFI_JS_PACKAGE_JSON_CONTENT)
else()
message(FATAL_ERROR "`package.json` not found in ${CMAKE_CURRENT_SOURCE_DIR}")
endif()
if("${CLP_FFI_JS_PACKAGE_JSON_CONTENT}" MATCHES "\"name\":[ ]*\"([^\"]+)\"")
set(CLP_FFI_JS_PROJECT_NAME "${CMAKE_MATCH_1}")
else()
set(CLP_FFI_JS_PROJECT_NAME "clp-ffi-js")
endif()
if("${CLP_FFI_JS_PACKAGE_JSON_CONTENT}" MATCHES "\"version\":[ ]*\"([^\"]+)\"")
set(CLP_FFI_JS_VERSION "${CMAKE_MATCH_1}")
else()
set(CLP_FFI_JS_VERSION "0.0.0")
endif()
project(
"${CLP_FFI_JS_PROJECT_NAME}"
LANGUAGES
C
CXX
VERSION "${CLP_FFI_JS_VERSION}"
)
# Enable exporting compile commands
set(CMAKE_EXPORT_COMPILE_COMMANDS
ON
CACHE BOOL
"Enable/Disable output of compile commands during generation."
FORCE
)
# Disable response files since `clang-tidy` doesn't seem to be able to use them
set(CMAKE_CXX_USE_RESPONSE_FILE_FOR_INCLUDES OFF)
# Set the default build type to Release if not specified
if(NOT CMAKE_BUILD_TYPE)
set(CLP_FFI_JS_DEFAULT_BUILD_TYPE "Release")
message(STATUS "No build type specified. Setting to '${CLP_FFI_JS_DEFAULT_BUILD_TYPE}'.")
set(CMAKE_BUILD_TYPE
"${CLP_FFI_JS_DEFAULT_BUILD_TYPE}"
CACHE STRING
"Choose the type of build."
FORCE
)
endif()
# Download and extract Boost
set(CLP_FFI_JS_BOOST_VERSION "1.85.0" CACHE STRING "Version of Boost library to use.")
string(REPLACE "." "_" CLP_FFI_JS_BOOST_ARCHIVE_VERSION_PART ${CLP_FFI_JS_BOOST_VERSION})
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL 3.24)
# Sets DOWNLOAD_EXTRACT_TIMESTAMP=ON in FetchContent_Declare()
cmake_policy(SET CMP0135 NEW)
endif()
FetchContent_Declare(
Boost
URL
"https://archives.boost.io/release/${CLP_FFI_JS_BOOST_VERSION}/source/\
boost_${CLP_FFI_JS_BOOST_ARCHIVE_VERSION_PART}.tar.gz"
URL_MD5 "53aeccc3167909ee770e34469f8dd592"
)
message(STATUS "Fetching Boost.")
FetchContent_MakeAvailable(Boost)
message("Boost sources successfully fetched into ${boost_SOURCE_DIR}")
set(CMAKE_EXECUTABLE_SUFFIX ".js" CACHE STRING "Binary type to be generated by Emscripten.")
# Set up common compile and link options to be merged with other options as necessary.
set(CLP_FFI_JS_COMMON_COMPILE_OPTIONS
-fwasm-exceptions
)
set(CLP_FFI_JS_COMMON_LINK_OPTIONS
-fwasm-exceptions
-sALLOW_MEMORY_GROWTH
-sEXPORT_ES6
-sMAXIMUM_MEMORY=4GB
-sMODULARIZE
-sWASM_BIGINT
)
if(CMAKE_BUILD_TYPE MATCHES "Release")
list(APPEND CLP_FFI_JS_COMMON_COMPILE_OPTIONS
-flto
)
list(APPEND CLP_FFI_JS_COMMON_LINK_OPTIONS
-flto
--closure=1
)
endif()
set(CLP_FFI_JS_SRC_MAIN
src/clp_ffi_js/ir/StreamReader.cpp
src/clp_ffi_js/ir/StructuredIrStreamReader.cpp
src/clp_ffi_js/ir/StructuredIrUnitHandler.cpp
src/clp_ffi_js/ir/UnstructuredIrStreamReader.cpp
)
set(CLP_FFI_JS_SRC_CLP_CORE
src/submodules/clp/components/core/src/clp/ffi/ir_stream/decoding_methods.cpp
src/submodules/clp/components/core/src/clp/ffi/ir_stream/ir_unit_deserialization_methods.cpp
src/submodules/clp/components/core/src/clp/ffi/ir_stream/utils.cpp
src/submodules/clp/components/core/src/clp/ffi/KeyValuePairLogEvent.cpp
src/submodules/clp/components/core/src/clp/ffi/SchemaTree.cpp
src/submodules/clp/components/core/src/clp/ir/EncodedTextAst.cpp
src/submodules/clp/components/core/src/clp/ir/LogEventDeserializer.cpp
src/submodules/clp/components/core/src/clp/ReadOnlyMemoryMappedFile.cpp
src/submodules/clp/components/core/src/clp/ReaderInterface.cpp
src/submodules/clp/components/core/src/clp/streaming_compression/zstd/Decompressor.cpp
src/submodules/clp/components/core/src/clp/TimestampPattern.cpp
)
set(CLP_FFI_JS_SRC_FMT src/submodules/fmt/src/format.cc)
set(CLP_FFI_JS_SRC_ZSTD
src/submodules/zstd/lib/common/entropy_common.c
src/submodules/zstd/lib/common/error_private.c
src/submodules/zstd/lib/common/fse_decompress.c
src/submodules/zstd/lib/common/zstd_common.c
src/submodules/zstd/lib/common/zstd_trace.c
src/submodules/zstd/lib/common/xxhash.c
src/submodules/zstd/lib/decompress/huf_decompress.c
src/submodules/zstd/lib/decompress/zstd_ddict.c
src/submodules/zstd/lib/decompress/zstd_decompress_block.c
src/submodules/zstd/lib/decompress/zstd_decompress.c
)
set(CLP_FFI_JS_SUPPORTED_ENVIRONMENTS
node
worker
CACHE INTERNAL
"List of supported environments."
)
foreach(env ${CLP_FFI_JS_SUPPORTED_ENVIRONMENTS})
set(CLP_FFI_JS_BIN_NAME "ClpFfiJs-${env}")
add_executable(${CLP_FFI_JS_BIN_NAME})
# Set up compile options
target_compile_features(${CLP_FFI_JS_BIN_NAME} PRIVATE cxx_std_20)
target_compile_definitions(${CLP_FFI_JS_BIN_NAME} PUBLIC SPDLOG_FMT_EXTERNAL=1)
target_compile_options(${CLP_FFI_JS_BIN_NAME} PRIVATE ${CLP_FFI_JS_COMMON_COMPILE_OPTIONS})
# Set up link options
target_link_libraries(${CLP_FFI_JS_BIN_NAME} PRIVATE embind)
set(CLP_FFI_JS_LINK_OPTIONS
${CLP_FFI_JS_COMMON_LINK_OPTIONS}
--emit-tsd=${CLP_FFI_JS_BIN_NAME}.d.ts
-sENVIRONMENT=${env}
)
target_link_options(
${CLP_FFI_JS_BIN_NAME}
PRIVATE
${CLP_FFI_JS_LINK_OPTIONS}
)
message(
"CLP_FFI_JS_BIN_NAME=\"${CLP_FFI_JS_BIN_NAME}\". \
CMAKE_BUILD_TYPE=\"${CMAKE_BUILD_TYPE}\". \
Compile options: ${CLP_FFI_JS_COMMON_COMPILE_OPTIONS}. \
Link options: ${CLP_FFI_JS_LINK_OPTIONS}."
)
# NOTE: We mark the include directories below as system headers so that the compiler (including
# `clang-tidy`) doesn't generate warnings from them.
target_include_directories(
${CLP_FFI_JS_BIN_NAME}
SYSTEM
PRIVATE
${boost_SOURCE_DIR}
src/submodules/clp/components/core/src
src/submodules/clp/components/core/src/clp
src/submodules/clp/components/core/submodules
src/submodules/fmt/include
src/submodules/spdlog/include
src/submodules/zstd/lib
)
target_include_directories(${CLP_FFI_JS_BIN_NAME} PRIVATE src/)
target_sources(
${CLP_FFI_JS_BIN_NAME}
PRIVATE
${CLP_FFI_JS_SRC_MAIN}
${CLP_FFI_JS_SRC_CLP_CORE}
${CLP_FFI_JS_SRC_FMT}
${CLP_FFI_JS_SRC_ZSTD}
)
endforeach()