DefineInstallVar.cmake 1.3 KB

1234567891011121314151617181920212223242526272829303132
  1. # This functions forwards a variable to
  2. # the install stage.
  3. # Parameters:
  4. # CONTENT: Variable content.
  5. # NAME: Variable name.
  6. # Options:
  7. # GENERATOR_EXPRESSION: Support generator expression for CONTENT.
  8. function(DEFINE_INSTALL_VAR)
  9. set(options GENERATOR_EXPRESSION)
  10. set(oneValueArgs NAME )
  11. set(multiValueArgs CONTENT)
  12. cmake_parse_arguments(VAR "${options}" "${oneValueArgs}"
  13. "${multiValueArgs}" ${ARGN} )
  14. # install(CODE) does not support generator expression in ver<3.14
  15. if(VAR_GENERATOR_EXPRESSION AND ${CMAKE_VERSION} VERSION_LESS "3.14.0")
  16. include(CreateTempFile)
  17. if(CMAKE_CONFIGURATION_TYPES) # in case of multi-config generators like MSVC generators
  18. CreateTempFilePath(OUTPUT_VAR file_path TAG "${VAR_NAME}" CONTENT "${VAR_CONTENT}" CONFIG_SUFFIX)
  19. install(CODE "file(READ \"${file_path}_\${CMAKE_INSTALL_CONFIG_NAME}\" \"${VAR_NAME}\")")
  20. else()
  21. CreateTempFilePath(OUTPUT_VAR file_path TAG "${VAR_NAME}" CONTENT "${VAR_CONTENT}")
  22. install(CODE "file(READ \"${file_path}\" \"${VAR_NAME}\")")
  23. endif()
  24. else()
  25. if(VAR_GENERATOR_EXPRESSION)
  26. cmake_policy(SET CMP0087 NEW)
  27. endif()
  28. install(CODE "set(\"${VAR_NAME}\" \"${VAR_CONTENT}\")")
  29. endif()
  30. endfunction()