summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBernhard Guillon <Bernhard.Guillon@begu.org>2026-06-30 20:31:21 +0200
committerBernhard Guillon <Bernhard.Guillon@begu.org>2026-06-30 20:31:21 +0200
commit2c74c8a08becb4cc12f3b7b280e46e9816a5dc21 (patch)
treeb9745e3d838a04e52b6b245afb7b2f580ef8e74f
parentceaf6ef05eb50b84c5de159a71e5869e2ac38f85 (diff)
downloadcsharp-cmake-2c74c8a08becb4cc12f3b7b280e46e9816a5dc21.tar.gz
csharp-cmake-2c74c8a08becb4cc12f3b7b280e46e9816a5dc21.zip
Reorganize into hello/ and foobar/ subdirectories
-rw-r--r--CMakeLists.txt50
-rw-r--r--foobar/CMakeLists.txt18
-rw-r--r--foobar/FooBar.cs (renamed from FooBar.cs)1
-rw-r--r--hello/CMakeLists.txt25
-rw-r--r--hello/Program.cs (renamed from Program.cs)0
5 files changed, 45 insertions, 49 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 2f12093..771f46b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -5,51 +5,5 @@ 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)
+add_subdirectory(foobar)
+add_subdirectory(hello)
diff --git a/foobar/CMakeLists.txt b/foobar/CMakeLists.txt
new file mode 100644
index 0000000..87dbba4
--- /dev/null
+++ b/foobar/CMakeLists.txt
@@ -0,0 +1,18 @@
+set(FOOBAR_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/FooBar.cs)
+set(FOOBAR_OUTPUT ${CMAKE_BINARY_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})
diff --git a/FooBar.cs b/foobar/FooBar.cs
index 1ccbe3b..fea9685 100644
--- a/FooBar.cs
+++ b/foobar/FooBar.cs
@@ -5,6 +5,5 @@ public class FooBar
public static void Print()
{
Console.WriteLine("FooBar");
- Console.WriteLine("FooBar");
}
}
diff --git a/hello/CMakeLists.txt b/hello/CMakeLists.txt
new file mode 100644
index 0000000..3d1427d
--- /dev/null
+++ b/hello/CMakeLists.txt
@@ -0,0 +1,25 @@
+set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/Program.cs)
+set(TARGET HelloCMake)
+set(OUTPUT_FILE ${CMAKE_BINARY_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:${CMAKE_BINARY_DIR}/FooBar.dll
+ -main:Program
+ ${SOURCES}
+ COMMAND ${CMAKE_COMMAND} -E copy_if_different
+ ${CMAKE_SOURCE_DIR}/HelloCMake.runtimeconfig.json
+ ${CMAKE_BINARY_DIR}/${TARGET}.runtimeconfig.json
+ DEPENDS ${SOURCES} ${CMAKE_BINARY_DIR}/FooBar.dll
+ COMMENT "Compiling ${TARGET} with Roslyn csc..."
+)
+
+add_custom_target(${TARGET} ALL DEPENDS ${OUTPUT_FILE})
+add_dependencies(${TARGET} FooBar)
diff --git a/Program.cs b/hello/Program.cs
index 33e286c..33e286c 100644
--- a/Program.cs
+++ b/hello/Program.cs