Skip to content
Snippets Groups Projects

Draft: Fix cmake threads

Closed Sergey Kosukhin requested to merge fix-cmake-threads into master
4 unresolved threads
Files
3
+ 31
8
@@ -2,7 +2,8 @@ include(CheckIncludeFiles)
@@ -2,7 +2,8 @@ include(CheckIncludeFiles)
check_include_files("execinfo.h" HAVE_EXECINFO_H)
check_include_files("execinfo.h" HAVE_EXECINFO_H)
check_include_files("link.h" HAVE_LINK_H)
check_include_files("link.h" HAVE_LINK_H)
check_include_files("unwind.h" HAVE_UNWIND_H)
check_include_files("unwind.h" HAVE_UNWIND_H)
check_include_files("pthread.h" HAVE_PTHREAD_H)
# We have already checked whether pthread.h is available:
 
set(HAVE_PTHREAD_H "${CMAKE_HAVE_PTHREAD_H}")
configure_file(
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/config.h.in
${CMAKE_CURRENT_SOURCE_DIR}/config.h.in
@@ -46,9 +47,28 @@ add_library(fortran-support
@@ -46,9 +47,28 @@ add_library(fortran-support
add_library(${PROJECT_NAME}::fortran-support ALIAS fortran-support)
add_library(${PROJECT_NAME}::fortran-support ALIAS fortran-support)
set(THREADS_PREFER_PTHREAD_FLAG ON)
# The main reason that the fortran-support does not simply depend on
find_package(Threads REQUIRED)
# Threads::Threads is that NAG chokes with -pthread, which is a possible value
target_link_libraries(${PROJECT_NAME} PRIVATE Threads::Threads)
# of the INTERFACE_COMPILE_OPTIONS and INTERFACE_LINK_LIBRARIES properties of
 
# the target. Since we have to circumvent the issue anyway, we also drop the
 
# redundant -pthread flag when compiling Fortran source files:
 
 
# Prepend '-pthread' with '-Wl,' when linking with the NAG compiler:
 
get_target_property(THREADS_LINK_LIBRARIES Threads::Threads INTERFACE_LINK_LIBRARIES)
 
if(THREADS_LINK_LIBRARIES)
 
if(NOT THREADS_LINK_LIBRARIES MATCHES "^-l")
 
set(THREADS_LINK_LIBRARIES "$<$<LINK_LANG_AND_ID:Fortran,NAG>:-Wl,${THREADS_LINK_LIBRARIES}>"
 
"$<$<NOT:$<LINK_LANG_AND_ID:Fortran,NAG>>:${THREADS_LINK_LIBRARIES}>")
 
endif()
 
target_link_libraries(fortran-support PRIVATE "${THREADS_LINK_LIBRARIES}")
 
endif()
 
 
# Do not use '-pthread' when compiling Fortran source files:
 
get_target_property(THREADS_COMPILER_OPTIONS Threads::Threads INTERFACE_COMPILE_OPTIONS)
 
if(THREADS_COMPILER_OPTIONS)
 
target_compile_options(fortran-support
 
PRIVATE "$<$<NOT:$<COMPILE_LANGUAGE:Fortran>>:${THREADS_COMPILER_OPTIONS}>")
 
endif()
set(Fortran_MODULE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/mod")
set(Fortran_MODULE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/mod")
set_target_properties(fortran-support
set_target_properties(fortran-support
@@ -60,12 +80,15 @@ set_target_properties(fortran-support
@@ -60,12 +80,15 @@ set_target_properties(fortran-support
target_include_directories(fortran-support
target_include_directories(fortran-support
PUBLIC
PUBLIC
$<BUILD_INTERFACE:${Fortran_MODULE_DIRECTORY}>
# Path to the Fortran modules:
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
$<BUILD_INTERFACE:$<$<COMPILE_LANGUAGE:Fortran>:${Fortran_MODULE_DIRECTORY}>>
 
$<INSTALL_INTERFACE:$<$<COMPILE_LANGUAGE:Fortran>:${CMAKE_INSTALL_INCLUDEDIR}>>
INTERFACE
INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
# Path to the internal C/C++ headers (for testing):
 
$<BUILD_INTERFACE:$<$<COMPILE_LANGUAGE:C,CXX>:${CMAKE_CURRENT_SOURCE_DIR}>>
PRIVATE
PRIVATE
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
# Path to config.h (for C and C++ only):
 
$<BUILD_INTERFACE:$<$<COMPILE_LANGUAGE:C,CXX>:${CMAKE_CURRENT_BINARY_DIR}>>
)
)
install(
install(
Loading