2
0

VCMIUtils.cmake 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. # This file should contain custom functions and macro and them only.
  2. # It's should not alter any configuration on inclusion
  3. #######################################
  4. # Build output path #
  5. #######################################
  6. macro(vcmi_set_output_dir name dir)
  7. # Multi-config builds for Visual Studio, Xcode
  8. foreach(OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES})
  9. string(TOUPPER ${OUTPUTCONFIG} OUTPUTCONFIGUPPERCASE)
  10. set_target_properties(${name} PROPERTIES RUNTIME_OUTPUT_DIRECTORY_${OUTPUTCONFIGUPPERCASE} ${CMAKE_BINARY_DIR}/bin/${OUTPUTCONFIG}/${dir})
  11. set_target_properties(${name} PROPERTIES LIBRARY_OUTPUT_DIRECTORY_${OUTPUTCONFIGUPPERCASE} ${CMAKE_BINARY_DIR}/bin/${OUTPUTCONFIG}/${dir})
  12. set_target_properties(${name} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY_${OUTPUTCONFIGUPPERCASE} ${CMAKE_BINARY_DIR}/bin/${OUTPUTCONFIG}/${dir})
  13. endforeach()
  14. # Generic no-config case for Makefiles, Ninja.
  15. # This is what Qt Creator is using
  16. set_target_properties(${name} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/${dir})
  17. set_target_properties(${name} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/${dir})
  18. set_target_properties(${name} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/${dir})
  19. endmacro()
  20. #######################################
  21. # Project generation #
  22. #######################################
  23. # Let us have proper tree-like structure in IDEs such as Visual Studio
  24. function(assign_source_group)
  25. foreach(_source IN ITEMS ${ARGN})
  26. if(IS_ABSOLUTE "${_source}")
  27. file(RELATIVE_PATH _source_rel "${CMAKE_CURRENT_SOURCE_DIR}" "${_source}")
  28. else()
  29. set(_source_rel "${_source}")
  30. endif()
  31. get_filename_component(_source_path "${_source_rel}" PATH)
  32. string(REPLACE "/" "\\" _source_path_msvc "${_source_path}")
  33. source_group("${_source_path_msvc}" FILES "${_source}")
  34. endforeach()
  35. endfunction(assign_source_group)
  36. # Macro to add subdirectory and set appropriate FOLDER for generated projects files
  37. function(add_subdirectory_with_folder _folder_name _folder)
  38. add_subdirectory(${_folder} ${ARGN})
  39. set_property(DIRECTORY "${_folder}" PROPERTY FOLDER "${_folder_name}")
  40. endfunction()
  41. # Macro for Xcode Projects generation
  42. # Slightly outdated, but useful reference for all options available here:
  43. # https://pewpewthespells.com/blog/buildsettings.html
  44. # https://github.com/samdmarshall/Xcode-Build-Settings-Reference
  45. if(${CMAKE_GENERATOR} MATCHES "Xcode")
  46. macro(set_xcode_property TARGET XCODE_PROPERTY XCODE_VALUE)
  47. set_property(TARGET ${TARGET} PROPERTY
  48. XCODE_ATTRIBUTE_${XCODE_PROPERTY} ${XCODE_VALUE})
  49. endmacro(set_xcode_property)
  50. endif(${CMAKE_GENERATOR} MATCHES "Xcode")
  51. #######################################
  52. # CMake debugging #
  53. #######################################
  54. # Can be called to see check cmake variables and environment variables
  55. # For "install" debugging just copy it here. There no easy way to include modules from source.
  56. function(vcmi_print_all_variables)
  57. message(STATUS "-- -- Start of all internal variables")
  58. get_cmake_property(_variableNames VARIABLES)
  59. foreach(_variableName ${_variableNames})
  60. message(STATUS "${_variableName}=${${_variableName}}")
  61. endforeach()
  62. message(STATUS "-- -- End of all internal variables")
  63. message(STATUS "--")
  64. message(STATUS "-- -- Start of all environment variables")
  65. execute_process(COMMAND "${CMAKE_COMMAND}" "-E" "environment")
  66. message(STATUS "-- -- End of all environment variables")
  67. endfunction()
  68. # Print CMake variables most important for debugging
  69. function(vcmi_print_important_variables)
  70. message(STATUS "-- -- Start of VCMI build debug information")
  71. message(STATUS "CMAKE_VERSION: " ${CMAKE_VERSION})
  72. message(STATUS "CMAKE_BUILD_TYPE: " ${CMAKE_BUILD_TYPE})
  73. message(STATUS "CMAKE_BINARY_DIR: " ${CMAKE_BINARY_DIR})
  74. message(STATUS "CMAKE_SOURCE_DIR: " ${CMAKE_SOURCE_DIR})
  75. # message(STATUS "PROJECT_BINARY_DIR: " ${PROJECT_BINARY_DIR})
  76. # message(STATUS "PROJECT_SOURCE_DIR: " ${PROJECT_SOURCE_DIR})
  77. message(STATUS "CMAKE_MODULE_PATH: " ${CMAKE_MODULE_PATH})
  78. message(STATUS "CMAKE_COMMAND: " ${CMAKE_COMMAND})
  79. message(STATUS "CMAKE_ROOT: " ${CMAKE_ROOT})
  80. # message(STATUS "CMAKE_CURRENT_LIST_FILE and LINE: ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE}")
  81. # message(STATUS "CMAKE_INCLUDE_PATH: " ${CMAKE_INCLUDE_PATH})
  82. # message(STATUS "CMAKE_LIBRARY_PATH: " ${CMAKE_LIBRARY_PATH})
  83. message(STATUS "UNIX: ${UNIX} - WIN32: ${WIN32} - APPLE: ${APPLE}")
  84. message(STATUS "MINGW: ${MINGW} - CYGWIN: ${CYGWIN} - MSVC: ${MSVC}")
  85. message(STATUS "CMAKE_CXX_COMPILER_ID: " ${CMAKE_CXX_COMPILER_ID})
  86. message(STATUS "CMAKE_CXX_COMPILER_VERSION: " ${CMAKE_CXX_COMPILER_VERSION})
  87. message(STATUS "CMAKE_C_COMPILER: " ${CMAKE_C_COMPILER})
  88. message(STATUS "CMAKE_CXX_COMPILER: " ${CMAKE_CXX_COMPILER})
  89. # message(STATUS "CMAKE_COMPILER_IS_GNUCC: " ${CMAKE_COMPILER_IS_GNUCC})
  90. # message(STATUS "CMAKE_COMPILER_IS_GNUCXX: " ${CMAKE_COMPILER_IS_GNUCXX})
  91. # message(STATUS "CMAKE_C_FLAGS: " ${CMAKE_C_FLAGS})
  92. # message(STATUS "CMAKE_CXX_FLAGS: " ${CMAKE_CXX_FLAGS})
  93. message(STATUS "CMAKE_SYSTEM: " ${CMAKE_SYSTEM})
  94. message(STATUS "CMAKE_SYSTEM_NAME: " ${CMAKE_SYSTEM_NAME})
  95. message(STATUS "CMAKE_SYSTEM_VERSION: " ${CMAKE_SYSTEM_VERSION})
  96. message(STATUS "CMAKE_SYSTEM_PROCESSOR: " ${CMAKE_SYSTEM_PROCESSOR})
  97. message(STATUS "-- -- End of VCMI build debug information")
  98. endfunction()
  99. # Print Git commit hash
  100. function(vcmi_print_git_commit_hash)
  101. message(STATUS "-- -- Start of Git information")
  102. message(STATUS "GIT_SHA1: " ${GIT_SHA1})
  103. message(STATUS "-- -- End of Git information")
  104. endfunction()