CMakeLists.txt 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. #
  2. # Copyright (C) 2013-2020 Mattia Basaglia
  3. #
  4. # This program is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU Lesser General Public License as published by
  6. # the Free Software Foundation, either version 3 of the License, or
  7. # (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU Lesser General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU Lesser General Public License
  15. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. #
  17. cmake_minimum_required (VERSION 3.1 FATAL_ERROR)
  18. if ( ${CMAKE_VERSION} VERSION_GREATER "3.12.0")
  19. cmake_policy(SET CMP0077 NEW)
  20. endif()
  21. set(COLORWIDGET_PROJECT_NAME QtColorWidgets)
  22. project(${COLORWIDGET_PROJECT_NAME} CXX)
  23. set (CMAKE_MODULE_PATH
  24. ${CMAKE_MODULE_PATH}
  25. ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules
  26. ${CMAKE_CURRENT_LIST_DIR})
  27. include (CheckCXXCompilerFlag)
  28. include (cmake/install.cmake)
  29. include (cmake/versioning.cmake)
  30. SET (${COLORWIDGET_PROJECT_NAME}_VERSION_MAJOR 2)
  31. SET (${COLORWIDGET_PROJECT_NAME}_VERSION_MINOR 2)
  32. SET (${COLORWIDGET_PROJECT_NAME}_VERSION_PATCH 0)
  33. SET (${COLORWIDGET_PROJECT_NAME}_VERSION "${${COLORWIDGET_PROJECT_NAME}_VERSION_MAJOR}.${${COLORWIDGET_PROJECT_NAME}_VERSION_MINOR}.${${COLORWIDGET_PROJECT_NAME}_VERSION_PATCH}")
  34. set(QT_VERSION_MAJOR 5)
  35. find_package(QT NAMES Qt5 Qt4 COMPONENTS Core QUIET)
  36. find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core Widgets REQUIRED)
  37. # Auto generate moc files
  38. set(CMAKE_AUTOMOC ON)
  39. # Auto generate moc files
  40. set(CMAKE_AUTOUIC ON)
  41. # Auto generate moc files
  42. set(CMAKE_AUTORCC ON)
  43. set (TARGET_NAME ${COLORWIDGET_PROJECT_NAME})
  44. option(COLOR_WIDGETS_QT_SUFFIX "Append qt version to the target output files" OFF)
  45. if ( COLOR_WIDGETS_QT_SUFFIX )
  46. set (TARGET_OUTPUT_SUFFIX "-Qt${QT_VERSION}${${COLORWIDGET_PROJECT_NAME}_VERSION_MAJOR}")
  47. else()
  48. set (TARGET_OUTPUT_SUFFIX "")
  49. endif()
  50. set (INCLUDE_PREFIX "QtColorWidgets")
  51. set (COLOR_WIDGETS_LIBRARY "${TARGET_NAME}")
  52. add_definitions(-DQTCOLORWIDGETS_STATICALLY_LINKED)
  53. add_library (${TARGET_NAME} STATIC "")
  54. set_target_properties(${TARGET_NAME}
  55. PROPERTIES
  56. EXPORT_NAME "${TARGET_NAME}${TARGET_OUTPUT_SUFFIX}")
  57. set_target_properties (${TARGET_NAME}
  58. PROPERTIES
  59. CXX_STANDARD 11
  60. CXX_STANDARD_REQUIRED ON
  61. VERSION ${${COLORWIDGET_PROJECT_NAME}_VERSION}
  62. SOVERSION ${${COLORWIDGET_PROJECT_NAME}_VERSION_MAJOR}
  63. "INTERFACE_${COLORWIDGET_PROJECT_NAME}_MAJOR_VERSION" ${${COLORWIDGET_PROJECT_NAME}_VERSION_MAJOR}
  64. COMPATIBLE_INTERFACE_STRING "${COLORWIDGET_PROJECT_NAME}_MAJOR_VERSION"
  65. COMPILE_DEFINITIONS QTCOLORWIDGETS_LIBRARY
  66. OUTPUT_NAME "${TARGET_NAME}${TARGET_OUTPUT_SUFFIX}")
  67. check_cxx_compiler_flag ("-Wall" Wall_FLAG_SUPPORTED)
  68. if (Wall_FLAG_SUPPORTED)
  69. set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall")
  70. endif (Wall_FLAG_SUPPORTED)
  71. check_cxx_compiler_flag ("-pedantic" pedantic_FLAG_SUPPORTED)
  72. if (pedantic_FLAG_SUPPORTED)
  73. set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -pedantic")
  74. endif (pedantic_FLAG_SUPPORTED)
  75. check_cxx_compiler_flag ("-Wextra" Wextra_FLAG_SUPPORTED)
  76. if (Wextra_FLAG_SUPPORTED)
  77. set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wextra")
  78. endif (Wextra_FLAG_SUPPORTED)
  79. set (EXPORT_HEADER "${INCLUDE_PREFIX}/colorwidgets_global.hpp")
  80. generate_versioning_information (
  81. TARGET_NAME ${TARGET_NAME}
  82. EXPORT_HEADER ${EXPORT_HEADER}
  83. EXPORT_MACRO QCP_EXPORT
  84. VERSIONED_ENTITY ${COLORWIDGET_PROJECT_NAME}
  85. INCLUDE_PREFIX ${INCLUDE_PREFIX}
  86. COMPANY_NAME "Mattia Basaglia"
  87. COMPANY_COPYRIGHT "Mattia Basaglia Copyright (C) 2013-2020"
  88. FILE_DESCRIPTION "Color wheel widget and dialog for Qt${QT_VERSION}"
  89. )
  90. target_include_directories(${TARGET_NAME}
  91. PUBLIC
  92. $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
  93. $<INSTALL_INTERFACE:include>
  94. PUBLIC
  95. $<BUILD_INTERFACE:${PROJECT_BINARY_DIR}>
  96. $<INSTALL_INTERFACE:include>
  97. )
  98. add_subdirectory (${CMAKE_CURRENT_SOURCE_DIR}/include/${INCLUDE_PREFIX})
  99. add_subdirectory (${CMAKE_CURRENT_SOURCE_DIR}/resources/${INCLUDE_PREFIX})
  100. add_subdirectory (${CMAKE_CURRENT_SOURCE_DIR}/src/${INCLUDE_PREFIX})
  101. target_link_libraries (${TARGET_NAME} PRIVATE Qt${QT_VERSION_MAJOR}::Widgets)
  102. install_project (
  103. PROJECT_NAME ${COLORWIDGET_PROJECT_NAME}
  104. TARGET_NAME ${TARGET_NAME}
  105. TARGET_OUTPUT_SUFFIX "${TARGET_OUTPUT_SUFFIX}"
  106. EXPORT_HEADER ${EXPORT_HEADER}
  107. INCLUDE_PREFIX ${INCLUDE_PREFIX}
  108. HEADER_MATCHING_REGEX "^.*\.h$|^.*\.hpp$|^.*$"
  109. VERSION_HEADER ${CMAKE_CURRENT_BINARY_DIR}/${COLORWIDGET_PROJECT_NAME}_version.h
  110. NAMESPACE "")
  111. add_subdirectory (gallery)
  112. option(QTCOLORWIDGETS_DESIGNER_PLUGIN "Build QtDesigner plugin" ON)
  113. if (${QTCOLORWIDGETS_DESIGNER_PLUGIN})
  114. find_package (Qt5Designer QUIET)
  115. if (Qt5Designer_FOUND)
  116. add_subdirectory (color_widgets_designer_plugin)
  117. endif(Qt5Designer_FOUND)
  118. endif()
  119. configure_file(Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
  120. add_custom_target(
  121. ${COLORWIDGET_PROJECT_NAME}_docs
  122. COMMAND doxygen Doxyfile
  123. COMMAND cp ${CMAKE_CURRENT_SOURCE_DIR}/gallery/*.png ${CMAKE_CURRENT_BINARY_DIR}/doxygen/html
  124. WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
  125. )