torque_macros.cmake 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. # -----------------------------------------------------------------------------
  2. # Copyright (c) 2014 GarageGames, LLC
  3. #
  4. # Permission is hereby granted, free of charge, to any person obtaining a copy
  5. # of this software and associated documentation files (the "Software"), to
  6. # deal in the Software without restriction, including without limitation the
  7. # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. # sell copies of the Software, and to permit persons to whom the Software is
  9. # furnished to do so, subject to the following conditions:
  10. #
  11. # The above copyright notice and this permission notice shall be included in
  12. # all copies or substantial portions of the Software.
  13. #
  14. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. # IN THE SOFTWARE.
  21. # -----------------------------------------------------------------------------
  22. ################# Helper Functions ###################
  23. macro(setupVersionNumbers)
  24. set(TORQUE_APP_VERSION_MAJOR 1 CACHE STRING "")
  25. set(TORQUE_APP_VERSION_MINOR 0 CACHE STRING "")
  26. set(TORQUE_APP_VERSION_PATCH 0 CACHE STRING "")
  27. set(TORQUE_APP_VERSION_TWEAK 0 CACHE STRING "")
  28. mark_as_advanced(TORQUE_APP_VERSION_TWEAK)
  29. MATH(EXPR TORQUE_APP_VERSION "${TORQUE_APP_VERSION_MAJOR} * 1000 + ${TORQUE_APP_VERSION_MINOR} * 100 + ${TORQUE_APP_VERSION_PATCH} * 10 + ${TORQUE_APP_VERSION_TWEAK}")
  30. set(TORQUE_APP_VERSION_STRING "${TORQUE_APP_VERSION_MAJOR}.${TORQUE_APP_VERSION_MINOR}.${TORQUE_APP_VERSION_PATCH}.${TORQUE_APP_VERSION_TWEAK}")
  31. endmacro()
  32. function(installTemplate templateName)
  33. message("Prepare Template(${templateName}) install...")
  34. file(COPY "${CMAKE_SOURCE_DIR}/Templates/${templateName}/" DESTINATION "${TORQUE_APP_ROOT_DIRECTORY}" FILES_MATCHING PATTERN "*.in")
  35. file(COPY "${CMAKE_SOURCE_DIR}/Templates/${templateName}/" DESTINATION "${TORQUE_APP_ROOT_DIRECTORY}" FILES_MATCHING PATTERN "*.cmake")
  36. add_subdirectory("${CMAKE_SOURCE_DIR}/Templates/${templateName}")
  37. endfunction()
  38. MACRO(SUBDIRLIST result curdir)
  39. FILE(GLOB children RELATIVE ${curdir} ${curdir}/*)
  40. SET(dirlist "")
  41. FOREACH(child ${children})
  42. IF(IS_DIRECTORY ${curdir}/${child})
  43. LIST(APPEND dirlist ${child})
  44. ENDIF()
  45. ENDFOREACH()
  46. SET(${result} ${dirlist})
  47. ENDMACRO()
  48. # Helper function to add a directory to the TORQUE_SOURCE_FILES variable. It automatically searches for .cpp and .h files in the
  49. # specified directory then adds them to the TORQUE_SOURCE_FILES variable.
  50. macro (torqueAddSourceDirectories)
  51. foreach(ARGUMENT ${ARGV})
  52. file(GLOB SCANNED_SOURCE_FILES "${ARGUMENT}/*.cpp")
  53. file(GLOB SCANNED_INCLUDE_FILES "${ARGUMENT}/*.h")
  54. if (APPLE)
  55. file(GLOB SCANNED_MAC_FILES "${ARGUMENT}/*.mm")
  56. endif (APPLE)
  57. # Set in both current and parent scope so this macro can be used from loaded modules
  58. set(TORQUE_SOURCE_FILES ${TORQUE_SOURCE_FILES} ${SCANNED_SOURCE_FILES} ${SCANNED_INCLUDE_FILES} ${SCANNED_MAC_FILES})
  59. set(TORQUE_SOURCE_FILES ${TORQUE_SOURCE_FILES} PARENT_SCOPE)
  60. endforeach()
  61. endmacro (torqueAddSourceDirectories)
  62. ################# Set Conditional Engine Defines ###################
  63. macro (forwardDef flag)
  64. if (${flag})
  65. set(TORQUE_COMPILE_DEFINITIONS ${TORQUE_COMPILE_DEFINITIONS} ${flag})
  66. endif()
  67. endmacro(forwardDef)
  68. macro (advanced_option flag description state)
  69. option(${flag} ${description} ${state})
  70. mark_as_advanced(${flag})
  71. endmacro(advanced_option)
  72. ################# additional preprocessor defines ###################
  73. macro(__addDef def config)
  74. # two possibilities: a) target already known, so add it directly, or b) target not yet known, so add it to its cache
  75. if(TARGET ${PROJECT_NAME})
  76. #message(STATUS "directly applying defs: ${PROJECT_NAME} with config ${config}: ${def}")
  77. if("${config}" STREQUAL "")
  78. set_property(TARGET ${PROJECT_NAME} APPEND PROPERTY COMPILE_DEFINITIONS ${def})
  79. else()
  80. set_property(TARGET ${PROJECT_NAME} APPEND PROPERTY COMPILE_DEFINITIONS $<$<CONFIG:${config}>:${def}>)
  81. endif()
  82. else()
  83. if("${config}" STREQUAL "")
  84. list(APPEND ${PROJECT_NAME}_defs_ ${def})
  85. else()
  86. list(APPEND ${PROJECT_NAME}_defs_ $<$<CONFIG:${config}>:${def}>)
  87. endif()
  88. #message(STATUS "added definition to cache: ${PROJECT_NAME}_defs_: ${${PROJECT_NAME}_defs_}")
  89. endif()
  90. endmacro()
  91. # adds a definition: argument 1: Nothing(for all), _DEBUG, _RELEASE, <more build configurations>
  92. macro(addDef def)
  93. set(def_configs "")
  94. if(${ARGC} GREATER 1)
  95. foreach(config ${ARGN})
  96. __addDef(${def} ${config})
  97. endforeach()
  98. else()
  99. __addDef(${def} "")
  100. endif()
  101. endmacro()
  102. # this applies cached definitions onto the target must come *after* target_compile_definitions
  103. macro(append_defs)
  104. if(DEFINED ${PROJECT_NAME}_defs_)
  105. set_property(TARGET ${PROJECT_NAME} APPEND PROPERTY COMPILE_DEFINITIONS ${${PROJECT_NAME}_defs_})
  106. #message(STATUS "applying defs to project ${PROJECT_NAME}: ${${PROJECT_NAME}_defs_}")
  107. else()
  108. #message(STATUS "NO ${PROJECT_NAME}_defs_ defined!")
  109. endif()
  110. endmacro()
  111. ################# file filtering ###################
  112. macro (filterOut)
  113. foreach(ARGUMENT ${ARGV})
  114. list(REMOVE_ITEM TORQUE_SOURCE_FILES "${CMAKE_SOURCE_DIR}/Engine/source/${ARGUMENT}")
  115. endforeach()
  116. endmacro (filterOut)
  117. ################# apple frameworks ###################
  118. macro(addFramework framework)
  119. if (APPLE)
  120. find_library(_${framework}_FRAMEWORK_PATH ${framework} PATHS /System/Library/Frameworks /Library/Frameworks)
  121. set(TORQUE_LINK_FRAMEWORKS ${TORQUE_LINK_FRAMEWORKS} "${_${framework}_FRAMEWORK_PATH}")
  122. endif()
  123. endmacro()