summaryrefslogtreecommitdiffstats
path: root/cmake/dotnet.cmake
diff options
context:
space:
mode:
Diffstat (limited to 'cmake/dotnet.cmake')
-rw-r--r--cmake/dotnet.cmake28
1 files changed, 26 insertions, 2 deletions
diff --git a/cmake/dotnet.cmake b/cmake/dotnet.cmake
index b4e893f..c4f00ab 100644
--- a/cmake/dotnet.cmake
+++ b/cmake/dotnet.cmake
@@ -2,8 +2,9 @@
# dotnet.cmake - CMake functions for building .NET projects with Roslyn csc
#
# Provides add_dotnet_library, add_dotnet_executable, target_link_dotnet_libraries,
-# target_link_dotnet_system_references, and dotnet_finalize_targets for building
-# .NET assemblies using the Roslyn compiler bundled with the .NET SDK.
+# target_link_dotnet_system_references, target_link_dotnet_directories, and
+# dotnet_finalize_targets for building .NET assemblies using the Roslyn compiler
+# bundled with the .NET SDK.
#
# Usage pattern:
#
@@ -12,6 +13,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)
+# target_link_dotnet_directories(MyApp /path/to/extra/libs)
#
# dotnet_finalize_targets() # Must be called after all targets are defined
#
@@ -201,6 +203,26 @@ function(target_link_dotnet_system_references TARGET)
endfunction()
+function(target_link_dotnet_directories 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_directories: '${TARGET}' is not a dotnet target")
+ endif()
+
+ foreach(dir IN LISTS arg_UNPARSED_ARGUMENTS)
+ get_property(CURRENT_DIRS GLOBAL PROPERTY DOTNET_TARGET_${TARGET}_LIB_DIRS)
+ if(NOT CURRENT_DIRS)
+ set(CURRENT_DIRS "")
+ endif()
+ list(APPEND CURRENT_DIRS "-lib:${dir}")
+ set_property(GLOBAL PROPERTY DOTNET_TARGET_${TARGET}_LIB_DIRS "${CURRENT_DIRS}")
+ 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.
@@ -216,6 +238,7 @@ function(dotnet_finalize_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)
+ get_property(LIB_DIRS GLOBAL PROPERTY DOTNET_TARGET_${NAME}_LIB_DIRS)
set(OUTPUT_FILE ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${NAME}.dll)
@@ -238,6 +261,7 @@ function(dotnet_finalize_targets)
${SYSTEM_REFS}
-out:${OUTPUT_FILE}
-lib:${RUNTIME_DIR}
+ ${LIB_DIRS}
-reference:System.Private.CoreLib.dll
-reference:System.Runtime.dll
-reference:System.Console.dll