macOS: Test OSX_COMPATIBILITY_VERSION and OSX_CURRENT_VERSION properties

Issue: #17652
This commit is contained in:
Brad King
2020-01-24 14:23:57 -05:00
parent 4a62e3d97c
commit 6a84f0b791
6 changed files with 55 additions and 0 deletions

View File

@@ -305,6 +305,7 @@ add_RunCMake_test(test_include_dirs)
add_RunCMake_test(BundleUtilities)
if(APPLE)
add_RunCMake_test(INSTALL_NAME_DIR)
add_RunCMake_test(MacOSVersions)
endif()
function(add_RunCMake_test_try_compile)

View File

@@ -0,0 +1,3 @@
cmake_minimum_required(VERSION 3.16)
project(${RunCMake_TEST} NONE)
include(${RunCMake_TEST}.cmake)

View File

@@ -0,0 +1,27 @@
set(cfg_dir)
if(RunCMake_GENERATOR_IS_MULTI_CONFIG)
set(cfg_dir /Debug)
endif()
set(lib "${RunCMake_TEST_BINARY_DIR}${cfg_dir}/libfoo.1.0.dylib")
if(NOT EXISTS "${lib}")
set(RunCMake_TEST_FAILED "Library file is missing:\n ${lib}")
return()
endif()
execute_process(COMMAND otool -l "${lib}" OUTPUT_VARIABLE out ERROR_VARIABLE err RESULT_VARIABLE res)
if(NOT res EQUAL 0)
string(REPLACE "\n" "\n " err " ${err}")
set(RunCMake_TEST_FAILED "Running 'otool -l' on file:\n ${lib}\nfailed:\n${err}")
return()
endif()
foreach(ver
[[current version 3\.2\.1]]
[[compatibility version 2\.1\.0]]
)
if(NOT "${out}" MATCHES "( |\n)${ver}( |\n)")
set(RunCMake_TEST_FAILED "Library file:\n ${lib}\ndoes not contain '${ver}'")
return()
endif()
endforeach()

View File

@@ -0,0 +1,9 @@
enable_language(C)
add_library(foo SHARED foo.c)
set_target_properties(foo PROPERTIES
VERSION 1.0
SOVERSION 1
OSX_COMPATIBILITY_VERSION 2.1.0
OSX_CURRENT_VERSION 3.2.1
)

View File

@@ -0,0 +1,11 @@
include(RunCMake)
function(run_MacOSVersions)
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/MacOSVersions-build)
run_cmake(MacOSVersions)
set(RunCMake_TEST_NO_CLEAN 1)
run_cmake_command(MacOSVersions-build ${CMAKE_COMMAND} --build . --config Debug)
endfunction()
run_MacOSVersions()

View File

@@ -0,0 +1,4 @@
int foo(void)
{
return 0;
}