GenQrc.cmake 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # GenQrc.cmake - Copyright (c) 2015 Lukas W <lukaswhl/at/gmail.com>
  2. # Generates a simple qrc file containing the given resource files ${ARGN}:
  3. # GEN_QRC(resources.qrc artwork.png icon.png PREFIX /icons)
  4. # Files may also be added using a pattern with the GLOB keyword, e.g.:
  5. # GEN_QRC(resources.qrc GLOB *.png)
  6. FUNCTION(GEN_QRC OUT_FILE)
  7. CMAKE_PARSE_ARGUMENTS(RC "" "PREFIX;GLOB" "" ${ARGN})
  8. IF(DEFINED RC_GLOB)
  9. FILE(GLOB GLOB_FILES ${RC_GLOB})
  10. ENDIF()
  11. # Set the standard prefix to "/" if none is given
  12. IF(NOT DEFINED RC_PREFIX)
  13. SET(RC_PREFIX "/")
  14. ENDIF()
  15. # We need to convert our list to a string in order to pass it to the script
  16. # on the command line.
  17. STRING(REPLACE ";" "\;" FILES "${RC_UNPARSED_ARGUMENTS};${GLOB_FILES}")
  18. SET(GENQRC_SCRIPT "${CMAKE_SOURCE_DIR}/cmake/scripts/GenQrc.cmake")
  19. ADD_CUSTOM_COMMAND(
  20. OUTPUT ${OUT_FILE}
  21. COMMAND ${CMAKE_COMMAND} -D OUT_FILE=${OUT_FILE} -D RC_PREFIX=${RC_PREFIX} -D FILES:list=${FILES} -D DIR=${CMAKE_CURRENT_SOURCE_DIR} -P "${GENQRC_SCRIPT}"
  22. DEPENDS ${GENQRC_SCRIPT}
  23. WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
  24. VERBATIM
  25. )
  26. ENDFUNCTION()
  27. # Generates a qrc file named ${QRC_OUT} from ${ARGN}, rccs it and returns Qt's
  28. # output file.
  29. # Must only be run once per CMakeLists.txt.
  30. # Usage example:
  31. # ADD_GEN_QRC(RCC_OUTPUT resources.qrc icon.png manual.pdf)
  32. # ADD_EXECUTABLE(myexe main.cpp ${RCC_OUTPUT})
  33. MACRO(ADD_GEN_QRC RCCOUT QRC_OUT)
  34. IF(NOT IS_ABSOLUTE ${QRC_OUT})
  35. SET(QRC_FILE "${CMAKE_CURRENT_BINARY_DIR}/${QRC_OUT}")
  36. ELSE()
  37. SET(QRC_FILE ${QRC_OUT})
  38. ENDIF()
  39. GEN_QRC(${QRC_FILE} "${ARGN}")
  40. QT5_ADD_RESOURCES(${RCCOUT} ${QRC_FILE})
  41. ENDMACRO()