Skip to content

Commit c9133e5

Browse files
committed
Moar
1 parent 6d4defe commit c9133e5

File tree

8 files changed

+71
-15
lines changed

8 files changed

+71
-15
lines changed

CMakeLists.txt

-13
Original file line numberDiff line numberDiff line change
@@ -115,19 +115,6 @@ if (CH_ODBC_RUNTIME_LINK_STATIC)
115115
string (REPLACE "-MD" "-MT" ${var} "${${var}}")
116116
endforeach ()
117117
endforeach ()
118-
elseif (
119-
CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR
120-
(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND NOT APPLE)
121-
)
122-
if (NOT APPLE AND NOT WIN32 AND NOT ARCH_FREEBSD)
123-
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--whole-archive -static-libgcc -static-libstdc++ -Wl,--no-whole-archive")
124-
set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--whole-archive -static-libgcc -static-libstdc++ -Wl,--no-whole-archive")
125-
else ()
126-
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc -static-libstdc++")
127-
set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-libgcc -static-libstdc++")
128-
endif ()
129-
else ()
130-
message (WARNING "linking with compiler and language runtime statically is not supported in the current build environment")
131118
endif()
132119
endif ()
133120

cmake/linux/default_libs.cmake

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Set standard, system and compiler libraries explicitly.
22
# This is intended for more control of what we are linking.
33

4+
set (DEFAULT_LIBS "-nodefaultlibs")
5+
46
# We need builtins from Clang's RT even without libcxx - for ubsan+int128.
57
# See https://bugs.llvm.org/show_bug.cgi?id=16404
68
execute_process (COMMAND
@@ -38,6 +40,8 @@ set(THREADS_PREFER_PTHREAD_FLAG ON)
3840
find_package(Threads REQUIRED)
3941

4042
include (cmake/cxx.cmake)
43+
include (cmake/unwind.cmake)
44+
4145
link_libraries(global-group)
4246

4347
target_link_libraries(global-group INTERFACE

cmake/unwind.cmake

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
add_subdirectory(contrib/libunwind-cmake)

contrib/libunwind

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit 601db0b0e03018c01710470a37703b618f9cf08b
+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
set(LIBUNWIND_SOURCE_DIR "${CMAKE_SOURCE_DIR}/contrib/libunwind")
2+
3+
set(LIBUNWIND_CXX_SOURCES
4+
"${LIBUNWIND_SOURCE_DIR}/src/libunwind.cpp"
5+
"${LIBUNWIND_SOURCE_DIR}/src/Unwind-EHABI.cpp"
6+
"${LIBUNWIND_SOURCE_DIR}/src/Unwind-seh.cpp")
7+
8+
set(LIBUNWIND_C_SOURCES
9+
"${LIBUNWIND_SOURCE_DIR}/src/UnwindLevel1.c"
10+
"${LIBUNWIND_SOURCE_DIR}/src/UnwindLevel1-gcc-ext.c"
11+
"${LIBUNWIND_SOURCE_DIR}/src/Unwind-sjlj.c"
12+
# Use unw_backtrace to override libgcc's backtrace symbol for better ABI compatibility
13+
unwind-override.c)
14+
set_source_files_properties(${LIBUNWIND_C_SOURCES} PROPERTIES COMPILE_FLAGS "-std=c99")
15+
16+
set(LIBUNWIND_ASM_SOURCES
17+
"${LIBUNWIND_SOURCE_DIR}/src/UnwindRegistersRestore.S"
18+
"${LIBUNWIND_SOURCE_DIR}/src/UnwindRegistersSave.S")
19+
20+
enable_language(ASM)
21+
22+
set(LIBUNWIND_SOURCES
23+
${LIBUNWIND_CXX_SOURCES}
24+
${LIBUNWIND_C_SOURCES}
25+
${LIBUNWIND_ASM_SOURCES})
26+
27+
add_library(unwind ${LIBUNWIND_SOURCES})
28+
set_target_properties(unwind PROPERTIES FOLDER "contrib/libunwind-cmake")
29+
30+
target_include_directories(unwind SYSTEM BEFORE PUBLIC $<BUILD_INTERFACE:${LIBUNWIND_SOURCE_DIR}/include>)
31+
target_compile_definitions(unwind PRIVATE -D_LIBUNWIND_NO_HEAP=1)
32+
target_compile_definitions(unwind PRIVATE -D_LIBUNWIND_REMEMBER_STACK_ALLOC=1)
33+
# NOTE: from this macros sizeof(unw_context_t)/sizeof(unw_cursor_t) is depends, so it should be set always
34+
target_compile_definitions(unwind PUBLIC -D_LIBUNWIND_IS_NATIVE_ONLY)
35+
36+
# We should enable optimizations (otherwise it will be too slow in debug)
37+
# and disable sanitizers (otherwise infinite loop may happen)
38+
target_compile_options(unwind PRIVATE -O3 -fno-exceptions -funwind-tables -fno-sanitize=all $<$<COMPILE_LANGUAGE:CXX>:-nostdinc++ -fno-rtti>)
39+
40+
target_compile_options(unwind PRIVATE -Wno-unused-but-set-variable)
41+
42+
# The library is using register variables that are bound to specific registers
43+
# Example: DwarfInstructions.hpp: register unsigned long long x16 __asm("x16") = cfa;
44+
target_compile_options(unwind PRIVATE "$<$<COMPILE_LANGUAGE:CXX>:-Wno-register>")
45+
46+
install(
47+
TARGETS unwind
48+
EXPORT global
49+
LIBRARY DESTINATION lib
50+
ARCHIVE DESTINATION lib
51+
)
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include <libunwind.h>
2+
3+
/// On MacOS this function will be replaced with a dynamic symbol
4+
/// from the system library.
5+
#if !defined(OS_DARWIN)
6+
int backtrace(void ** buffer, int size)
7+
{
8+
return unw_backtrace(buffer, size);
9+
}
10+
#endif

driver/CMakeLists.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,9 @@ target_link_libraries (${libname}-impl
172172
)
173173

174174
if (ARCH_LINUX)
175-
target_link_libraries (${libname}-impl PUBLIC ch_contrib::unixodbc ch_contrib::nanodbc)
175+
target_link_libraries (${libname}-impl
176+
PUBLIC ch_contrib::unixodbc
177+
PUBLIC ch_contrib::nanodbc)
176178
else()
177179
target_link_libraries (${libname}-impl PUBLIC ODBC::Driver)
178180
endif()

driver/test/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ function (declare_odbc_test_targets libname UNICODE)
8383
)
8484

8585
if (ARCH_LINUX)
86-
target_link_libraries (${libname}-impl PUBLIC ch_contrib::unixodbc ch_contrib:nanodbc)
86+
target_link_libraries (${libname}-impl PUBLIC ch_contrib::unixodbc ch_contrib::nanodbc)
8787
else()
8888
target_link_libraries (${libname}-impl PUBLIC ODBC::App)
8989
endif()

0 commit comments

Comments
 (0)