diff options
author | DRC <dcommander@users.sourceforge.net> | 2011-07-28 09:58:24 +0000 |
---|---|---|
committer | DRC <dcommander@users.sourceforge.net> | 2011-07-28 09:58:24 +0000 |
commit | 883f2d69ef603fa3b33cd93dde29d5b4d6ca9231 (patch) | |
tree | 5495771d0311d979ac8f9c8bee54ff8c7b768421 /CMakeLists.txt | |
parent | 95b083f2e0fb83376762e862eb9fdd046f295e09 (diff) | |
download | tigervnc-883f2d69ef603fa3b33cd93dde29d5b4d6ca9231.tar.gz tigervnc-883f2d69ef603fa3b33cd93dde29d5b4d6ca9231.zip |
Add a BUILD_STATIC option which links statically against libgcc and libstdc++ (if applicable.) Remove the corresponding code from build-xorg.
git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@4608 3789f03b-4d11-0410-bbf8-ca57d06f2519
Diffstat (limited to 'CMakeLists.txt')
-rw-r--r-- | CMakeLists.txt | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index ef347056..e67feb4f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -107,6 +107,44 @@ else() message(STATUS "32-bit build") endif() +# This ensures that we don't depend on libstdc++ or libgcc +if(CMAKE_COMPILER_IS_GNUCXX AND NOT APPLE AND NOT CYGWIN) + option(BUILD_STATIC + "Link statically against libgcc and libstdc++, if possible" OFF) + if(BUILD_STATIC) + # For some reason, simply passing ${CMAKE_CXX_FLAGS} to the compiler in + # execute_process() doesn't work. Grrr... + if(64BIT) + execute_process(COMMAND ${CMAKE_CXX_COMPILER} -m64 + --print-file-name=libstdc++.a OUTPUT_VARIABLE LIBSTDCPLUSPLUS + RESULT_VARIABLE RESULT) + else() + execute_process(COMMAND ${CMAKE_CXX_COMPILER} -m32 + --print-file-name=libstdc++.a OUTPUT_VARIABLE LIBSTDCPLUSPLUS + RESULT_VARIABLE RESULT) + endif() + string(REGEX REPLACE "\n" "" LIBSTDCPLUSPLUS ${LIBSTDCPLUSPLUS}) + if(RESULT MATCHES 0 AND LIBSTDCPLUSPLUS) + message(STATUS "Linking with static libstdc++:\n ${LIBSTDCPLUSPLUS}") + file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/staticlib) + execute_process(COMMAND ${CMAKE_COMMAND} -E remove + ${CMAKE_BINARY_DIR}/staticlib/libstdc++.a) + execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink + ${LIBSTDCPLUSPLUS} ${CMAKE_BINARY_DIR}/staticlib/libstdc++.a) + set(CMAKE_EXE_LINKER_FLAGS + "${CMAKE_EXE_LINKER_FLAGS} -L${CMAKE_BINARY_DIR}/staticlib") + set(CMAKE_SHARED_LINKER_FLAGS + "${CMAKE_SHARED_LINKER_FLAGS} -L${CMAKE_BINARY_DIR}/staticlib") + else() + message(WARNING Cannot find static libstdc++. VirtualGL will depend on dynamic libstdc++.) + endif() + add_definitions(-static-libgcc) + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc") + set(CMAKE_SHARED_LINKER_FLAGS + "${CMAKE_SHARED_LINKER_FLAGS} -static-libgcc") + endif() +endif() + # CMake doesn't properly support resource compilation with MinGW. Boo! if(MINGW) if(NOT DEFINED RC) |