BuildPlugin.cmake 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. # BuildPlugin.cmake - Copyright (c) 2008 Tobias Doerffel
  2. #
  3. # description: build LMMS-plugin
  4. # usage: BUILD_PLUGIN(<PLUGIN_NAME> <PLUGIN_SOURCES> MOCFILES <HEADERS_FOR_MOC> EMBEDDED_RESOURCES <LIST_OF_FILES_TO_EMBED> UICFILES <UI_FILES_TO_COMPILE> LINK <SHARED|MODULE>)
  5. INCLUDE(GenQrc)
  6. MACRO(BUILD_PLUGIN PLUGIN_NAME)
  7. CMAKE_PARSE_ARGUMENTS(PLUGIN "" "LINK;EXPORT_BASE_NAME" "MOCFILES;EMBEDDED_RESOURCES;UICFILES" ${ARGN})
  8. SET(PLUGIN_SOURCES ${PLUGIN_UNPARSED_ARGUMENTS})
  9. INCLUDE_DIRECTORIES("${CMAKE_CURRENT_BINARY_DIR}" "${CMAKE_BINARY_DIR}" "${CMAKE_SOURCE_DIR}/include")
  10. ADD_DEFINITIONS(-DPLUGIN_NAME=${PLUGIN_NAME})
  11. LIST(LENGTH PLUGIN_EMBEDDED_RESOURCES ER_LEN)
  12. IF(ER_LEN)
  13. # Expand and sort arguments to avoid locale dependent sorting in
  14. # shell
  15. SET(NEW_ARGS)
  16. FOREACH(ARG ${PLUGIN_EMBEDDED_RESOURCES})
  17. FILE(GLOB EXPANDED "${ARG}")
  18. LIST(SORT EXPANDED)
  19. FOREACH(ITEM ${EXPANDED})
  20. LIST(APPEND NEW_ARGS "${ITEM}")
  21. ENDFOREACH()
  22. ENDFOREACH()
  23. SET(PLUGIN_EMBEDDED_RESOURCES ${NEW_ARGS})
  24. ADD_GEN_QRC(RCC_OUT "${PLUGIN_NAME}.qrc" PREFIX artwork/${PLUGIN_NAME} ${PLUGIN_EMBEDDED_RESOURCES})
  25. ENDIF(ER_LEN)
  26. QT5_WRAP_CPP(plugin_MOC_out ${PLUGIN_MOCFILES})
  27. QT5_WRAP_UI(plugin_UIC_out ${PLUGIN_UICFILES})
  28. FOREACH(f ${PLUGIN_SOURCES})
  29. ADD_FILE_DEPENDENCIES(${f} ${RCC_OUT} ${plugin_UIC_out})
  30. ENDFOREACH(f)
  31. IF(LMMS_BUILD_APPLE)
  32. LINK_DIRECTORIES("${CMAKE_BINARY_DIR}")
  33. LINK_LIBRARIES(${QT_LIBRARIES})
  34. ENDIF(LMMS_BUILD_APPLE)
  35. IF(LMMS_BUILD_WIN32)
  36. LINK_DIRECTORIES("${CMAKE_BINARY_DIR}" "${CMAKE_SOURCE_DIR}")
  37. LINK_LIBRARIES(${QT_LIBRARIES})
  38. ENDIF(LMMS_BUILD_WIN32)
  39. IF(LMMS_BUILD_MSYS AND CMAKE_BUILD_TYPE STREQUAL "Debug")
  40. # Override Qt debug libraries with release versions
  41. SET(QT_LIBRARIES "${QT_OVERRIDE_LIBRARIES}")
  42. ENDIF()
  43. IF (NOT PLUGIN_LINK)
  44. SET(PLUGIN_LINK "MODULE")
  45. ENDIF()
  46. ADD_LIBRARY(${PLUGIN_NAME} ${PLUGIN_LINK} ${PLUGIN_SOURCES} ${plugin_MOC_out} ${RCC_OUT})
  47. TARGET_LINK_LIBRARIES(${PLUGIN_NAME} Qt5::Widgets Qt5::Xml)
  48. IF(LMMS_BUILD_WIN32)
  49. TARGET_LINK_LIBRARIES(${PLUGIN_NAME} lmms)
  50. ENDIF(LMMS_BUILD_WIN32)
  51. INSTALL(TARGETS ${PLUGIN_NAME}
  52. LIBRARY DESTINATION "${PLUGIN_DIR}"
  53. RUNTIME DESTINATION "${PLUGIN_DIR}"
  54. )
  55. IF(LMMS_BUILD_APPLE)
  56. IF ("${PLUGIN_LINK}" STREQUAL "SHARED")
  57. SET_TARGET_PROPERTIES(${PLUGIN_NAME} PROPERTIES LINK_FLAGS "-undefined dynamic_lookup")
  58. ELSE()
  59. SET_TARGET_PROPERTIES(${PLUGIN_NAME} PROPERTIES LINK_FLAGS "-bundle_loader \"${CMAKE_BINARY_DIR}/lmms\"")
  60. ENDIF()
  61. ADD_DEPENDENCIES(${PLUGIN_NAME} lmms)
  62. ENDIF(LMMS_BUILD_APPLE)
  63. IF(LMMS_BUILD_WIN32)
  64. IF(STRIP)
  65. ADD_CUSTOM_COMMAND(TARGET ${PLUGIN_NAME} POST_BUILD COMMAND ${STRIP} "$<TARGET_FILE:${PLUGIN_NAME}>")
  66. ENDIF()
  67. SET_TARGET_PROPERTIES(${PLUGIN_NAME} PROPERTIES PREFIX "")
  68. ENDIF()
  69. SET_DIRECTORY_PROPERTIES(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${RCC_OUT} ${plugin_MOC_out}")
  70. IF(NOT PLUGIN_EXPORT_BASE_NAME)
  71. SET(PLUGIN_EXPORT_BASE_NAME "PLUGIN")
  72. ENDIF()
  73. GENERATE_EXPORT_HEADER(${PLUGIN_NAME}
  74. BASE_NAME ${PLUGIN_EXPORT_BASE_NAME}
  75. )
  76. TARGET_INCLUDE_DIRECTORIES(${PLUGIN_NAME}
  77. PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
  78. )
  79. SET_PROPERTY(GLOBAL APPEND PROPERTY PLUGINS_BUILT ${PLUGIN_NAME})
  80. GET_PROPERTY(PLUGINS_BUILT GLOBAL PROPERTY PLUGINS_BUILT)
  81. ENDMACRO(BUILD_PLUGIN)