cmake_minimum_required(VERSION 4.3) project(HelloCMake) find_program(CSC_EXECUTABLE NAMES csc csc.exe) if(NOT CSC_EXECUTABLE) message(FATAL_ERROR "C# compiler (csc) not found!") endif() set(OUTPUT_DIR ${CMAKE_BINARY_DIR}) set(SOURCES ${CMAKE_SOURCE_DIR}/Program.cs) set(TARGET HelloCMake) set(OUTPUT_FILE ${OUTPUT_DIR}/${TARGET}.exe) add_custom_command( OUTPUT ${OUTPUT_FILE} COMMAND ${CSC_EXECUTABLE} /target:exe /out:${OUTPUT_FILE} ${SOURCES} DEPENDS ${SOURCES} COMMENT "Compiling ${TARGET} with csc..." ) add_custom_target(${TARGET} ALL DEPENDS ${OUTPUT_FILE})