1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-14 02:08:27 +08:00

UseSWIG: Use standard library name conventions for csharp language

Fixes: #21542
This commit is contained in:
Marc Chevrier
2021-03-26 16:27:18 +01:00
parent 18a2e86385
commit 1d8e3a1e77
13 changed files with 98 additions and 3 deletions

View File

@@ -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
=================================

17
Help/policy/CMP0122.rst Normal file
View File

@@ -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

View File

@@ -0,0 +1,5 @@
UseSWIG-csharp
--------------
* The :module:`UseSWIG` module use now standard library name conventions for
``CSharp`` language. See policy :policy:`CMP0122`.

View File

@@ -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 "")

View File

@@ -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) \

View File

@@ -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()

View File

@@ -0,0 +1,2 @@
cmake_policy(SET CMP0122 NEW)
include(CMP0122-common.cmake)

View File

@@ -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()

View File

@@ -0,0 +1,2 @@
cmake_policy(SET CMP0122 OLD)
include(CMP0122-common.cmake)

View File

@@ -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\.$

View File

@@ -0,0 +1 @@
include(CMP0122-common.cmake)

View File

@@ -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")

View File

@@ -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)