generated from duckdb/extension-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
121 lines (108 loc) · 4.7 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
cmake_minimum_required(VERSION 3.5)
# Set extension name here
set(TARGET_NAME wvlet)
find_package(OpenSSL REQUIRED)
# Detect system and architecture
execute_process(
COMMAND uname -m
OUTPUT_VARIABLE SYSTEM_ARCH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
message(STATUS "Detected architecture: ${SYSTEM_ARCH}")
# Determine libraries for detected system and architecture
set(WVLET_STATIC_URL "")
set(WVLET_DYNAMIC_URL "")
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
if(VCPKG_TARGET_TRIPLET MATCHES "arm64-linux" OR SYSTEM_ARCH MATCHES ".*(arm64|aarch64).*")
set(WVLET_STATIC_URL "https://github.com/quackscience/wvlet-lib/releases/download/latest/linux-arm64_libwvlet.a")
set(WVLET_STATIC_PATH "${CMAKE_CURRENT_SOURCE_DIR}/third-party/linux-arm64_libwvlet.a")
set(WVLET_DYNAMIC_URL "https://github.com/quackscience/wvlet-lib/releases/download/latest/linux-arm64_libwvlet.so")
set(WVLET_DYNAMIC_PATH "${CMAKE_CURRENT_SOURCE_DIR}/third-party/linux-arm64_libwvlet.so")
elseif(VCPKG_TARGET_TRIPLET MATCHES "x64-linux" OR SYSTEM_ARCH MATCHES ".*(amd64|x86_64).*")
set(WVLET_STATIC_URL "https://github.com/quackscience/wvlet-lib/releases/download/latest/linux-x64_libwvlet.a")
set(WVLET_STATIC_PATH "${CMAKE_CURRENT_SOURCE_DIR}/third-party/linux-x64_libwvlet.a")
set(WVLET_DYNAMIC_URL "https://github.com/quackscience/wvlet-lib/releases/download/latest/linux-x64_libwvlet.so")
set(WVLET_DYNAMIC_PATH "${CMAKE_CURRENT_SOURCE_DIR}/third-party/linux-x64_libwvlet.so")
endif()
elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set(WVLET_STATIC_URL "https://github.com/quackscience/wvlet-lib/releases/download/latest/mac-arm64_libwvlet.a")
set(WVLET_STATIC_PATH "${CMAKE_CURRENT_SOURCE_DIR}/third-party/mac-arm64_libwvlet.a")
set(WVLET_DYNAMIC_URL "https://github.com/quackscience/wvlet-lib/releases/download/latest/mac-arm64_libwvlet.dylib")
set(WVLET_DYNAMIC_PATH "${CMAKE_CURRENT_SOURCE_DIR}/third-party/mac-arm64_libwvlet.dylib")
else()
message(FATAL_ERROR "Unsupported system: ${CMAKE_SYSTEM_NAME} ${CMAKE_SYSTEM_PROCESSOR}")
endif()
# Function to download library if it doesn't exist
function(download_library url path)
if(NOT EXISTS ${path})
message(STATUS "Downloading wvlet library from ${url}")
file(MAKE_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/third-party")
file(DOWNLOAD
${url}
${path}
SHOW_PROGRESS
STATUS DOWNLOAD_STATUS
TLS_VERIFY ON)
list(GET DOWNLOAD_STATUS 0 STATUS_CODE)
if(NOT STATUS_CODE EQUAL 0)
message(FATAL_ERROR "Failed to download wvlet library from ${url}")
endif()
endif()
endfunction()
# Download both libraries
download_library(${WVLET_STATIC_URL} ${WVLET_STATIC_PATH})
download_library(${WVLET_DYNAMIC_URL} ${WVLET_DYNAMIC_PATH})
set(EXTENSION_NAME ${TARGET_NAME}_extension)
set(LOADABLE_EXTENSION_NAME ${TARGET_NAME}_loadable_extension)
project(${TARGET_NAME})
include_directories(src/include)
set(EXTENSION_SOURCES src/wvlet_extension.cpp)
build_static_extension(${TARGET_NAME} ${EXTENSION_SOURCES})
build_loadable_extension(${TARGET_NAME} " " ${EXTENSION_SOURCES})
# Create list of libraries in correct order for static linking
set(STATIC_LIBS
-Wl,--whole-archive
${WVLET_STATIC_PATH}
-Wl,--no-whole-archive
# Runtime dependencies
${CMAKE_DL_LIBS}
-pthread
OpenSSL::Crypto
OpenSSL::SSL
)
if(VCPKG_TARGET_TRIPLET MATCHES "arm64-linux" OR SYSTEM_ARCH MATCHES ".*(arm64|aarch64).*")
list(APPEND STATIC_LIBS "atomic")
# Use pkg-config to find and link libatomic-ops
find_package(PkgConfig REQUIRED)
pkg_check_modules(ATOMIC_OPS REQUIRED atomic_ops)
if(ATOMIC_OPS_FOUND)
message(STATUS "libatomic-ops found by pkg-config")
include_directories(${ATOMIC_OPS_INCLUDE_DIRS})
endif()
endif()
# For static extension, use static library with correct link order
target_link_libraries(${EXTENSION_NAME}
# ${WVLET_DYNAMIC_PATH}
${STATIC_LIBS}
)
# For loadable extension, use dynamic library
target_link_libraries(${LOADABLE_EXTENSION_NAME}
OpenSSL::SSL
OpenSSL::Crypto
${WVLET_DYNAMIC_PATH}
)
# Set link flags to ensure proper symbol resolution
if(VCPKG_TARGET_TRIPLET MATCHES "arm64-linux" OR SYSTEM_ARCH MATCHES ".*(arm64|aarch64).*")
set_target_properties(${EXTENSION_NAME} PROPERTIES
LINK_FLAGS "-Wl,--no-as-needed -Wl,-z,now -Wl,--export-dynamic" # -latomic
)
else()
set_target_properties(${EXTENSION_NAME} PROPERTIES
LINK_FLAGS "-Wl,--no-as-needed -Wl,-z,now -Wl,--export-dynamic"
)
endif()
install(
TARGETS ${EXTENSION_NAME}
EXPORT "${DUCKDB_EXPORT_SET}"
LIBRARY DESTINATION "${INSTALL_LIB_DIR}"
ARCHIVE DESTINATION "${INSTALL_LIB_DIR}")