summaryrefslogtreecommitdiffstats
path: root/cmake
diff options
context:
space:
mode:
Diffstat (limited to 'cmake')
-rw-r--r--cmake/dotnet.cmake27
1 files changed, 25 insertions, 2 deletions
diff --git a/cmake/dotnet.cmake b/cmake/dotnet.cmake
index 8782659..b4e893f 100644
--- a/cmake/dotnet.cmake
+++ b/cmake/dotnet.cmake
@@ -2,8 +2,8 @@
# dotnet.cmake - CMake functions for building .NET projects with Roslyn csc
#
# Provides add_dotnet_library, add_dotnet_executable, target_link_dotnet_libraries,
-# and dotnet_finalize_targets for building .NET assemblies using the Roslyn
-# compiler bundled with the .NET SDK.
+# target_link_dotnet_system_references, and dotnet_finalize_targets for building
+# .NET assemblies using the Roslyn compiler bundled with the .NET SDK.
#
# Usage pattern:
#
@@ -11,6 +11,7 @@
#
# add_dotnet_executable(MyApp MAIN Program SOURCES Program.cs)
# target_link_dotnet_libraries(MyApp PRIVATE MyLib)
+# target_link_dotnet_system_references(MyApp System.Linq System.Net.Http)
#
# dotnet_finalize_targets() # Must be called after all targets are defined
#
@@ -180,6 +181,26 @@ function(target_link_dotnet_libraries TARGET)
endfunction()
+function(target_link_dotnet_system_references TARGET)
+ cmake_parse_arguments(PARSE_ARGV 1 arg "" "" "${ARGN}")
+
+ get_property(ALL_TARGETS GLOBAL PROPERTY DOTNET_TARGETS)
+ list(FIND ALL_TARGETS "${TARGET}" _idx)
+ if(_idx EQUAL -1)
+ message(FATAL_ERROR "target_link_dotnet_system_references: '${TARGET}' is not a dotnet target")
+ endif()
+
+ foreach(ref IN LISTS arg_UNPARSED_ARGUMENTS)
+ get_property(CURRENT_REFS GLOBAL PROPERTY DOTNET_TARGET_${TARGET}_SYSTEM_REFS)
+ if(NOT CURRENT_REFS)
+ set(CURRENT_REFS "")
+ endif()
+ list(APPEND CURRENT_REFS "-reference:${ref}.dll")
+ set_property(GLOBAL PROPERTY DOTNET_TARGET_${TARGET}_SYSTEM_REFS "${CURRENT_REFS}")
+ endforeach()
+endfunction()
+
+
# Creates the actual custom commands and targets with full dependency knowledge.
# Must be called after all add_dotnet_library/add_dotnet_executable and
# target_link_dotnet_libraries calls.
@@ -194,6 +215,7 @@ function(dotnet_finalize_targets)
get_property(DEP_TARGETS GLOBAL PROPERTY DOTNET_TARGET_${NAME}_DEP_TARGETS)
get_property(ALL_REFS GLOBAL PROPERTY DOTNET_TARGET_${NAME}_ALL_REFS)
get_property(PUB_REFS GLOBAL PROPERTY DOTNET_TARGET_${NAME}_PUB_REFS)
+ get_property(SYSTEM_REFS GLOBAL PROPERTY DOTNET_TARGET_${NAME}_SYSTEM_REFS)
set(OUTPUT_FILE ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${NAME}.dll)
@@ -213,6 +235,7 @@ function(dotnet_finalize_targets)
COMMAND dotnet ${CSC_DLL}
${CSC_FLAGS}
${ALL_REFS}
+ ${SYSTEM_REFS}
-out:${OUTPUT_FILE}
-lib:${RUNTIME_DIR}
-reference:System.Private.CoreLib.dll