Skip to content

Commit ff27a80

Browse files
authored
Fix building on FreeBSD via cmake (#925)
Currently building swift-testing via cmake (e.g. when building the toolchain) fail if not compile as PIC. Adding "-fPIC" fixed this problem. Moreover, we need to link against `libexecinfo` on FreeBSD where the symbol `backtrace` lives. ### Result: Swift testing can now successfully build via cmake thus installed to the toolchain 🥳
1 parent 88cb1a4 commit ff27a80

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

Sources/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ if(SwiftTesting_MACRO STREQUAL "<auto>")
6666
if(NOT SwiftTesting_BuildMacrosAsExecutables)
6767
if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin")
6868
set(SwiftTesting_MACRO_PATH "${SwiftTesting_MACRO_INSTALL_PREFIX}/lib/swift/host/plugins/testing/libTestingMacros.dylib")
69-
elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux")
69+
elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux" or CMAKE_HOST_SYSTEM_NAME STREQUAL "FreeBSD")
7070
set(SwiftTesting_MACRO_PATH "${SwiftTesting_MACRO_INSTALL_PREFIX}/lib/swift/host/plugins/libTestingMacros.so")
7171
elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
7272
set(SwiftTesting_MACRO_PATH "${SwiftTesting_MACRO_INSTALL_PREFIX}/bin/TestingMacros.dll")

Sources/Testing/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ if(NOT APPLE)
113113
endif()
114114
target_link_libraries(Testing PUBLIC
115115
Foundation)
116+
if (CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
117+
target_link_libraries(Testing PUBLIC execinfo)
118+
endif()
116119
endif()
117120
if(NOT BUILD_SHARED_LIBS)
118121
# When building a static library, tell clients to autolink the internal

Sources/_TestingInternals/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ if("${CMAKE_CXX_COMPILER_FRONTEND_VARIANT}" STREQUAL "MSVC" OR
2020
"${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
2121
target_compile_options(_TestingInternals PRIVATE
2222
/EHa-c)
23+
elseif(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
24+
target_compile_options(_TestingInternals PRIVATE
25+
-fno-exceptions -fPIC)
2326
else()
2427
target_compile_options(_TestingInternals PRIVATE
2528
-fno-exceptions)

0 commit comments

Comments
 (0)