llvm.org GIT mirror llvm / 1e67d66
[build] Make sure to link main executable with pthreads Otherwise it gets linked in by one of the dependencies of shared libraries which may be too late and we end up with weird crashes in std::call_once(). Differential Revision: http://reviews.llvm.org/D21478 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@273302 91177308-0d34-0410-b5e6-96231b3b80d8 Artem Belevich 3 years ago
3 changed file(s) with 24 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
109109 endif()
110110
111111 if(HAVE_LIBPTHREAD)
112 set(PTHREAD_LIB pthread)
112 # We want to find pthreads library and at the moment we do want to
113 # have it reported as '-l' instead of '-pthread'.
114 # TODO: switch to -pthread once the rest of the build system can deal with it.
115 set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
116 set(THREADS_HAVE_PTHREAD_ARG Off)
117 find_package(Threads REQUIRED)
118 set(PTHREAD_LIB ${CMAKE_THREAD_LIBS_INIT})
113119 endif()
114120
115121 # Don't look for these libraries on Windows. Also don't look for them if we're
668668
669669 if(NOT ARG_IGNORE_EXTERNALIZE_DEBUGINFO)
670670 llvm_externalize_debuginfo(${name})
671 endif()
672 if (PTHREAD_LIB)
673 # libpthreads overrides some standard library symbols, so main
674 # executable must be linked with it in order to provide consistent
675 # API for all shared libaries loaded by this executable.
676 target_link_libraries(${name} ${PTHREAD_LIB})
671677 endif()
672678 endmacro(add_llvm_executable name)
673679
952958 add_llvm_executable(${test_name} IGNORE_EXTERNALIZE_DEBUGINFO ${ARGN})
953959 set(outdir ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR})
954960 set_output_directory(${test_name} BINARY_DIR ${outdir} LIBRARY_DIR ${outdir})
955 target_link_libraries(${test_name} gtest_main gtest)
961 # libpthreads overrides some standard library symbols, so main
962 # executable must be linked with it in order to provide consistent
963 # API for all shared libaries loaded by this executable.
964 target_link_libraries(${test_name} gtest_main gtest ${PTHREAD_LIB})
956965
957966 add_dependencies(${test_suite} ${test_name})
958967 get_target_property(test_suite_folder ${test_suite} FOLDER)
1313 if(MSVC)
1414 set(SYSTEM_LIBS ${SYSTEM_LIBS} "${l}.lib")
1515 else()
16 set(SYSTEM_LIBS ${SYSTEM_LIBS} "-l${l}")
16 if (l MATCHES "^-")
17 # If it's an option, pass it without changes.
18 set(SYSTEM_LIBS ${SYSTEM_LIBS} "${l}")
19 else()
20 # Otherwise assume it's a library name we need to link with.
21 set(SYSTEM_LIBS ${SYSTEM_LIBS} "-l${l}")
22 endif()
1723 endif()
1824 endforeach()
1925 string(REPLACE ";" " " SYSTEM_LIBS "${SYSTEM_LIBS}")