-
Notifications
You must be signed in to change notification settings - Fork 4
/
CMakeLists.txt
112 lines (91 loc) · 4 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
cmake_minimum_required(VERSION 3.22)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
project(TANTIVY_LIB)
set(SANITIZER "" CACHE STRING "Sanitizer to enable (address, thread, memory)")
message(${SANITIZER})
if(SANITIZER STREQUAL "address")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")
# set(CXXBRIDGE_CXXFLAGS "${CXXBRIDGE_CXXFLAGS} -fsanitize=address")
set(RUST_CXXFLAGS "${RUST_CXXFLAGS} -fsanitize=address")
elseif(SANITIZER STREQUAL "thread")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=thread -g -fno-omit-frame-pointer")
set(CXXBRIDGE_CXXFLAGS "${CXXBRIDGE_CXXFLAGS} -fsanitize=thread")
# set(RUST_CXXFLAGS "${RUST_CXXFLAGS} -Zsanitizer=thread")
set(RUST_CXXFLAGS "${RUST_CXXFLAGS} -fsanitize=thread")
# set(RUST_CXXFLAGS "${RUST_CXXFLAGS}")
elseif(SANITIZER STREQUAL "memory")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=memory")
# set(CXXBRIDGE_CXXFLAGS "${CXXBRIDGE_CXXFLAGS} -fsanitize=memory")
set(RUST_CXXFLAGS "${RUST_CXXFLAGS} -fsanitize=memory")
endif()
add_subdirectory(contrib ${CMAKE_CURRENT_BINARY_DIR}/contrib)
if(CMAKE_BUILD_TYPE STREQUAL "Release")
set(RUST_PROFILE release)
elseif(CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
set(RUST_PROFILE relwithdebinfo)
elseif(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(RUST_PROFILE dev)
else()
set(RUST_PROFILE release)
endif()
corrosion_import_crate(
MANIFEST_PATH "Cargo.toml"
PROFILE ${RUST_PROFILE}
)
set(rust_lib "tantivy_search")
# set(CMAKE_CXX_FLAGS " -std=c++11 -fsanitize=address -fsanitize-recover=all -fsanitize=leak")
# -Wno-dollar-in-identifier-extension: cxx bridge complies names with '$'
# -Wno-unused-macros: unused CXXBRIDGE1_RUST_STRING
set(CXXBRIDGE_CXXFLAGS "-Wno-dollar-in-identifier-extension -Wno-unused-macros")
set(RUST_CXXFLAGS "${CXXBRIDGE_CXXFLAGS} ${RUST_CXXFLAGS}")
message(STATUS "Config cxx-bridge, use RUST_CXXFLAGS: " ${RUST_CXXFLAGS})
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/.cargo/config.toml.in" "${CMAKE_CURRENT_SOURCE_DIR}/.cargo/config.toml" @ONLY)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/build.rs.in" "${CMAKE_CURRENT_SOURCE_DIR}/build.rs" @ONLY)
set(cxx_bridge_binary_folder ${CMAKE_BINARY_DIR}/cargo/build/${Rust_CARGO_TARGET_CACHED}/cxxbridge)
set(cxx_bridge_source_file "src/lib.rs")
set(common_header ${cxx_bridge_binary_folder}/rust/cxx.h)
# tantivy_search cxx header and source.
set(tantivy_search_header ${cxx_bridge_binary_folder}/${rust_lib}/${cxx_bridge_source_file}.h)
set(tantivy_search_source ${cxx_bridge_binary_folder}/${rust_lib}/${cxx_bridge_source_file}.cc)
# get include path
set(tantivy_search_include ${CMAKE_CURRENT_SOURCE_DIR}/include)
message(STATUS "❄️ -> common_header: ${tantivy_search_header}")
message(STATUS "❄️ -> tantivy_search header: ${tantivy_search_header}")
message(STATUS "❄️ -> tantivy_search source: ${tantivy_search_source}")
message(STATUS "❄️ -> tantivy_search include: ${tantivy_search_include}")
add_custom_command(
OUTPUT
${common_header}
${tantivy_search_header}
${tantivy_search_source}
COMMAND
DEPENDS ${rust_lib}-static
COMMENT "Fixing cmake to find source files"
)
add_library(${rust_lib}_cxxbridge
${common_header}
${skim_header}
${skim_source}
${tantivy_search_header}
${tantivy_search_source}
)
# cxx bridge compiles such bindings
set_target_properties(${rust_lib}_cxxbridge PROPERTIES COMPILE_FLAGS "${CXXBRIDGE_CXXFLAGS}")
set_target_properties(${rust_lib}_cxxbridge PROPERTIES LINKER_LANGUAGE CXX)
target_include_directories(${rust_lib}_cxxbridge
PUBLIC
${tantivy_search_include}
)
# Create total target with alias with given namespace
add_library(${rust_lib}-total INTERFACE)
target_link_libraries(${rust_lib}-total
INTERFACE
${rust_lib}_cxxbridge
${rust_lib}
)
# for end-user to link into project
add_library(rust::${rust_lib} ALIAS ${rust_lib}-total)
add_subdirectory(benchmark ${CMAKE_CURRENT_BINARY_DIR}/benchmark)
add_subdirectory(tests ${CMAKE_CURRENT_BINARY_DIR}/tests)