diff options
author | Marc Chevrier <marc.chevrier@gmail.com> | 2022-02-21 16:30:29 (GMT) |
---|---|---|
committer | Marc Chevrier <marc.chevrier@gmail.com> | 2022-03-05 12:57:45 (GMT) |
commit | 9fb1dff0708792ba275fa841459d6d3875613cfa (patch) | |
tree | 3a2d591ca44cf279cde8e1252bf72065b468d85a /Tests | |
parent | 93a153bc7ffc217181ba56eadc35f1103f902038 (diff) | |
download | CMake-9fb1dff0708792ba275fa841459d6d3875613cfa.zip CMake-9fb1dff0708792ba275fa841459d6d3875613cfa.tar.gz CMake-9fb1dff0708792ba275fa841459d6d3875613cfa.tar.bz2 |
LINK_LIBRARY: Add features for library support on Apple
Diffstat (limited to 'Tests')
8 files changed, 54 insertions, 7 deletions
diff --git a/Tests/RunCMake/target_link_libraries-LINK_LIBRARY/External/CMakeLists.txt b/Tests/RunCMake/target_link_libraries-LINK_LIBRARY/External/CMakeLists.txt new file mode 100644 index 0000000..212741a --- /dev/null +++ b/Tests/RunCMake/target_link_libraries-LINK_LIBRARY/External/CMakeLists.txt @@ -0,0 +1,6 @@ + +cmake_minimum_required(VERSION 3.23) + +project(External LANGUAGES C) + +add_library(external SHARED ../unref.c) diff --git a/Tests/RunCMake/target_link_libraries-LINK_LIBRARY/RunCMakeTest.cmake b/Tests/RunCMake/target_link_libraries-LINK_LIBRARY/RunCMakeTest.cmake index 9582e11..349310f 100644 --- a/Tests/RunCMake/target_link_libraries-LINK_LIBRARY/RunCMakeTest.cmake +++ b/Tests/RunCMake/target_link_libraries-LINK_LIBRARY/RunCMakeTest.cmake @@ -97,3 +97,16 @@ if (CMAKE_C_COMPILER_ID STREQUAL "AppleClang" AND CMAKE_C_COMPILER_VERSION GREAT run_cmake_target(apple_framework target-needed_framework main-target-needed_framework) endif() + +# Apple library features +if(APPLE AND (CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID MATCHES "Clang")) + run_cmake(apple_library_external) + run_cmake_target(apple_library_external build external) + run_cmake_with_options(apple_library "-DRunCMake_BINARY_DIR=${RunCMake_BINARY_DIR}") + run_cmake_target(apple_library reexport_library main-reexport_library) + run_cmake_target(apple_library weak_library main-weak_library) +endif() + +if (CMAKE_C_COMPILER_ID STREQUAL "AppleClang" AND CMAKE_C_COMPILER_VERSION GREATER_EQUAL "12") + run_cmake_target(apple_library needed_library main-needed_library) +endif() diff --git a/Tests/RunCMake/target_link_libraries-LINK_LIBRARY/apple_library.cmake b/Tests/RunCMake/target_link_libraries-LINK_LIBRARY/apple_library.cmake new file mode 100644 index 0000000..fb85d05 --- /dev/null +++ b/Tests/RunCMake/target_link_libraries-LINK_LIBRARY/apple_library.cmake @@ -0,0 +1,24 @@ + +enable_language(C) + +add_library(lib SHARED base.c lib.c) + +# feature NEEDED_FRAMEWORK +add_executable(main-needed_library main.c) +target_link_directories(main-needed_library PRIVATE "${RunCMake_BINARY_DIR}/apple_library_external-build" + "${RunCMake_BINARY_DIR}/apple_library_external-build/$<CONFIG>") +target_link_libraries(main-needed_library PRIVATE "$<LINK_LIBRARY:NEEDED_LIBRARY,lib,external>") + + +# feature REEXPORT_FRAMEWORK +add_executable(main-reexport_library main.c) +target_link_directories(main-reexport_library PRIVATE "${RunCMake_BINARY_DIR}/apple_library_external-build" + "${RunCMake_BINARY_DIR}/apple_library_external-build/$<CONFIG>") +target_link_libraries(main-reexport_library PRIVATE "$<LINK_LIBRARY:REEXPORT_LIBRARY,lib,external>") + + +# feature WEAK_FRAMEWORK +add_executable(main-weak_library main.c) +target_link_directories(main-weak_library PRIVATE "${RunCMake_BINARY_DIR}/apple_library_external-build" + "${RunCMake_BINARY_DIR}/apple_library_external-build/$<CONFIG>") +target_link_libraries(main-weak_library PRIVATE "$<LINK_LIBRARY:WEAK_LIBRARY,lib,external>") diff --git a/Tests/RunCMake/target_link_libraries-LINK_LIBRARY/apple_library_external.cmake b/Tests/RunCMake/target_link_libraries-LINK_LIBRARY/apple_library_external.cmake new file mode 100644 index 0000000..f5a566f --- /dev/null +++ b/Tests/RunCMake/target_link_libraries-LINK_LIBRARY/apple_library_external.cmake @@ -0,0 +1,4 @@ + +enable_language(C) + +add_library(external SHARED unref.c) diff --git a/Tests/RunCMake/target_link_libraries-LINK_LIBRARY/base.c b/Tests/RunCMake/target_link_libraries-LINK_LIBRARY/base.c index a5075d4..ed769a0 100644 --- a/Tests/RunCMake/target_link_libraries-LINK_LIBRARY/base.c +++ b/Tests/RunCMake/target_link_libraries-LINK_LIBRARY/base.c @@ -4,6 +4,6 @@ __declspec(dllexport) # endif #endif - void base() + void base(void) { } diff --git a/Tests/RunCMake/target_link_libraries-LINK_LIBRARY/lib.c b/Tests/RunCMake/target_link_libraries-LINK_LIBRARY/lib.c index 35ab367..21f559c 100644 --- a/Tests/RunCMake/target_link_libraries-LINK_LIBRARY/lib.c +++ b/Tests/RunCMake/target_link_libraries-LINK_LIBRARY/lib.c @@ -4,12 +4,12 @@ __declspec(dllimport) # endif #endif - void base(); + void base(void); #if defined(_WIN32) __declspec(dllexport) #endif - void lib() + void lib(void) { base(); } diff --git a/Tests/RunCMake/target_link_libraries-LINK_LIBRARY/main.c b/Tests/RunCMake/target_link_libraries-LINK_LIBRARY/main.c index 601bd96..2e39bce 100644 --- a/Tests/RunCMake/target_link_libraries-LINK_LIBRARY/main.c +++ b/Tests/RunCMake/target_link_libraries-LINK_LIBRARY/main.c @@ -2,14 +2,14 @@ #if defined(_WIN32) __declspec(dllimport) #endif - void lib(); + void lib(void); #if defined(_WIN32) __declspec(dllimport) #endif - void unref(); + void unref(void); -int main() +int main(void) { lib(); unref(); diff --git a/Tests/RunCMake/target_link_libraries-LINK_LIBRARY/unref.c b/Tests/RunCMake/target_link_libraries-LINK_LIBRARY/unref.c index 37c3206..11922de 100644 --- a/Tests/RunCMake/target_link_libraries-LINK_LIBRARY/unref.c +++ b/Tests/RunCMake/target_link_libraries-LINK_LIBRARY/unref.c @@ -3,6 +3,6 @@ #if defined(_WIN32) __declspec(dllexport) #endif - void unref() + void unref(void) { } |