summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBernhard Guillon <Bernhard.Guillon@begu.org>2026-06-30 21:08:01 +0200
committerBernhard Guillon <Bernhard.Guillon@begu.org>2026-06-30 21:08:01 +0200
commit4aef7357af63fc20681f40fc77957811cd8f88a4 (patch)
tree472ce62fb149cb790c369cc90fdcd75b8197b92a
parent17a7b6d602ec4e0bf39078a3a9a03ef71d65cf10 (diff)
downloadcsharp-cmake-4aef7357af63fc20681f40fc77957811cd8f88a4.tar.gz
csharp-cmake-4aef7357af63fc20681f40fc77957811cd8f88a4.zip
Use add_library instead of custom command for C library
-rw-r--r--CMakeLists.txt2
-rw-r--r--chello/CMakeLists.txt16
2 files changed, 4 insertions, 14 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 4a9563a..7706b85 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 4.3)
-project(HelloCMake)
+project(HelloCMake LANGUAGES C)
set(DOTNET_ROOT /usr/share/dotnet)
set(CSC_DLL ${DOTNET_ROOT}/sdk/10.0.109/Roslyn/bincore/csc.dll)
diff --git a/chello/CMakeLists.txt b/chello/CMakeLists.txt
index f7a276f..c48ba4b 100644
--- a/chello/CMakeLists.txt
+++ b/chello/CMakeLists.txt
@@ -1,15 +1,5 @@
-find_program(CMAKE_C_COMPILER NAMES gcc cc)
-if(NOT CMAKE_C_COMPILER)
- message(FATAL_ERROR "C compiler not found!")
-endif()
+add_library(hello_c SHARED hello.c)
-set(OUTPUT_FILE ${CMAKE_BINARY_DIR}/libhello_c.so)
-
-add_custom_command(
- OUTPUT ${OUTPUT_FILE}
- COMMAND ${CMAKE_C_COMPILER} -shared -fPIC -o ${OUTPUT_FILE} ${CMAKE_CURRENT_SOURCE_DIR}/hello.c
- DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/hello.c
- COMMENT "Compiling hello_c shared library..."
+set_target_properties(hello_c PROPERTIES
+ LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}
)
-
-add_custom_target(hello_c ALL DEPENDS ${OUTPUT_FILE})