-
Notifications
You must be signed in to change notification settings - Fork 16
/
CMakeLists.txt
95 lines (82 loc) · 3.23 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
cmake_minimum_required(VERSION 3.16 FATAL_ERROR)
project(adbc_nif C CXX)
if(NOT DEFINED PRIV_DIR)
if(DEFINED MIX_APP_PATH AND NOT "${MIX_APP_PATH}" STREQUAL "")
if(WIN32)
string(REPLACE "\\" "/" MIX_APP_PATH "${MIX_APP_PATH}")
endif()
set(PRIV_DIR "${MIX_APP_PATH}/priv")
else()
set(PRIV_DIR "${CMAKE_CURRENT_SOURCE_DIR}/priv")
endif()
endif()
message(STATUS "Using PRIV_DIR: ${PRIV_DIR}")
if(DEFINED ERTS_INCLUDE_DIR AND NOT "${ERTS_INCLUDE_DIR}" STREQUAL "")
set(ERTS_INCLUDE_DIR "${ERTS_INCLUDE_DIR}")
else()
set(ERTS_INCLUDE_DIR_ONE_LINER "erl -noshell -eval \"io:format('~ts/erts-~ts/include/', [code:root_dir(), erlang:system_info(version)]), halt().\"")
if(WIN32)
execute_process(COMMAND powershell -command "${ERTS_INCLUDE_DIR_ONE_LINER}" OUTPUT_VARIABLE ERTS_INCLUDE_DIR)
else()
execute_process(COMMAND bash -c "${ERTS_INCLUDE_DIR_ONE_LINER}" OUTPUT_VARIABLE ERTS_INCLUDE_DIR)
endif()
set(ERTS_INCLUDE_DIR "${ERTS_INCLUDE_DIR}")
endif()
message(STATUS "Using ERTS_INCLUDE_DIR: ${ERTS_INCLUDE_DIR}")
if(UNIX AND APPLE)
set(CMAKE_SHARED_LINKER_FLAGS "-undefined dynamic_lookup")
endif()
set(CMAKE_CXX_STANDARD 17)
if(DEFINED ENV{TARGET_GCC_FLAGS})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} $ENV{TARGET_GCC_FLAGS}")
endif()
message(STATUS "CMAKE_TOOLCHAIN_FILE: ${CMAKE_TOOLCHAIN_FILE}")
find_package(AdbcDriverManager REQUIRED PATHS "${PRIV_DIR}/" NO_DEFAULT_PATH)
include_directories("${PRIV_DIR}/include")
if(WIN32)
string(REPLACE "\\" "/" C_SRC "${C_SRC}")
endif()
set(SOURCE_FILES
"${C_SRC}/nif_utils.cpp"
"${C_SRC}/adbc_nif.cpp"
)
include_directories("${ERTS_INCLUDE_DIR}")
include_directories("${ADBC_SRC}/c/include")
add_subdirectory("${ADBC_SRC}/c/vendor/nanoarrow")
include_directories("${ADBC_SRC}/c/vendor")
add_library(adbc_nif SHARED
${SOURCE_FILES}
)
target_link_libraries(adbc_nif PUBLIC AdbcDriverManager::adbc_driver_manager_shared)
target_link_libraries(adbc_nif PUBLIC nanoarrow)
install(
TARGETS adbc_nif
RUNTIME DESTINATION "${PRIV_DIR}"
)
set_target_properties(adbc_nif PROPERTIES PREFIX "")
if(NOT WIN32)
set_target_properties(adbc_nif PROPERTIES SUFFIX ".so")
endif()
set_target_properties(adbc_nif PROPERTIES
INSTALL_RPATH_USE_LINK_PATH TRUE
BUILD_WITH_INSTALL_RPATH TRUE
)
if(UNIX AND NOT APPLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-unused-but-set-variable -Wno-reorder")
set_target_properties(adbc_nif PROPERTIES INSTALL_RPATH "\$ORIGIN/lib")
elseif(UNIX AND APPLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-reorder-ctor")
set(CMAKE_SHARED_LINKER_FLAGS "-flat_namespace -undefined dynamic_lookup")
set_target_properties(adbc_nif PROPERTIES INSTALL_RPATH "@loader_path/lib")
endif()
if(WIN32)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj /wd4996 /wd4267 /wd4068")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 -g3")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-function -Wno-sign-compare -Wno-unused-parameter -Wno-missing-field-initializers -Wno-deprecated-declarations")
endif()