Fix up the pthread usage on broken ubuntu gcc4.8.1

For more information:

http://stackoverflow.com/questions/19463602/compiling-multithread-code-with-g
This commit is contained in:
Jason Turner 2014-03-01 16:03:01 -07:00
parent 1f2c9b0c77
commit daf5480c48

View File

@ -75,6 +75,7 @@ if (CMAKE_COMPILER_IS_GNUCC)
execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion
OUTPUT_VARIABLE GCC_VERSION) OUTPUT_VARIABLE GCC_VERSION)
if (GCC_VERSION VERSION_LESS 4.8) if (GCC_VERSION VERSION_LESS 4.8)
SET(CPP11_FLAG "-std=c++0x") SET(CPP11_FLAG "-std=c++0x")
else() else()
@ -106,7 +107,7 @@ if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set (EXTRA_LINKER_FLAGS ${CPP11_FLAG}) set (EXTRA_LINKER_FLAGS ${CPP11_FLAG})
endif() endif()
else() else()
set (EXTRA_LINKER_FLAGS ) set (EXTRA_LINKER_FLAGS ${CPP11_FLAG})
endif() endif()
# limitations in MinGW require us to make an optimized build # 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") endif(NOT ${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
if (MULTITHREAD_SUPPORT_ENABLED) 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) add_definitions(-pthread)
endif() endif()
endif(CMAKE_HOST_UNIX) endif(CMAKE_HOST_UNIX)
list(APPEND LIBS ${READLINE_LIB}) list(APPEND LIBS ${READLINE_LIB})
@ -147,7 +159,7 @@ if (CMAKE_COMPILER_2005)
endif() endif()
add_library(chaiscript_stdlib MODULE src/chaiscript_stdlib.cpp) 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}) add_executable(chai src/main.cpp ${Chai_INCLUDES})
target_link_libraries(chai ${LIBS} ${EXTRA_LINKER_FLAGS}) target_link_libraries(chai ${LIBS} ${EXTRA_LINKER_FLAGS})