blob: 2f1209378eedee074098063def029b432e97eb24 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
cmake_minimum_required(VERSION 4.3)
project(HelloCMake)
set(DOTNET_ROOT /usr/share/dotnet)
set(CSC_DLL ${DOTNET_ROOT}/sdk/10.0.109/Roslyn/bincore/csc.dll)
set(RUNTIME_DIR ${DOTNET_ROOT}/shared/Microsoft.NETCore.App/10.0.9)
set(OUTPUT_DIR ${CMAKE_BINARY_DIR})
# FooBar library
set(FOOBAR_SOURCES ${CMAKE_SOURCE_DIR}/FooBar.cs)
set(FOOBAR_OUTPUT ${OUTPUT_DIR}/FooBar.dll)
add_custom_command(
OUTPUT ${FOOBAR_OUTPUT}
COMMAND dotnet ${CSC_DLL}
-target:library
-out:${FOOBAR_OUTPUT}
-lib:${RUNTIME_DIR}
-reference:System.Private.CoreLib.dll
-reference:System.Runtime.dll
-reference:System.Console.dll
${FOOBAR_SOURCES}
DEPENDS ${FOOBAR_SOURCES}
COMMENT "Compiling FooBar library with Roslyn csc..."
)
add_custom_target(FooBar ALL DEPENDS ${FOOBAR_OUTPUT})
# HelloCMake executable
set(SOURCES ${CMAKE_SOURCE_DIR}/Program.cs)
set(TARGET HelloCMake)
set(OUTPUT_FILE ${OUTPUT_DIR}/${TARGET}.dll)
add_custom_command(
OUTPUT ${OUTPUT_FILE}
COMMAND dotnet ${CSC_DLL}
-target:exe
-out:${OUTPUT_FILE}
-lib:${RUNTIME_DIR}
-reference:System.Private.CoreLib.dll
-reference:System.Runtime.dll
-reference:System.Console.dll
-reference:${FOOBAR_OUTPUT}
-main:Program
${SOURCES}
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${CMAKE_SOURCE_DIR}/HelloCMake.runtimeconfig.json
${OUTPUT_DIR}/${TARGET}.runtimeconfig.json
DEPENDS ${SOURCES} ${FOOBAR_OUTPUT}
COMMENT "Compiling ${TARGET} with Roslyn csc..."
)
add_custom_target(${TARGET} ALL DEPENDS ${OUTPUT_FILE})
add_dependencies(${TARGET} FooBar)
|