CMAKE_MINIMUM_REQUIRED(VERSION 2.8 FATAL_ERROR) PROJECT(RC C RC) SET(CMAKE_VERBOSE_MAKEFILE ON) FILE(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/rc) FUNCTION(ADD_EXECUTABLE TARGET) UNSET(ARGS) FOREACH(i IN LISTS ARGN) IF(i MATCHES "\\.rc$") IF(IS_ABSOLUTE "${i}") GET_FILENAME_COMPONENT(p "${i}" PATH) FILE(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/rc${p}") EXECUTE_PROCESS(COMMAND ${CMAKE_COMMAND} -E create_symlink "${i}" "${CMAKE_BINARY_DIR}/rc${i}") LIST(APPEND ARGS "${CMAKE_BINARY_DIR}/rc${i}") ELSEIF(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${i}") GET_FILENAME_COMPONENT(p "${CMAKE_CURRENT_SOURCE_DIR}/${i}" PATH) FILE(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/rc${p}") EXECUTE_PROCESS(COMMAND ${CMAKE_COMMAND} -E create_symlink "${CMAKE_CURRENT_SOURCE_DIR}/${i}" "${CMAKE_BINARY_DIR}/rc${CMAKE_CURRENT_SOURCE_DIR}/${i}") LIST(APPEND ARGS "${CMAKE_BINARY_DIR}/rc${CMAKE_CURRENT_SOURCE_DIR}/${i}") ELSE() GET_FILENAME_COMPONENT(p "${CMAKE_CURRENT_BINARY_DIR}/${i}" PATH) FILE(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/rc${p}") EXECUTE_PROCESS(COMMAND ${CMAKE_COMMAND} -E create_symlink "${CMAKE_CURRENT_BINARY_DIR}/${i}" "${CMAKE_BINARY_DIR}/rc${CMAKE_CURRENT_BINARY_DIR}/${i}") LIST(APPEND ARGS "${CMAKE_BINARY_DIR}/rc${CMAKE_CURRENT_BINARY_DIR}/${i}") ENDIF() ELSE() LIST(APPEND ARGS "${i}") ENDIF() ENDFOREACH() _ADD_EXECUTABLE(${TARGET} ${ARGS}) ENDFUNCTION() SET_PROPERTY(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "bash ${CMAKE_SOURCE_DIR}/rc.sh ") FILE(WRITE ${CMAKE_BINARY_DIR}/main.c "int main(void){return 0;}\n") FILE(WRITE ${CMAKE_BINARY_DIR}/bindir.rc "") # <-- Something meaningful. ADD_EXECUTABLE(main main.c srcdir.rc bindir.rc "${CMAKE_SOURCE_DIR}/abs.rc")