summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Help/manual/cmake-policies.7.rst3
-rw-r--r--Help/policy/CMP0122.rst17
-rw-r--r--Help/release/dev/UseSWIG-csharp.rst5
-rw-r--r--Modules/UseSWIG.cmake19
-rw-r--r--Source/cmPolicies.h6
-rw-r--r--Tests/RunCMake/UseSWIG/CMP0122-NEW-check.cmake10
-rw-r--r--Tests/RunCMake/UseSWIG/CMP0122-NEW.cmake2
-rw-r--r--Tests/RunCMake/UseSWIG/CMP0122-OLD-check.cmake10
-rw-r--r--Tests/RunCMake/UseSWIG/CMP0122-OLD.cmake2
-rw-r--r--Tests/RunCMake/UseSWIG/CMP0122-WARN-stderr.txt10
-rw-r--r--Tests/RunCMake/UseSWIG/CMP0122-WARN.cmake1
-rw-r--r--Tests/RunCMake/UseSWIG/CMP0122-common.cmake12
-rw-r--r--Tests/RunCMake/UseSWIG/RunCMakeTest.cmake4
13 files changed, 98 insertions, 3 deletions
diff --git a/Help/manual/cmake-policies.7.rst b/Help/manual/cmake-policies.7.rst
index f103c50..5dfa894 100644
--- a/Help/manual/cmake-policies.7.rst
+++ b/Help/manual/cmake-policies.7.rst
@@ -57,7 +57,8 @@ Policies Introduced by CMake 3.21
.. toctree::
:maxdepth: 1
- CMP0121: The list command detects invalid indicies </policy/CMP0121>
+ CMP0122: UseSWIG use standard library name conventions for csharp language. </policy/CMP0122>
+ CMP0121: The list command detects invalid indicies. </policy/CMP0121>
Policies Introduced by CMake 3.20
=================================
diff --git a/Help/policy/CMP0122.rst b/Help/policy/CMP0122.rst
new file mode 100644
index 0000000..1ff8c48
--- /dev/null
+++ b/Help/policy/CMP0122.rst
@@ -0,0 +1,17 @@
+CMP0122
+-------
+
+.. versionadded:: 3.21
+
+:module:`UseSWIG` use library name conventions for ``CSharp`` language.
+
+Starting with CMake 3.21, :module:`UseSWIG` generates now a library using
+default naming conventions. This policy provides compatibility with projects
+that expect the legacy behavior.
+
+This policy was introduced in CMake version 3.21. CMake version
+|release| warns when the policy is not set and uses ``OLD`` behavior.
+Use the :command:`cmake_policy` command to set it to ``OLD`` or ``NEW``
+explicitly.
+
+.. include:: DEPRECATED.txt
diff --git a/Help/release/dev/UseSWIG-csharp.rst b/Help/release/dev/UseSWIG-csharp.rst
new file mode 100644
index 0000000..dbbeaf1
--- /dev/null
+++ b/Help/release/dev/UseSWIG-csharp.rst
@@ -0,0 +1,5 @@
+UseSWIG-csharp
+--------------
+
+* The :module:`UseSWIG` module use now standard library name conventions for
+ ``CSharp`` language. See policy :policy:`CMP0122`.
diff --git a/Modules/UseSWIG.cmake b/Modules/UseSWIG.cmake
index b1e0576..c7d8346 100644
--- a/Modules/UseSWIG.cmake
+++ b/Modules/UseSWIG.cmake
@@ -38,7 +38,13 @@ Defines the following command for use with ``SWIG``:
.. versionchanged:: 3.15
Alternate library name (set with the :prop_tgt:`OUTPUT_NAME` property,
- for example) will be passed on to Python and CSharp wrapper libraries.
+ for example) will be passed on to ``Python`` and ``CSharp`` wrapper
+ libraries.
+
+ .. versionchanged:: 3.21
+ Generated library use standard naming conventions for ``CSharp`` language
+ when policy :policy:`CMP0122` is set to ``NEW``. Otherwise, the legacy
+ behavior is applied.
.. note::
@@ -950,6 +956,17 @@ function(SWIG_ADD_LIBRARY name)
endif ()
elseif (swig_lowercase_language STREQUAL "fortran")
# Do *not* override the target's library prefix
+ elseif (swig_lowercase_language STREQUAL "csharp")
+ cmake_policy(GET CMP0122 csharp_naming_policy)
+ if (csharp_naming_policy STREQUAL "NEW")
+ # Do *not* override the target's library prefix
+ else()
+ if (NOT csharp_naming_policy)
+ cmake_policy(GET_WARNING CMP0122 _cmp0122_warning)
+ message(AUTHOR_WARNING "${_cmp0122_warning}\n")
+ endif()
+ set_target_properties (${target_name} PROPERTIES PREFIX "")
+ endif()
else()
# assume empty prefix because we expect the module to be dynamically loaded
set_target_properties (${target_name} PROPERTIES PREFIX "")
diff --git a/Source/cmPolicies.h b/Source/cmPolicies.h
index 9295a3f..d546b6e 100644
--- a/Source/cmPolicies.h
+++ b/Source/cmPolicies.h
@@ -362,7 +362,11 @@ class cmMakefile;
cmPolicies::WARN) \
SELECT(POLICY, CMP0121, \
"The list() command now validates parsing of index arguments.", 3, \
- 21, 0, cmPolicies::WARN)
+ 21, 0, cmPolicies::WARN) \
+ SELECT( \
+ POLICY, CMP0122, \
+ "UseSWIG use standard library name conventions for csharp language.", 3, \
+ 21, 0, cmPolicies::WARN)
#define CM_SELECT_ID(F, A1, A2, A3, A4, A5, A6) F(A1)
#define CM_FOR_EACH_POLICY_ID(POLICY) \
diff --git a/Tests/RunCMake/UseSWIG/CMP0122-NEW-check.cmake b/Tests/RunCMake/UseSWIG/CMP0122-NEW-check.cmake
new file mode 100644
index 0000000..a26c278
--- /dev/null
+++ b/Tests/RunCMake/UseSWIG/CMP0122-NEW-check.cmake
@@ -0,0 +1,10 @@
+
+cmake_policy(VERSION 3.1)
+
+file(STRINGS "${RunCMake_TEST_BINARY_DIR}/CMP0122-library-name.txt" prefixes)
+
+list(GET prefixes 0 std_prefix)
+list(GET prefixes 1 lib_prefix)
+if (NOT std_prefix STREQUAL lib_prefix)
+ string (APPEND RunCMake_TEST_FAILED "\nFound prefix: '${lib_prefix}', expected: '${std_prefix}'.")
+endif()
diff --git a/Tests/RunCMake/UseSWIG/CMP0122-NEW.cmake b/Tests/RunCMake/UseSWIG/CMP0122-NEW.cmake
new file mode 100644
index 0000000..fecb7db
--- /dev/null
+++ b/Tests/RunCMake/UseSWIG/CMP0122-NEW.cmake
@@ -0,0 +1,2 @@
+cmake_policy(SET CMP0122 NEW)
+include(CMP0122-common.cmake)
diff --git a/Tests/RunCMake/UseSWIG/CMP0122-OLD-check.cmake b/Tests/RunCMake/UseSWIG/CMP0122-OLD-check.cmake
new file mode 100644
index 0000000..01657d0
--- /dev/null
+++ b/Tests/RunCMake/UseSWIG/CMP0122-OLD-check.cmake
@@ -0,0 +1,10 @@
+
+cmake_policy(VERSION 3.1)
+
+file(STRINGS "${RunCMake_TEST_BINARY_DIR}/CMP0122-library-name.txt" prefixes)
+
+list(GET prefixes 1 lib_prefix)
+if (lib_prefix)
+ # prefix must be empty
+ string (APPEND RunCMake_TEST_FAILED "\nFound unexpected prefix: '${lib_prefix}'.")
+endif()
diff --git a/Tests/RunCMake/UseSWIG/CMP0122-OLD.cmake b/Tests/RunCMake/UseSWIG/CMP0122-OLD.cmake
new file mode 100644
index 0000000..a787b68
--- /dev/null
+++ b/Tests/RunCMake/UseSWIG/CMP0122-OLD.cmake
@@ -0,0 +1,2 @@
+cmake_policy(SET CMP0122 OLD)
+include(CMP0122-common.cmake)
diff --git a/Tests/RunCMake/UseSWIG/CMP0122-WARN-stderr.txt b/Tests/RunCMake/UseSWIG/CMP0122-WARN-stderr.txt
new file mode 100644
index 0000000..37c4fbd
--- /dev/null
+++ b/Tests/RunCMake/UseSWIG/CMP0122-WARN-stderr.txt
@@ -0,0 +1,10 @@
+CMake Warning \(dev\) at .*/Modules/UseSWIG.cmake:[0-9]+ \(message\):
+ Policy CMP0122 is not set: UseSWIG use standard library name conventions
+ for csharp language\. Run "cmake --help-policy CMP0122" for policy details\.
+ Use the cmake_policy command to set the policy and suppress this warning\.
+
+Call Stack \(most recent call first\):
+ CMP0122-common.cmake:9 \(swig_add_library\)
+ CMP0122-WARN.cmake:1 \(include\)
+ CMakeLists.txt:3 \(include\)
+This warning is for project developers\. Use -Wno-dev to suppress it\.$
diff --git a/Tests/RunCMake/UseSWIG/CMP0122-WARN.cmake b/Tests/RunCMake/UseSWIG/CMP0122-WARN.cmake
new file mode 100644
index 0000000..5d571aa
--- /dev/null
+++ b/Tests/RunCMake/UseSWIG/CMP0122-WARN.cmake
@@ -0,0 +1 @@
+include(CMP0122-common.cmake)
diff --git a/Tests/RunCMake/UseSWIG/CMP0122-common.cmake b/Tests/RunCMake/UseSWIG/CMP0122-common.cmake
new file mode 100644
index 0000000..be880ec
--- /dev/null
+++ b/Tests/RunCMake/UseSWIG/CMP0122-common.cmake
@@ -0,0 +1,12 @@
+
+cmake_policy(SET CMP0078 NEW)
+cmake_policy(SET CMP0086 NEW)
+
+set(SWIG_EXECUTABLE "swig")
+set(SWIG_DIR "/swig")
+include(UseSWIG)
+
+swig_add_library(example LANGUAGE csharp TYPE SHARED SOURCES example.i)
+
+file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/CMP0122-library-name.txt"
+ CONTENT "${CMAKE_SHARED_LIBRARY_PREFIX}\n$<TARGET_FILE_PREFIX:example>\n")
diff --git a/Tests/RunCMake/UseSWIG/RunCMakeTest.cmake b/Tests/RunCMake/UseSWIG/RunCMakeTest.cmake
index 6acf719..c7a118f 100644
--- a/Tests/RunCMake/UseSWIG/RunCMakeTest.cmake
+++ b/Tests/RunCMake/UseSWIG/RunCMakeTest.cmake
@@ -23,3 +23,7 @@ if (CMake_TEST_FindPython)
run_cmake_target(CMP0086-NEW build example)
endif()
+
+run_cmake(CMP0122-WARN)
+run_cmake(CMP0122-OLD)
+run_cmake(CMP0122-NEW)