diff options
author | Ivan Maidanski <ivmai@mail.ru> | 2022-09-23 20:07:46 +0300 |
---|---|---|
committer | Ivan Maidanski <ivmai@mail.ru> | 2022-09-23 20:07:46 +0300 |
commit | 044573903530c4a8e8318e20a830d4a0531b2035 (patch) | |
tree | b3ce05888978f425bba092c0d6409f6cca1b70f8 | |
parent | aa860c6bee0378528b79665f95e94e400d3919f1 (diff) | |
download | libatomic_ops-044573903530c4a8e8318e20a830d4a0531b2035.tar.gz |
Fix 'unknown option --no-undefined' linker error in cmake script (OS X)
Use check_linker_flag() and LINKER prefix in CMakeLists.txt.
This fixes the linker error that "--no-undefined" option is unknown,
at least with apple-clang 13.0.
* CMakeLists.txt [CMP0057] (CMP0057): Set to NEW.
* CMakeLists.txt [$CMAKE_VERSION<3.18.0]: Include CheckLinkerFlag.
* CMakeLists.txt [BUILD_SHARED_LIBS] (WL_NO_UNDEFINED_OPT): New
variable.
* CMakeLists.txt [BUILD_SHARED_LIBS && $CMAKE_VERSION>=3.18.0]
(WL_NO_UNDEFINED_OPT): Use "LINKER:" prefix.
* CMakeLists.txt [BUILD_SHARED_LIBS && $CMAKE_VERSION>=3.18.0]
(HAVE_FLAG_WL_NO_UNDEFINED): Use check_linker_flag(C) instead of
check_c_compiler_flag.
* CMakeLists.txt [BUILD_SHARED_LIBS && $CMAKE_VERSION<3.13.0]
(atomic_ops): Use $WL_NO_UNDEFINED_OPT.
* CMakeLists.txt [BUILD_SHARED_LIBS && $CMAKE_VERSION<3.13.0
&& enable_gpl] (atomic_ops_gpl): Likewise.
* CMakeLists.txt [BUILD_SHARED_LIBS && $CMAKE_VERSION>=3.13.0]
(atomic_ops): Use target_link_options instead of
target_link_libraries; remove TODO item.
* CMakeLists.txt [BUILD_SHARED_LIBS && $CMAKE_VERSION>=3.13.0
&& enable_gpl] (atomic_ops_gpl): Likewise.
-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) |