mirror of
https://github.com/reactos/CMake.git
synced 2025-02-12 06:51:00 +00:00
![Brad King](/assets/img/avatar_default.png)
A that target contains only `.cs` sources should be generated as a `.csproj` project even if it links to non-CSharp static libraries. The latter case was broken by refactoring in commit v3.12.0-rc1~160^2~7 (remove TargetIsCSharpOnly() and use methods from cmGeneratorTarget, 2018-03-19). The reason is that the `HasLanguage` method added by commit v3.12.0-rc1~239^2~6 (cmGeneratorTarget: add HasLanguage() as wrapper for GetLanguages(), 2018-03-19) enforces its "exclusive" check on the combined set of source file languages and the link language. To restore the original `TargetIsCSharpOnly` semantics, update `HasLanguage` to enforce exclusiveness only on the list of sources. Fixes: #18239
30 lines
1.0 KiB
CMake
30 lines
1.0 KiB
CMake
# test if CSharp application correctly links
|
|
# to managed C++ binary
|
|
cmake_minimum_required(VERSION 3.9)
|
|
project (CSharpLinkToCxx CXX CSharp)
|
|
|
|
# we have to change the default flags for the
|
|
# managed C++ project to build
|
|
string(REPLACE "/EHsc" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
|
|
string(REPLACE "/RTC1" "" CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
|
|
|
|
add_library(CLIApp SHARED cli.hpp cli.cpp)
|
|
|
|
target_compile_options(CLIApp PRIVATE "/clr")
|
|
|
|
add_executable(CSharpLinkToCxx csharp.cs)
|
|
|
|
target_link_libraries(CSharpLinkToCxx CLIApp)
|
|
|
|
# this unmanaged C++ library will be added to the C#/.NET
|
|
# references of CSharpLinkToCxx but it will show a warning
|
|
# because it is unmanaged
|
|
add_library(CppNativeApp SHARED cpp_native.hpp cpp_native.cpp)
|
|
target_link_libraries(CSharpLinkToCxx CppNativeApp)
|
|
|
|
# Link a static C++ library into the CSharp executable.
|
|
# We do not actually use any symbols but this helps cover
|
|
# link language selection.
|
|
add_library(CppStaticLib STATIC cpp_static.cpp)
|
|
target_link_libraries(CSharpLinkToCxx CppStaticLib)
|