From b1e19235802df83b85e42510462a1d47851c1f70 Mon Sep 17 00:00:00 2001 From: Krishna Vedala <7001608+kvedala@users.noreply.github.com> Date: Fri, 29 May 2020 14:04:14 -0400 Subject: [PATCH] check if math library is available and include if present --- CMakeLists.txt | 2 ++ conversions/CMakeLists.txt | 7 ++----- misc/CMakeLists.txt | 6 ++---- numerical_methods/CMakeLists.txt | 7 +++---- project_euler/CMakeLists.txt | 7 +++---- searching/CMakeLists.txt | 6 ++---- sorting/CMakeLists.txt | 6 ++---- 7 files changed, 16 insertions(+), 25 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 03e5371d..20ab85a0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,6 +46,8 @@ if(MSVC) add_compile_options(/Za) endif(MSVC) +find_library(MATH_LIBRARY m) + add_subdirectory(conversions) add_subdirectory(misc) add_subdirectory(project_euler) diff --git a/conversions/CMakeLists.txt b/conversions/CMakeLists.txt index d48b58a6..6ff51c3f 100644 --- a/conversions/CMakeLists.txt +++ b/conversions/CMakeLists.txt @@ -16,12 +16,9 @@ foreach( testsourcefile ${APP_SOURCES} ) if(OpenMP_C_FOUND) target_link_libraries(${testname} OpenMP::OpenMP_C) endif() - if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") - target_link_libraries(${testname} m) - elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - target_link_libraries(${testname} m) + if(MATH_LIBRARY) + target_link_libraries(${testname} ${MATH_LIBRARY}) endif() - install(TARGETS ${testname} DESTINATION "bin/conversions") endforeach( testsourcefile ${APP_SOURCES} ) diff --git a/misc/CMakeLists.txt b/misc/CMakeLists.txt index b2500be6..6a7dd981 100644 --- a/misc/CMakeLists.txt +++ b/misc/CMakeLists.txt @@ -16,10 +16,8 @@ foreach( testsourcefile ${APP_SOURCES} ) if(OpenMP_C_FOUND) target_link_libraries(${testname} OpenMP::OpenMP_C) endif() - if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") - target_link_libraries(${testname} m) - elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - target_link_libraries(${testname} m) + if(MATH_LIBRARY) + target_link_libraries(${testname} ${MATH_LIBRARY}) endif() install(TARGETS ${testname} DESTINATION "bin/misc") diff --git a/numerical_methods/CMakeLists.txt b/numerical_methods/CMakeLists.txt index 81000766..945fd99f 100644 --- a/numerical_methods/CMakeLists.txt +++ b/numerical_methods/CMakeLists.txt @@ -24,10 +24,9 @@ foreach( testsourcefile ${APP_SOURCES} ) if(OpenMP_C_FOUND) target_link_libraries(${testname} OpenMP::OpenMP_C) endif() - if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") - target_link_libraries(${testname} m) - elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - target_link_libraries(${testname} m) + + if(MATH_LIBRARY) + target_link_libraries(${testname} ${MATH_LIBRARY}) endif() install(TARGETS ${testname} DESTINATION "bin/numerical_methods") diff --git a/project_euler/CMakeLists.txt b/project_euler/CMakeLists.txt index 70f18faf..1e896582 100644 --- a/project_euler/CMakeLists.txt +++ b/project_euler/CMakeLists.txt @@ -19,10 +19,9 @@ foreach( testsourcefile ${APP_SOURCES} ) if(OpenMP_C_FOUND) target_link_libraries(${testname} OpenMP::OpenMP_C) endif() - if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") - target_link_libraries(${testname} m) - elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - target_link_libraries(${testname} m) + + if(MATH_LIBRARY) + target_link_libraries(${testname} ${MATH_LIBRARY}) endif() install(TARGETS ${testname} DESTINATION "bin/misc") diff --git a/searching/CMakeLists.txt b/searching/CMakeLists.txt index 3d29def6..f51852b5 100644 --- a/searching/CMakeLists.txt +++ b/searching/CMakeLists.txt @@ -16,10 +16,8 @@ foreach( testsourcefile ${APP_SOURCES} ) if(OpenMP_C_FOUND) target_link_libraries(${testname} OpenMP::OpenMP_C) endif() - if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") - target_link_libraries(${testname} m) - elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - target_link_libraries(${testname} m) + if(MATH_LIBRARY) + target_link_libraries(${testname} ${MATH_LIBRARY}) endif() install(TARGETS ${testname} DESTINATION "bin/searching") diff --git a/sorting/CMakeLists.txt b/sorting/CMakeLists.txt index e361d575..e3ff0d66 100644 --- a/sorting/CMakeLists.txt +++ b/sorting/CMakeLists.txt @@ -16,10 +16,8 @@ foreach( testsourcefile ${APP_SOURCES} ) if(OpenMP_C_FOUND) target_link_libraries(${testname} OpenMP::OpenMP_C) endif() - if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") - target_link_libraries(${testname} m) - elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - target_link_libraries(${testname} m) + if(MATH_LIBRARY) + target_link_libraries(${testname} ${MATH_LIBRARY}) endif() install(TARGETS ${testname} DESTINATION "bin/sorting")