Default.cmake 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. ################################################################################
  2. # Command for variable_watch. This command issues error message, if a variable
  3. # is changed. If variable PROPERTY_READER_GUARD_DISABLED is TRUE nothing happens
  4. # variable_watch(<variable> property_reader_guard)
  5. ################################################################################
  6. function(property_reader_guard VARIABLE ACCESS VALUE CURRENT_LIST_FILE STACK)
  7. if("${PROPERTY_READER_GUARD_DISABLED}")
  8. return()
  9. endif()
  10. if("${ACCESS}" STREQUAL "MODIFIED_ACCESS")
  11. message(FATAL_ERROR
  12. " Variable ${VARIABLE} is not supposed to be changed.\n"
  13. " It is used only for reading target property ${VARIABLE}.\n"
  14. " Use\n"
  15. " set_target_properties(\"<target>\" PROPERTIES \"${VARIABLE}\" \"<value>\")\n"
  16. " or\n"
  17. " set_target_properties(\"<target>\" PROPERTIES \"${VARIABLE}_<CONFIG>\" \"<value>\")\n"
  18. " instead.\n")
  19. endif()
  20. endfunction()
  21. ################################################################################
  22. # Create variable <name> with generator expression that expands to value of
  23. # target property <name>_<CONFIG>. If property is empty or not set then property
  24. # <name> is used instead. Variable <name> has watcher property_reader_guard that
  25. # doesn't allow to edit it.
  26. # create_property_reader(<name>)
  27. # Input:
  28. # name - Name of watched property and output variable
  29. ################################################################################
  30. function(create_property_reader NAME)
  31. set(PROPERTY_READER_GUARD_DISABLED TRUE)
  32. set(CONFIG_VALUE "$<TARGET_GENEX_EVAL:${PROPS_TARGET},$<TARGET_PROPERTY:${PROPS_TARGET},${NAME}_$<UPPER_CASE:$<CONFIG>>>>")
  33. set(IS_CONFIG_VALUE_EMPTY "$<STREQUAL:${CONFIG_VALUE},>")
  34. set(GENERAL_VALUE "$<TARGET_GENEX_EVAL:${PROPS_TARGET},$<TARGET_PROPERTY:${PROPS_TARGET},${NAME}>>")
  35. set("${NAME}" "$<IF:${IS_CONFIG_VALUE_EMPTY},${GENERAL_VALUE},${CONFIG_VALUE}>" PARENT_SCOPE)
  36. variable_watch("${NAME}" property_reader_guard)
  37. endfunction()
  38. ################################################################################
  39. # Set property $<name>_${PROPS_CONFIG_U} of ${PROPS_TARGET} to <value>
  40. # set_config_specific_property(<name> <value>)
  41. # Input:
  42. # name - Prefix of property name
  43. # value - New value
  44. ################################################################################
  45. function(set_config_specific_property NAME VALUE)
  46. set_target_properties("${PROPS_TARGET}" PROPERTIES "${NAME}_${PROPS_CONFIG_U}" "${VALUE}")
  47. endfunction()
  48. ################################################################################
  49. create_property_reader("TARGET_NAME")
  50. create_property_reader("OUTPUT_DIRECTORY")
  51. set_config_specific_property("TARGET_NAME" "${PROPS_TARGET}")
  52. set_config_specific_property("OUTPUT_NAME" "${TARGET_NAME}")
  53. set_config_specific_property("ARCHIVE_OUTPUT_NAME" "${TARGET_NAME}")
  54. set_config_specific_property("LIBRARY_OUTPUT_NAME" "${TARGET_NAME}")
  55. set_config_specific_property("RUNTIME_OUTPUT_NAME" "${TARGET_NAME}")
  56. set_config_specific_property("ARCHIVE_OUTPUT_DIRECTORY" "${OUTPUT_DIRECTORY}")
  57. set_config_specific_property("LIBRARY_OUTPUT_DIRECTORY" "${OUTPUT_DIRECTORY}")
  58. set_config_specific_property("RUNTIME_OUTPUT_DIRECTORY" "${OUTPUT_DIRECTORY}")