diff options
-rw-r--r-- | CMakeLists.txt | 35 |
1 files changed, 28 insertions, 7 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 2bd87e3..c09bf15 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,12 +33,21 @@ set(LIBATOMIC_OPS_GPL_VER_INFO 2:3:1) project(libatomic_ops C) +if (POLICY CMP0057) + # Required for CheckLinkerFlag, at least. + cmake_policy(SET CMP0057 NEW) +endif() + include(CheckCCompilerFlag) include(CheckFunctionExists) include(CMakePackageConfigHelpers) include(CTest) include(GNUInstallDirs) +if (NOT (${CMAKE_VERSION} VERSION_LESS "3.18.0")) + include(CheckLinkerFlag) +endif() + # Customize the build by passing "-D<option_name>=ON|OFF" in the command line. option(BUILD_SHARED_LIBS "Build shared libraries" OFF) option(build_tests "Build tests" OFF) @@ -169,15 +178,27 @@ if (enable_gpl) endif(enable_gpl) if (BUILD_SHARED_LIBS) - check_c_compiler_flag(-Wl,--no-undefined HAVE_FLAG_WL_NO_UNDEFINED) + if (${CMAKE_VERSION} VERSION_LESS "3.18.0") + set(WL_NO_UNDEFINED_OPT "-Wl,--no-undefined") + check_c_compiler_flag(${WL_NO_UNDEFINED_OPT} HAVE_FLAG_WL_NO_UNDEFINED) + else() + set(WL_NO_UNDEFINED_OPT "LINKER:--no-undefined") + check_linker_flag(C "${WL_NO_UNDEFINED_OPT}" HAVE_FLAG_WL_NO_UNDEFINED) + endif() if (HAVE_FLAG_WL_NO_UNDEFINED) # Declare that the libraries do not refer to external symbols. - # TODO: use add_link_options() when cmake_minimum_required > 3.13 - target_link_libraries(atomic_ops PRIVATE -Wl,--no-undefined) - if (enable_gpl) - target_link_libraries(atomic_ops_gpl PRIVATE -Wl,--no-undefined) - endif(enable_gpl) - endif() + if (${CMAKE_VERSION} VERSION_LESS "3.13.0") + target_link_libraries(atomic_ops PRIVATE ${WL_NO_UNDEFINED_OPT}) + if (enable_gpl) + target_link_libraries(atomic_ops_gpl PRIVATE ${WL_NO_UNDEFINED_OPT}) + endif(enable_gpl) + else() + target_link_options(atomic_ops PRIVATE ${WL_NO_UNDEFINED_OPT}) + if (enable_gpl) + target_link_options(atomic_ops_gpl PRIVATE ${WL_NO_UNDEFINED_OPT}) + endif(enable_gpl) + endif() + endif(HAVE_FLAG_WL_NO_UNDEFINED) set_property(TARGET atomic_ops PROPERTY VERSION ${AO_VERSION_PROP}) set_property(TARGET atomic_ops PROPERTY SOVERSION ${AO_SOVERSION}) endif(BUILD_SHARED_LIBS) |