summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2020-01-28 15:58:21 (GMT)
committerKitware Robot <kwrobot@kitware.com>2020-01-28 15:59:03 (GMT)
commitb6da71e299ccdd202f1ea35f33cfcfeb36467e1d (patch)
treeee13e7ad9d9c5205621f1cb72896665a146aa36b
parente4e41d33d62236f60d909bd1d06b417590933980 (diff)
parent6a84f0b79189be4c982a6ba55c5cdcafee118813 (diff)
downloadCMake-b6da71e299ccdd202f1ea35f33cfcfeb36467e1d.zip
CMake-b6da71e299ccdd202f1ea35f33cfcfeb36467e1d.tar.gz
CMake-b6da71e299ccdd202f1ea35f33cfcfeb36467e1d.tar.bz2
Merge topic 'osx-version-flags'
6a84f0b791 macOS: Test OSX_COMPATIBILITY_VERSION and OSX_CURRENT_VERSION properties 4a62e3d97c macOS: Add OSX_COMPATIBILITY_VERSION and OSX_CURRENT_VERSION properties Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !4274
-rw-r--r--Help/manual/cmake-properties.7.rst2
-rw-r--r--Help/prop_tgt/OSX_COMPATIBILITY_VERSION.rst14
-rw-r--r--Help/prop_tgt/OSX_CURRENT_VERSION.rst13
-rw-r--r--Help/prop_tgt/SOVERSION.rst10
-rw-r--r--Help/prop_tgt/VERSION.rst6
-rw-r--r--Help/release/dev/osx-version-flags.rst9
-rw-r--r--Source/cmCommonTargetGenerator.cxx5
-rw-r--r--Source/cmGeneratorTarget.cxx22
-rw-r--r--Source/cmGeneratorTarget.h12
-rw-r--r--Source/cmGlobalXCodeGenerator.cxx10
-rw-r--r--Tests/RunCMake/CMakeLists.txt1
-rw-r--r--Tests/RunCMake/MacOSVersions/CMakeLists.txt3
-rw-r--r--Tests/RunCMake/MacOSVersions/MacOSVersions-build-check.cmake27
-rw-r--r--Tests/RunCMake/MacOSVersions/MacOSVersions.cmake9
-rw-r--r--Tests/RunCMake/MacOSVersions/RunCMakeTest.cmake11
-rw-r--r--Tests/RunCMake/MacOSVersions/foo.c4
16 files changed, 139 insertions, 19 deletions
diff --git a/Help/manual/cmake-properties.7.rst b/Help/manual/cmake-properties.7.rst
index 717fae6..bcf21a5 100644
--- a/Help/manual/cmake-properties.7.rst
+++ b/Help/manual/cmake-properties.7.rst
@@ -302,6 +302,8 @@ Properties on Targets
/prop_tgt/OBJCXX_STANDARD_REQUIRED
/prop_tgt/OSX_ARCHITECTURES_CONFIG
/prop_tgt/OSX_ARCHITECTURES
+ /prop_tgt/OSX_CURRENT_VERSION
+ /prop_tgt/OSX_COMPATIBILITY_VERSION
/prop_tgt/OUTPUT_NAME_CONFIG
/prop_tgt/OUTPUT_NAME
/prop_tgt/PDB_NAME_CONFIG
diff --git a/Help/prop_tgt/OSX_COMPATIBILITY_VERSION.rst b/Help/prop_tgt/OSX_COMPATIBILITY_VERSION.rst
new file mode 100644
index 0000000..1694df1
--- /dev/null
+++ b/Help/prop_tgt/OSX_COMPATIBILITY_VERSION.rst
@@ -0,0 +1,14 @@
+OSX_COMPATIBILITY_VERSION
+-------------------------
+
+What current version number is this target for OSX.
+
+For shared libraries on Mach-O systems (e.g. macOS, iOS)
+the ``OSX_COMPATIBILITY_VERSION`` property correspond to
+``compatibility version`` and :prop_tgt:`OSX_CURRENT_VERSION` to
+``current version``.
+See the :prop_tgt:`FRAMEWORK` target property for an example.
+
+Versions of Mach-O binaries may be checked with the ``otool -L <binary>``
+command. If ``OSX_COMPATIBILITY_VERSION`` is not set, the value of
+the :prop_tgt:``SOVERSION`` property will be used.
diff --git a/Help/prop_tgt/OSX_CURRENT_VERSION.rst b/Help/prop_tgt/OSX_CURRENT_VERSION.rst
new file mode 100644
index 0000000..609924d
--- /dev/null
+++ b/Help/prop_tgt/OSX_CURRENT_VERSION.rst
@@ -0,0 +1,13 @@
+OSX_CURRENT_VERSION
+-------------------
+
+What current version number is this target for OSX.
+
+For shared libraries on Mach-O systems (e.g. macOS, iOS)
+the :prop_tgt:`OSX_COMPATIBILITY_VERSION` property correspond to
+``compatibility version`` and ``OSX_CURRENT_VERSION`` to ``current version``.
+See the :prop_tgt:`FRAMEWORK` target property for an example.
+
+Versions of Mach-O binaries may be checked with the ``otool -L <binary>``
+command. If ``OSX_CURRENT_VERSION`` is not set, the value of
+the :prop_tgt:``VERSION`` property will be used.
diff --git a/Help/prop_tgt/SOVERSION.rst b/Help/prop_tgt/SOVERSION.rst
index b07c17c..1a66c8f 100644
--- a/Help/prop_tgt/SOVERSION.rst
+++ b/Help/prop_tgt/SOVERSION.rst
@@ -21,7 +21,9 @@ Mach-O Versions
^^^^^^^^^^^^^^^
For shared libraries and executables on Mach-O systems (e.g. macOS, iOS),
-the ``SOVERSION`` property corresponds to *compatibility version* and
-:prop_tgt:`VERSION` to *current version*. See the :prop_tgt:`FRAMEWORK` target
-property for an example. Versions of Mach-O binaries may be checked with the
-``otool -L <binary>`` command.
+the ``SOVERSION`` property is a fallback to
+:prop_tgt:`OSX_COMPATIBILITY_VERSION` property which corresponds to
+*compatiblity version* and :prop_tgt:`VERSION` is a fallback to
+:prop_tgt:`OSX_CURRENT_VERSION` which corresponds to *current version*.
+See the :prop_tgt:`FRAMEWORK` target property for an example. Versions
+of Mach-O binaries may be checked with the ``otool -L <binary>`` command.
diff --git a/Help/prop_tgt/VERSION.rst b/Help/prop_tgt/VERSION.rst
index ff3b303..a24b613 100644
--- a/Help/prop_tgt/VERSION.rst
+++ b/Help/prop_tgt/VERSION.rst
@@ -23,7 +23,9 @@ Mach-O Versions
^^^^^^^^^^^^^^^
For shared libraries and executables on Mach-O systems (e.g. macOS, iOS),
-the :prop_tgt:`SOVERSION` property correspond to *compatibility version* and
-``VERSION`` to *current version*. See the :prop_tgt:`FRAMEWORK` target
+the ``VERSION`` property is a fallback to :prop_tgt:`OSX_CURRENT_VERSION`
+property which corresponds to *current version* and :prop_tgt:`SOVERSION`
+is a fallback to :prop_tgt:`OSX_COMPATIBILITY_VERSION` which corresponds
+to *compatiblity version*. See the :prop_tgt:`FRAMEWORK` target
property for an example. Versions of Mach-O binaries may be checked with the
``otool -L <binary>`` command.
diff --git a/Help/release/dev/osx-version-flags.rst b/Help/release/dev/osx-version-flags.rst
new file mode 100644
index 0000000..329aca3
--- /dev/null
+++ b/Help/release/dev/osx-version-flags.rst
@@ -0,0 +1,9 @@
+add_osx_compatiblity_property
+-----------------------------
+
+* Target properties :prop_tgt:`OSX_COMPATIBILITY_VERSION` and
+ :prop_tgt:`OSX_CURRENT_VERSION` were added to set the
+ ``compatibility_version`` and ``curent_version`` respectively
+ on macOS. For backwards compatibility, if these properties
+ are not set, :prop_tgt:`SOVERSION` and :prop_tgt:`VERSION`
+ are used respectively as fallbacks.
diff --git a/Source/cmCommonTargetGenerator.cxx b/Source/cmCommonTargetGenerator.cxx
index 9106e70..b8d8b96 100644
--- a/Source/cmCommonTargetGenerator.cxx
+++ b/Source/cmCommonTargetGenerator.cxx
@@ -233,7 +233,10 @@ void cmCommonTargetGenerator::AppendOSXVerFlag(std::string& flags,
int major;
int minor;
int patch;
- this->GeneratorTarget->GetTargetVersion(so, major, minor, patch);
+ std::string prop = cmStrCat("OSX_", name, "_VERSION");
+ std::string fallback_prop = so ? "SOVERSION" : "VERSION";
+ this->GeneratorTarget->GetTargetVersionFallback(prop, fallback_prop, major,
+ minor, patch);
if (major > 0 || minor > 0 || patch > 0) {
// Append the flag since a non-zero version is specified.
std::ostringstream vflag;
diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx
index 792cd4d..c525a6e 100644
--- a/Source/cmGeneratorTarget.cxx
+++ b/Source/cmGeneratorTarget.cxx
@@ -5280,11 +5280,23 @@ cmComputeLinkInformation* cmGeneratorTarget::GetLinkInformation(
void cmGeneratorTarget::GetTargetVersion(int& major, int& minor) const
{
int patch;
- this->GetTargetVersion(false, major, minor, patch);
+ this->GetTargetVersion("VERSION", major, minor, patch);
}
-void cmGeneratorTarget::GetTargetVersion(bool soversion, int& major,
- int& minor, int& patch) const
+void cmGeneratorTarget::GetTargetVersionFallback(
+ const std::string& property, const std::string& fallback_property,
+ int& major, int& minor, int& patch) const
+{
+ if (this->GetProperty(property)) {
+ this->GetTargetVersion(property, major, minor, patch);
+ } else {
+ this->GetTargetVersion(fallback_property, major, minor, patch);
+ }
+}
+
+void cmGeneratorTarget::GetTargetVersion(const std::string& property,
+ int& major, int& minor,
+ int& patch) const
{
// Set the default values.
major = 0;
@@ -5293,9 +5305,7 @@ void cmGeneratorTarget::GetTargetVersion(bool soversion, int& major,
assert(this->GetType() != cmStateEnums::INTERFACE_LIBRARY);
- // Look for a VERSION or SOVERSION property.
- const char* prop = soversion ? "SOVERSION" : "VERSION";
- if (const char* version = this->GetProperty(prop)) {
+ if (const char* version = this->GetProperty(property)) {
// Try to parse the version number and store the results that were
// successfully parsed.
int parsed_major;
diff --git a/Source/cmGeneratorTarget.h b/Source/cmGeneratorTarget.h
index 9d06104..ac254c1 100644
--- a/Source/cmGeneratorTarget.h
+++ b/Source/cmGeneratorTarget.h
@@ -755,11 +755,19 @@ public:
void GetTargetVersion(int& major, int& minor) const;
/** Get the target major, minor, and patch version numbers
- interpreted from the VERSION or SOVERSION property. Version 0
+ interpreted from the given property. Version 0
is returned if the property is not set or cannot be parsed. */
- void GetTargetVersion(bool soversion, int& major, int& minor,
+ void GetTargetVersion(std::string const& property, int& major, int& minor,
int& patch) const;
+ /** Get the target major, minor, and patch version numbers
+ interpreted from the given property and if empty use the
+ fallback property. Version 0 is returned if the property is
+ not set or cannot be parsed. */
+ void GetTargetVersionFallback(const std::string& property,
+ const std::string& fallback_property,
+ int& major, int& minor, int& patch) const;
+
std::string GetFortranModuleDirectory(std::string const& working_dir) const;
const char* GetSourcesProperty() const;
diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx
index f887284..da56f3f 100644
--- a/Source/cmGlobalXCodeGenerator.cxx
+++ b/Source/cmGlobalXCodeGenerator.cxx
@@ -2366,8 +2366,9 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt,
int minor;
int patch;
- // VERSION -> current_version
- gtgt->GetTargetVersion(false, major, minor, patch);
+ // OSX_CURRENT_VERSION or VERSION -> current_version
+ gtgt->GetTargetVersionFallback("OSX_CURRENT_VERSION", "VERSION", major,
+ minor, patch);
std::ostringstream v;
// Xcode always wants at least 1.0.0 or nothing
@@ -2377,8 +2378,9 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt,
buildSettings->AddAttribute("DYLIB_CURRENT_VERSION",
this->CreateString(v.str()));
- // SOVERSION -> compatibility_version
- gtgt->GetTargetVersion(true, major, minor, patch);
+ // OSX_COMPATIBILITY_VERSION or SOVERSION -> compatibility_version
+ gtgt->GetTargetVersionFallback("OSX_COMPATIBILITY_VERSION", "SOVERSION",
+ major, minor, patch);
std::ostringstream vso;
// Xcode always wants at least 1.0.0 or nothing
diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt
index dae3d17..ad70a34 100644
--- a/Tests/RunCMake/CMakeLists.txt
+++ b/Tests/RunCMake/CMakeLists.txt
@@ -306,6 +306,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)
diff --git a/Tests/RunCMake/MacOSVersions/CMakeLists.txt b/Tests/RunCMake/MacOSVersions/CMakeLists.txt
new file mode 100644
index 0000000..2632ffa
--- /dev/null
+++ b/Tests/RunCMake/MacOSVersions/CMakeLists.txt
@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 3.16)
+project(${RunCMake_TEST} NONE)
+include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/MacOSVersions/MacOSVersions-build-check.cmake b/Tests/RunCMake/MacOSVersions/MacOSVersions-build-check.cmake
new file mode 100644
index 0000000..c4faa8b
--- /dev/null
+++ b/Tests/RunCMake/MacOSVersions/MacOSVersions-build-check.cmake
@@ -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()
diff --git a/Tests/RunCMake/MacOSVersions/MacOSVersions.cmake b/Tests/RunCMake/MacOSVersions/MacOSVersions.cmake
new file mode 100644
index 0000000..629e445
--- /dev/null
+++ b/Tests/RunCMake/MacOSVersions/MacOSVersions.cmake
@@ -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
+ )
diff --git a/Tests/RunCMake/MacOSVersions/RunCMakeTest.cmake b/Tests/RunCMake/MacOSVersions/RunCMakeTest.cmake
new file mode 100644
index 0000000..eb7ca48
--- /dev/null
+++ b/Tests/RunCMake/MacOSVersions/RunCMakeTest.cmake
@@ -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()
diff --git a/Tests/RunCMake/MacOSVersions/foo.c b/Tests/RunCMake/MacOSVersions/foo.c
new file mode 100644
index 0000000..c83d856
--- /dev/null
+++ b/Tests/RunCMake/MacOSVersions/foo.c
@@ -0,0 +1,4 @@
+int foo(void)
+{
+ return 0;
+}