From 062b50abff6a3cb2319ade41dddf76caa36f27e3 Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Tue, 28 Apr 2020 17:33:29 +0200 Subject: CMake: Namespace all our IMPORTED targets CMake IMPORTED targets should be namespaced so that CMake knows that the name refers to a target and not a file. Use the existing WrapXXX naming scheme where applicable. Fixes: QTBUG-83773 Change-Id: I5b0b722c811200c56c260c69e76940a625228769 Reviewed-by: Alexandru Croitor --- cmake/FindAtomic.cmake | 44 -------------------------------------------- cmake/FindSlog2.cmake | 8 +++----- cmake/FindWrapAtomic.cmake | 44 ++++++++++++++++++++++++++++++++++++++++++++ cmake/FindWrapRt.cmake | 6 +++--- 4 files changed, 50 insertions(+), 52 deletions(-) delete mode 100644 cmake/FindAtomic.cmake create mode 100644 cmake/FindWrapAtomic.cmake (limited to 'cmake') diff --git a/cmake/FindAtomic.cmake b/cmake/FindAtomic.cmake deleted file mode 100644 index 91cee62046..0000000000 --- a/cmake/FindAtomic.cmake +++ /dev/null @@ -1,44 +0,0 @@ -# We can't create the same interface imported target multiple times, CMake will complain if we do -# that. This can happen if the find_package call is done in multiple different subdirectories. -if(TARGET Atomic) - set(Atomic_FOUND ON) - return() -endif() - -include(CheckCXXSourceCompiles) - -set (atomic_test_sources "#include -#include - -void test(volatile std::atomic &a) -{ - std::int64_t v = a.load(std::memory_order_acquire); - while (!a.compare_exchange_strong(v, v + 1, - std::memory_order_acq_rel, - std::memory_order_acquire)) { - v = a.exchange(v - 1); - } - a.store(v + 1, std::memory_order_release); -} - -int main(int, char **) -{ - void *ptr = (void*)0xffffffc0; // any random pointer - test(*reinterpret_cast *>(ptr)); - return 0; -}") - -check_cxx_source_compiles("${atomic_test_sources}" HAVE_STDATOMIC) -if(NOT HAVE_STDATOMIC) - set(_req_libraries "${CMAKE_REQUIRE_LIBRARIES}") - set(CMAKE_REQUIRE_LIBRARIES "atomic") - check_cxx_source_compiles("${atomic_test_sources}" HAVE_STDATOMIC_WITH_LIB) - set(CMAKE_REQUIRE_LIBRARIES "${_req_libraries}") -endif() - -add_library(Atomic INTERFACE IMPORTED) -if(HAVE_STDATOMIC_WITH_LIB) - target_link_libraries(Atomic INTERFACE atomic) -endif() - -set(Atomic_FOUND 1) diff --git a/cmake/FindSlog2.cmake b/cmake/FindSlog2.cmake index dfb6635a39..807ab6b12a 100644 --- a/cmake/FindSlog2.cmake +++ b/cmake/FindSlog2.cmake @@ -11,9 +11,7 @@ find_package_handle_standard_args(Slog2 DEFAULT_MSG Slog2_INCLUDE_DIR Slog2_LIBR mark_as_advanced(Slog2_INCLUDE_DIR Slog2_LIBRARY) if(Slog2_FOUND) - add_library(__Slog2 INTERFACE IMPORTED) - target_link_libraries(__Slog2 INTERFACE ${Slog2_LIBRARY}) - target_include_directories(__Slog2 INTERFACE ${Slog2_INCLUDE_DIR}) - - add_library(Slog2::Slog2 ALIAS __Slog2) + add_library(Slog2::Slog2 INTERFACE IMPORTED) + target_link_libraries(Slog2::Slog2 INTERFACE ${Slog2_LIBRARY}) + target_include_directories(Slog2::Slog2 INTERFACE ${Slog2_INCLUDE_DIR}) endif() diff --git a/cmake/FindWrapAtomic.cmake b/cmake/FindWrapAtomic.cmake new file mode 100644 index 0000000000..c65ee1da06 --- /dev/null +++ b/cmake/FindWrapAtomic.cmake @@ -0,0 +1,44 @@ +# We can't create the same interface imported target multiple times, CMake will complain if we do +# that. This can happen if the find_package call is done in multiple different subdirectories. +if(TARGET WrapAtomic::WrapAtomic) + set(WrapAtomic_FOUND ON) + return() +endif() + +include(CheckCXXSourceCompiles) + +set (atomic_test_sources "#include +#include + +void test(volatile std::atomic &a) +{ + std::int64_t v = a.load(std::memory_order_acquire); + while (!a.compare_exchange_strong(v, v + 1, + std::memory_order_acq_rel, + std::memory_order_acquire)) { + v = a.exchange(v - 1); + } + a.store(v + 1, std::memory_order_release); +} + +int main(int, char **) +{ + void *ptr = (void*)0xffffffc0; // any random pointer + test(*reinterpret_cast *>(ptr)); + return 0; +}") + +check_cxx_source_compiles("${atomic_test_sources}" HAVE_STDATOMIC) +if(NOT HAVE_STDATOMIC) + set(_req_libraries "${CMAKE_REQUIRE_LIBRARIES}") + set(CMAKE_REQUIRE_LIBRARIES "atomic") + check_cxx_source_compiles("${atomic_test_sources}" HAVE_STDATOMIC_WITH_LIB) + set(CMAKE_REQUIRE_LIBRARIES "${_req_libraries}") +endif() + +add_library(WrapAtomic::WrapAtomic INTERFACE IMPORTED) +if(HAVE_STDATOMIC_WITH_LIB) + target_link_libraries(WrapAtomic::WrapAtomic INTERFACE atomic) +endif() + +set(WrapAtomic_FOUND 1) diff --git a/cmake/FindWrapRt.cmake b/cmake/FindWrapRt.cmake index 0e57cadef5..6a138d348f 100644 --- a/cmake/FindWrapRt.cmake +++ b/cmake/FindWrapRt.cmake @@ -1,6 +1,6 @@ # We can't create the same interface imported target multiple times, CMake will complain if we do # that. This can happen if the find_package call is done in multiple different subdirectories. -if(TARGET WrapRt) +if(TARGET WrapRt::WrapRt) set(WrapRt_FOUND ON) return() endif() @@ -30,8 +30,8 @@ cmake_pop_check_state() if(HAVE_GETTIME) set(WrapRt_FOUND ON) - add_library(WrapRt INTERFACE IMPORTED) + add_library(WrapRt::WrapRt INTERFACE IMPORTED) if (LIBRT_FOUND) - target_link_libraries(WrapRt INTERFACE "${LIBRT}") + target_link_libraries(WrapRt::WrapRt INTERFACE "${LIBRT}") endif() endif() -- cgit v1.2.3