UseSWIG: swig_add_library fails on csharp output
When trying to use swig_add_library
, configure step fails with CMake Error.
CMake Error: Error required internal CMake variable not set, cmake may not be built correctly.
Missing variable is:
CMAKE_CSharp_COMPILE_OBJECT
Minimal reproduction:
cmake_minimum_required(VERSION 3.12)
find_package(SWIG)
include(UseSWIG)
file(WRITE test.i "%module test")
swig_add_library(csharp
TYPE MODULE
LANGUAGE csharp
SOURCES test.i)
Applying the following patch will fix the issue.
diff --git a/Modules/UseSWIG.cmake b/Modules/UseSWIG.cmake
index 8424a9ffc..02cd2bd4f 100644
--- a/Modules/UseSWIG.cmake
+++ b/Modules/UseSWIG.cmake
@@ -309,7 +309,7 @@ function(SWIG_GET_EXTRA_OUTPUT_FILES language outfiles generatedpath infile)
foreach(it ${SWIG_${language}_EXTRA_FILE_EXTENSIONS})
set(extra_file "${generatedpath}/${module_basename}${it}")
if (extra_file MATCHES "\\.cs$")
- set_source_files_properties(${extra_file} PROPERTIES LANGUAGE "CSharp")
+ set_source_files_properties(${extra_file} PROPERTIES LANGUAGE "")
else()
# Treat extra outputs as plain files regardless of language.
set_source_files_properties(${extra_file} PROPERTIES LANGUAGE "")
I believe the issue will only appear on platforms that do not support building CSharp, i.e. everything but Windows.
Edited by Brad King