CSharpMacros.cmake
上传用户:king477883
上传日期:2021-03-01
资源大小:9553k
文件大小:6k
源码类别:

游戏引擎

开发平台:

C++ Builder

  1. # - This is a support module for easy Mono/C# handling with CMake
  2. # It defines the following macros:
  3. #
  4. # ADD_CS_LIBRARY (<target> <source>)
  5. # ADD_CS_EXECUTABLE (<target> <source>)
  6. # INSTALL_GAC (<target>)
  7. #
  8. # Note that the order of the arguments is important.
  9. #
  10. # You can optionally set the variable CS_FLAGS to tell the macros whether
  11. # to pass additional flags to the compiler. This is particularly useful to
  12. # set assembly references, unsafe code, etc... These flags are always reset
  13. # after the target was added so you don't have to care about that.
  14. #
  15. # copyright (c) 2007 Arno Rehn arno@arnorehn.de
  16. #
  17. # Redistribution and use is allowed according to the terms of the GPL license.
  18. # ----- support macros -----
  19. MACRO(GET_CS_LIBRARY_TARGET_DIR)
  20.         IF (NOT LIBRARY_OUTPUT_PATH)
  21.                 SET(CS_LIBRARY_TARGET_DIR ${CMAKE_CURRENT_BINARY_DIR})
  22.         ELSE (NOT LIBRARY_OUTPUT_PATH)
  23.                 SET(CS_LIBRARY_TARGET_DIR ${LIBRARY_OUTPUT_PATH})
  24.         ENDIF (NOT LIBRARY_OUTPUT_PATH)
  25. ENDMACRO(GET_CS_LIBRARY_TARGET_DIR)
  26. MACRO(GET_CS_EXECUTABLE_TARGET_DIR)
  27.         IF (NOT EXECUTABLE_OUTPUT_PATH)
  28.                 SET(CS_EXECUTABLE_TARGET_DIR ${CMAKE_CURRENT_BINARY_DIR})
  29.         ELSE (NOT EXECUTABLE_OUTPUT_PATH)
  30.                 SET(CS_EXECUTABLE_TARGET_DIR ${EXECUTABLE_OUTPUT_PATH})
  31.         ENDIF (NOT EXECUTABLE_OUTPUT_PATH)
  32. ENDMACRO(GET_CS_EXECUTABLE_TARGET_DIR)
  33. MACRO(MAKE_PROPER_FILE_LIST)
  34.         FOREACH(file ${ARGN})
  35.                 # first assume it's a relative path
  36.                 FILE(GLOB globbed ${CMAKE_CURRENT_SOURCE_DIR}/${file})
  37.                 IF(globbed)
  38.                         FILE(TO_NATIVE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/${file} native)
  39.                 ELSE(globbed)
  40.                         FILE(TO_NATIVE_PATH ${file} native)
  41.                 ENDIF(globbed)
  42.                 SET(proper_file_list ${proper_file_list} ${native})
  43.                 SET(native "")
  44.         ENDFOREACH(file)
  45. ENDMACRO(MAKE_PROPER_FILE_LIST)
  46. # ----- end support macros -----
  47. MACRO(ADD_CS_LIBRARY target)
  48.         GET_CS_LIBRARY_TARGET_DIR()
  49.         
  50.         SET(target_DLL "${CS_LIBRARY_TARGET_DIR}/${target}.dll")
  51.         MAKE_PROPER_FILE_LIST(${ARGN})
  52.         FILE(RELATIVE_PATH relative_path ${CMAKE_BINARY_DIR} ${target_DLL})
  53.         
  54.         SET(target_KEY "${CMAKE_CURRENT_SOURCE_DIR}/${target}.key")
  55.         SET(target_CS_FLAGS "${CS_FLAGS}")
  56.         IF(${target}_CS_FLAGS)
  57.                 LIST(APPEND target_CS_FLAGS ${${target}_CS_FLAGS})
  58.         ENDIF(${target}_CS_FLAGS)
  59.         IF(EXISTS ${target_KEY})
  60.                 LIST(APPEND target_CS_FLAGS -keyfile:${target_KEY})
  61.         ENDIF(EXISTS ${target_KEY})
  62.         FOREACH(ref ${${target}_REFS})
  63.                 SET(ref_DLL ${CMAKE_CURRENT_BINARY_DIR}/${ref}.dll)
  64.                 IF(EXISTS ${ref_DLL})
  65.                         LIST(APPEND target_CS_FLAGS -r:${ref_DLL})
  66.                 ELSE(EXISTS ${ref_DLL})
  67.                         LIST(APPEND target_CS_FLAGS -r:${ref})
  68.                 ENDIF(EXISTS ${ref_DLL})
  69.         ENDFOREACH(ref ${${target}_REFS})
  70.         ADD_CUSTOM_COMMAND (OUTPUT ${target_DLL}
  71.                 COMMAND ${MCS_EXECUTABLE} ${target_CS_FLAGS} -out:${target_DLL} -target:library ${proper_file_list}
  72.                 MAIN_DEPENDENCY ${proper_file_list}
  73.                 DEPENDS ${ARGN}
  74.                 COMMENT "Building ${relative_path}")
  75.         ADD_CUSTOM_TARGET (${target} ALL DEPENDS ${target_DLL})
  76.         FOREACH(ref ${${target}_REFS})
  77.                 GET_TARGET_PROPERTY(is_target ${ref} TYPE)
  78.                 IF(is_target)
  79.                         ADD_DEPENDENCIES(${target} ${ref})
  80.                 ENDIF(is_target)
  81.         ENDFOREACH(ref ${${target}_REFS})
  82.         SET(relative_path "")
  83.         SET(proper_file_list "")
  84. ENDMACRO(ADD_CS_LIBRARY)
  85. MACRO(ADD_CS_EXECUTABLE target)
  86.         GET_CS_EXECUTABLE_TARGET_DIR()
  87.         
  88.         # Seems like cmake doesn't like the ".exe" ending for custom commands.
  89.         # If we call it ${target}.exe, 'make' will later complain about a missing rule.
  90.         # Create a fake target instead.
  91.         SET(target_EXE "${CS_EXECUTABLE_TARGET_DIR}/${target}.exe")
  92.         SET(target_TOUCH "${CS_EXECUTABLE_TARGET_DIR}/${target}.exe-built")
  93.         GET_DIRECTORY_PROPERTY(clean ADDITIONAL_MAKE_CLEAN_FILES)
  94.         LIST(APPEND clean ${target}.exe)
  95.         SET_DIRECTORY_PROPERTIES(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${clean}")
  96.         MAKE_PROPER_FILE_LIST(${ARGN})
  97.         FILE(RELATIVE_PATH relative_path ${CMAKE_BINARY_DIR} ${target_EXE})
  98.         SET(target_CS_FLAGS "${CS_FLAGS}")
  99.         
  100.         FOREACH(ref ${${target}_REFS})
  101.                 SET(ref_DLL ${CMAKE_CURRENT_SOURCE_DIR}/${ref}.dll)
  102.                 IF(EXISTS ${ref_DLL})
  103.                         LIST(APPEND target_CS_FLAGS -r:${ref_DLL})
  104.                 ELSE(EXISTS ${ref_DLL})
  105.                         LIST(APPEND target_CS_FLAGS -r:${ref})
  106.                 ENDIF(EXISTS ${ref_DLL})
  107.         ENDFOREACH(ref ${${target}_REFS})
  108.         ADD_CUSTOM_COMMAND (OUTPUT "${target_TOUCH}"
  109.                 COMMAND ${MCS_EXECUTABLE} ${target_CS_FLAGS} -out:${target_EXE} ${proper_file_list}
  110.                 COMMAND ${CMAKE_COMMAND} -E touch ${target_TOUCH}
  111.                 MAIN_DEPENDENCY ${ARGN}
  112.                 DEPENDS ${ARGN}
  113.                 COMMENT "Building ${relative_path}")
  114.         ADD_CUSTOM_TARGET ("${target}" ALL DEPENDS "${target_TOUCH}")
  115.         FOREACH(ref ${${target}_REFS})
  116.                 GET_TARGET_PROPERTY(is_target ${ref} TYPE)
  117.                 IF(is_target)
  118.                         ADD_DEPENDENCIES(${target} ${ref})
  119.                 ENDIF(is_target)
  120.         ENDFOREACH(ref ${${target}_REFS})
  121.         SET(relative_path "")
  122.         SET(proper_file_list "")
  123. ENDMACRO(ADD_CS_EXECUTABLE)
  124. MACRO(INSTALL_GAC target)
  125.         GET_CS_LIBRARY_TARGET_DIR()
  126.         
  127.         INSTALL(CODE "EXECUTE_PROCESS(COMMAND ${GACUTIL_EXECUTABLE} -i ${CS_LIBRARY_TARGET_DIR}/${target}.dll -package 2.0)")
  128. ENDMACRO(INSTALL_GAC target)