VCMIUtils.cmake 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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_get_cmake_debug_info)
  57. message(STATUS "Debug - Internal variables:")
  58. get_cmake_property(_variableNames VARIABLES)
  59. foreach(_variableName ${_variableNames})
  60. message(STATUS "${_variableName}=${${_variableName}}")
  61. endforeach()
  62. message(STATUS "Debug - Environment variables:")
  63. execute_process(COMMAND "${CMAKE_COMMAND}" "-E" "environment")
  64. endfunction()