Skip to content

Commit 536b068

Browse files
arrowdTheAssassin
authored andcommitted
Check if -static-{libgcc,libstdc++} flags are supported before passing them
Clang does not support these flags and -static is enough to link everything statically. This fixes build on FreeBSD.
1 parent f62e84f commit 536b068

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

src/CMakeLists.txt

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,28 @@ endif()
1414

1515
set(_target_name linuxdeploy-plugin-appimage)
1616

17+
# Clang does not support -static-libstdc++ and -static-libgcc, but just -static
18+
# is enough to link everything statically. We check for these flags and only
19+
# use them if they're supported.
20+
include(CheckCXXCompilerFlag)
21+
check_cxx_compiler_flag(-static-libstdc++ STATIC_LIBSTDCXX_SUPPORTED)
22+
check_cxx_compiler_flag(-static-libgcc STATIC_LIBGCC_SUPPORTED)
23+
1724
# main executable
1825
add_executable(${_target_name} main.cpp)
1926

2027
target_link_libraries(${_target_name} args)
2128

2229
set(_cflags
2330
-static
24-
-static-libstdc++
25-
-static-libgcc
2631
-flto
2732
)
33+
if(STATIC_LIBSTDCXX_SUPPORTED)
34+
list(APPEND _cflags -static-libstdc++)
35+
endif()
36+
if(STATIC_LIBGCC_SUPPORTED)
37+
list(APPEND _cflags -static-libgcc)
38+
endif()
2839
target_compile_options(${_target_name} PUBLIC ${_cflags})
2940
target_link_options(${_target_name} PUBLIC ${_cflags})
3041

0 commit comments

Comments
 (0)