Skip to content

Commit

Permalink
Simplify link libraries
Browse files Browse the repository at this point in the history
  • Loading branch information
kimwalisch committed Jun 22, 2024
1 parent 67f5672 commit dd4dd5e
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 11 deletions.
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ endif()
# Enable __float128 support (requires libquadmath) ###################

if(WITH_FLOAT128)
set(LIB_QUADMATH "quadmath")
list(APPEND PRIMECOUNT_LINK_LIBRARIES "quadmath")
list(APPEND PRIMECOUNT_COMPILE_DEFINITIONS "HAVE_FLOAT128")
endif()

Expand Down Expand Up @@ -253,7 +253,7 @@ if(BUILD_SHARED_LIBS)
set_target_properties(libprimecount PROPERTIES VERSION ${PRIMECOUNT_VERSION})
target_compile_options(libprimecount PRIVATE "${WNO_UNINITIALIZED}")
target_compile_definitions(libprimecount PRIVATE ${PRIMECOUNT_COMPILE_DEFINITIONS})
target_link_libraries(libprimecount PRIVATE primesieve::primesieve "${LIB_OPENMP}" "${LIB_QUADMATH}" "${LIB_ATOMIC}")
target_link_libraries(libprimecount PRIVATE primesieve::primesieve ${PRIMECOUNT_LINK_LIBRARIES})

target_compile_features(libprimecount
PRIVATE
Expand All @@ -278,7 +278,7 @@ if(BUILD_STATIC_LIBS)
set_target_properties(libprimecount-static PROPERTIES OUTPUT_NAME primecount)
target_compile_options(libprimecount-static PRIVATE "${WNO_UNINITIALIZED}")
target_compile_definitions(libprimecount-static PRIVATE ${PRIMECOUNT_COMPILE_DEFINITIONS})
target_link_libraries(libprimecount-static PRIVATE primesieve::primesieve "${LIB_OPENMP}" "${LIB_QUADMATH}" "${LIB_ATOMIC}")
target_link_libraries(libprimecount-static PRIVATE primesieve::primesieve ${PRIMECOUNT_LINK_LIBRARIES})

if(WITH_MSVC_CRT_STATIC)
set_target_properties(libprimecount-static PROPERTIES MSVC_RUNTIME_LIBRARY "MultiThreaded")
Expand Down
8 changes: 5 additions & 3 deletions cmake/OpenMP.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,12 @@ if(OpenMP_FOUND OR OpenMP_CXX_FOUND)
return 0;
}" OpenMP_with_libatomic)

if(NOT OpenMP_with_libatomic)
if(OpenMP_with_libatomic)
list(APPEND PRIMECOUNT_LINK_LIBRARIES "${LIB_ATOMIC}")
else()
set(LIB_ATOMIC "")

if (NOT DISABLE_INT128)
if(NOT DISABLE_INT128)
# As a last resort check if OpenMP supports int128_t if
# we include our <int128_OpenMP_patch.hpp> header.
# In this case OpenMP will use critical sections instead
Expand Down Expand Up @@ -129,7 +131,7 @@ if(OpenMP_FOUND OR OpenMP_CXX_FOUND)
# OpenMP has been tested successfully, enable it
if(OpenMP OR OpenMP_with_libatomic OR OpenMP_int128_patch)
if(TARGET OpenMP::OpenMP_CXX)
set(LIB_OPENMP "OpenMP::OpenMP_CXX")
list(APPEND PRIMECOUNT_LINK_LIBRARIES "OpenMP::OpenMP_CXX")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
endif()
Expand Down
2 changes: 1 addition & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ foreach(file ${files})
get_filename_component(binary_name ${file} NAME_WE)
add_executable(${binary_name} ${file})
target_compile_definitions(${binary_name} PRIVATE ${PRIMECOUNT_COMPILE_DEFINITIONS})
target_link_libraries(${binary_name} primecount::primecount primesieve::primesieve "${LIB_OPENMP}" "${LIB_ATOMIC}")
target_link_libraries(${binary_name} primecount::primecount primesieve::primesieve ${PRIMECOUNT_LINK_LIBRARIES})
add_test(NAME ${binary_name} COMMAND ${binary_name})
endforeach()

Expand Down
2 changes: 1 addition & 1 deletion test/api/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ foreach(file ${files})
get_filename_component(binary_name ${file} NAME_WE)
add_executable(${binary_name} ${file})
target_compile_definitions(${binary_name} PRIVATE ${PRIMECOUNT_COMPILE_DEFINITIONS})
target_link_libraries(${binary_name} primecount::primecount primesieve::primesieve "${LIB_OPENMP}" "${LIB_ATOMIC}")
target_link_libraries(${binary_name} primecount::primecount primesieve::primesieve ${PRIMECOUNT_LINK_LIBRARIES})
add_test(NAME ${binary_name} COMMAND ${binary_name})
endforeach()
2 changes: 1 addition & 1 deletion test/deleglise-rivat/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ foreach(file ${files})
get_filename_component(binary_name ${file} NAME_WE)
add_executable(${binary_name} ${file})
target_compile_definitions(${binary_name} PRIVATE ${PRIMECOUNT_COMPILE_DEFINITIONS})
target_link_libraries(${binary_name} primecount::primecount primesieve::primesieve "${LIB_OPENMP}" "${LIB_ATOMIC}")
target_link_libraries(${binary_name} primecount::primecount primesieve::primesieve ${PRIMECOUNT_LINK_LIBRARIES})
add_test(NAME ${binary_name} COMMAND ${binary_name})
endforeach()
2 changes: 1 addition & 1 deletion test/gourdon/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ foreach(file ${files})
get_filename_component(binary_name ${file} NAME_WE)
add_executable(${binary_name} ${file})
target_compile_definitions(${binary_name} PRIVATE ${PRIMECOUNT_COMPILE_DEFINITIONS})
target_link_libraries(${binary_name} primecount::primecount primesieve::primesieve "${LIB_OPENMP}" "${LIB_ATOMIC}")
target_link_libraries(${binary_name} primecount::primecount primesieve::primesieve ${PRIMECOUNT_LINK_LIBRARIES})
add_test(NAME ${binary_name} COMMAND ${binary_name})
endforeach()
2 changes: 1 addition & 1 deletion test/lmo/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ foreach(file ${files})
get_filename_component(binary_name ${file} NAME_WE)
add_executable(${binary_name} ${file})
target_compile_definitions(${binary_name} PRIVATE ${PRIMECOUNT_COMPILE_DEFINITIONS})
target_link_libraries(${binary_name} primecount::primecount primesieve::primesieve "${LIB_OPENMP}" "${LIB_ATOMIC}")
target_link_libraries(${binary_name} primecount::primecount primesieve::primesieve ${PRIMECOUNT_LINK_LIBRARIES})
add_test(NAME ${binary_name} COMMAND ${binary_name})
endforeach()

0 comments on commit dd4dd5e

Please sign in to comment.