Skip to content

Commit

Permalink
cmake: Don't use -static-libstdc++ unless it was built with -fPIC.
Browse files Browse the repository at this point in the history
  • Loading branch information
jrfonseca committed Mar 13, 2015
1 parent b132f86 commit 0953138
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion wrappers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,23 @@ if (ENABLE_STATIC_LIBGCC)
add_linker_flags ("-static-libgcc")
endif ()
if (ENABLE_STATIC_LIBSTDCXX)
add_linker_flags ("-static-libstdc++")
# Unfortunately for a long time static libstdcxx didn't built with -fPIC
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=28811
include (CheckCXXSourceCompiles)
set (CMAKE_REQUIRED_FLAGS ${CMAKE_SHARED_LIBRARY_C_FLAGS})
set (CMAKE_REQUIRED_LIBRARIES -shared -static-libgcc -static-libstdc++)
check_cxx_source_compiles (
"
#include <string>
std::string s;
"
STATIC_LIBSTDCXX_PIC
)
unset (CMAKE_REQUIRED_LIBRARIES)
unset (CMAKE_REQUIRED_FLAGS)
if (STATIC_LIBSTDCXX_PIC)
add_linker_flags ("-static-libstdc++")
endif ()
endif ()

set (CMAKE_INCLUDE_CURRENT_DIR ON)
Expand Down

0 comments on commit 0953138

Please sign in to comment.