cmake_minimum_required(VERSION 3.10) project(suntest C) set(SUNCC ${PROJECT_BINARY_DIR}/../compiler/suncc) function(target_add_sun_sources TARGET) foreach(SRC ${ARGN}) cmake_path(GET SRC STEM SUN_BASENAME) set(SUN_OUTPUT ${PROJECT_BINARY_DIR}/${SUN_BASENAME}.c) add_custom_command( OUTPUT ${SUN_OUTPUT} DEPENDS ${SRC} COMMAND ${SUNCC} ${SUN_OUTPUT} ${SRC} ) list(APPEND SUN_C_SOURCES ${SUN_OUTPUT}) endforeach() target_sources(${TARGET} PRIVATE ${SUN_C_SOURCES}) endfunction() set(SUN_TEST_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/test_1.sun ) add_executable(suntest main.c) target_add_sun_sources(suntest ${SUN_TEST_SOURCES}) #target_include_directories(suncc PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) #target_link_libraries(suncc suncore) #target_link_libraries(suncc ${FLEX_LIBRARIES})