summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBernhard Guillon <Bernhard.Guillon@begu.org>2026-06-30 20:29:11 +0200
committerBernhard Guillon <Bernhard.Guillon@begu.org>2026-06-30 20:29:11 +0200
commitceaf6ef05eb50b84c5de159a71e5869e2ac38f85 (patch)
treedd72cc6240825eb5e39dc4b0ac2cc58867f3ecc9
parent5ec50e41ea76d26bac1686672a8cff2248465f98 (diff)
downloadcsharp-cmake-ceaf6ef05eb50b84c5de159a71e5869e2ac38f85.tar.gz
csharp-cmake-ceaf6ef05eb50b84c5de159a71e5869e2ac38f85.zip
Add FooBar library with CMake build integration
-rw-r--r--CMakeLists.txt26
-rw-r--r--FooBar.cs10
-rw-r--r--Program.cs1
3 files changed, 36 insertions, 1 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index b76d217..2f12093 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -6,6 +6,28 @@ 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)
@@ -19,13 +41,15 @@ add_custom_command(
-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}
+ DEPENDS ${SOURCES} ${FOOBAR_OUTPUT}
COMMENT "Compiling ${TARGET} with Roslyn csc..."
)
add_custom_target(${TARGET} ALL DEPENDS ${OUTPUT_FILE})
+add_dependencies(${TARGET} FooBar)
diff --git a/FooBar.cs b/FooBar.cs
new file mode 100644
index 0000000..1ccbe3b
--- /dev/null
+++ b/FooBar.cs
@@ -0,0 +1,10 @@
+using System;
+
+public class FooBar
+{
+ public static void Print()
+ {
+ Console.WriteLine("FooBar");
+ Console.WriteLine("FooBar");
+ }
+}
diff --git a/Program.cs b/Program.cs
index 5dd49a9..33e286c 100644
--- a/Program.cs
+++ b/Program.cs
@@ -5,5 +5,6 @@ class Program
static void Main()
{
Console.WriteLine("Hello, CMake + C#!");
+ FooBar.Print();
}
}