From daf5480c483ae5a9c6153e1e38748c166d3eeb4f Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Sat, 1 Mar 2014 16:03:01 -0700 Subject: [PATCH] Fix up the pthread usage on broken ubuntu gcc4.8.1 For more information: http://stackoverflow.com/questions/19463602/compiling-multithread-code-with-g --- CMakeLists.txt | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index acf6de8..c122aac 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -75,6 +75,7 @@ if (CMAKE_COMPILER_IS_GNUCC) execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION) + if (GCC_VERSION VERSION_LESS 4.8) SET(CPP11_FLAG "-std=c++0x") else() @@ -101,12 +102,12 @@ if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") if (USE_LIBCXX) add_definitions(-stdlib=libc++) - set (EXTRA_LINKER_FLAGS ${CPP11_FLAG}-stdlib=libc++) + set (EXTRA_LINKER_FLAGS ${CPP11_FLAG} -stdlib=libc++) else () - set (EXTRA_LINKER_FLAGS ${CPP11_FLAG} ) + set (EXTRA_LINKER_FLAGS ${CPP11_FLAG}) endif() else() - set (EXTRA_LINKER_FLAGS ) + set (EXTRA_LINKER_FLAGS ${CPP11_FLAG}) endif() # limitations in MinGW require us to make an optimized build @@ -133,9 +134,20 @@ if (CMAKE_HOST_UNIX) endif(NOT ${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") if (MULTITHREAD_SUPPORT_ENABLED) - list(APPEND LIBS "pthread") + if (CMAKE_COMPILER_IS_GNUCC) + execute_process(COMMAND ${CMAKE_C_COMPILER} --version OUTPUT_VARIABLE GCC_FULL_VERSION) + if (GCC_FULL_VERSION MATCHES "4.8.1.*ubuntu") + set (EXTRA_LINKER_FLAGS ${EXTRA_LINKER_FLAGS} -Wl,--no-as-needed -pthread ) + else() + set (EXTRA_LINKER_FLAGS ${EXTRA_LINKER_FLAGS} -pthread ) + endif() + else() + set (EXTRA_LINKER_FLAGS ${EXTRA_LINKER_FLAGS} -pthread ) + endif() + add_definitions(-pthread) endif() + endif(CMAKE_HOST_UNIX) list(APPEND LIBS ${READLINE_LIB}) @@ -147,7 +159,7 @@ if (CMAKE_COMPILER_2005) endif() add_library(chaiscript_stdlib MODULE src/chaiscript_stdlib.cpp) -target_link_libraries(chaiscript_stdlib ${LIBS} ${EXTRA_LINKER_FLAGS}) +target_link_libraries(chaiscript_stdlib ${LIBS} ${EXTRA_LINKER_FLAGS} ${CMAKE_THREAD_LIBS_INIT}) add_executable(chai src/main.cpp ${Chai_INCLUDES}) target_link_libraries(chai ${LIBS} ${EXTRA_LINKER_FLAGS})