1 # Based on CMakeDependentOption.cmake
2 #=============================================================================
3 # Copyright 2006-2009 Kitware, Inc.
4 # Copyright 2013 Pali Rohár <pali.rohar@gmail.com>
6 # Distributed under the OSI-approved BSD License (the "License");
7 # see accompanying file Copyright.txt for details.
9 # This software is distributed WITHOUT ANY WARRANTY; without even the
10 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 # See the License for more information.
12 #=============================================================================
13 # (To distribute this file outside of CMake, substitute the full
14 # License text for the above reference.)
16 include(FeatureSummary)
18 # trojita_string_option(option description default depends force [options...])
19 macro(trojita_string_option option description default depends force)
20 if(${option}_ISSET MATCHES "^${option}_ISSET$")
21 set(${option}_AVAILABLE 1)
23 string(REGEX REPLACE " +" ";" CMAKE_DEPENDENT_OPTION_DEP "${d}")
24 if(NOT (${CMAKE_DEPENDENT_OPTION_DEP}))
25 set(${option}_AVAILABLE 0)
26 message(STATUS "Disabling ${option} because of ${CMAKE_DEPENDENT_OPTION_DEP}")
29 if(${option}_AVAILABLE)
30 if(${option} MATCHES "^${option}$")
31 set(${option} "${default}" CACHE STRING "${description}" FORCE)
33 set(${option} "${${option}}" CACHE STRING "${description}" FORCE)
35 set_property(CACHE ${option} PROPERTY STRINGS ${ARGN})
37 if(NOT ${option} MATCHES "^${option}$")
38 set(${option} "${${option}}" CACHE INTERNAL "${description}")
40 set(${option} ${force})
43 set(${option} "${${option}_ISSET}")
47 # trojita_option(option description default [depends])
48 macro(trojita_option option description default)
50 trojita_string_option(${option} "${description}" ${default} "${depends}" OFF AUTO ON OFF)
51 add_feature_info(${option} ${option} "${description}")
54 # trojita_plugin_option(option description [depends] [STATIC])
55 macro(trojita_plugin_option option description)
59 if("${arg}" STREQUAL "STATIC")
62 list(APPEND depends "${arg}")
65 trojita_string_option(${option} "${description}" ${default} "${depends}" OFF AUTO STATIC ON OFF)
66 if(NOT WITH_SHARED_PLUGINS)
67 if("${${option}}" STREQUAL "AUTO")
68 if(NOT ${option} MATCHES "^${option}$")
69 set(${option} "${${option}}" CACHE INTERNAL "${description}")
71 set(${option} "STATIC")
72 elseif(NOT "${${option}}" STREQUAL "STATIC")
73 message(STATUS "Disabling ${option} because of NOT WITH_SHARED_PLUGINS")
74 if("${${option}}" STREQUAL "ON")
75 message(FATAL_ERROR "Plugin ${option} is disabled")
77 if(NOT ${option} MATCHES "^${option}$")
78 set(${option} "${${option}}" CACHE INTERNAL "${description}")
83 add_feature_info(${option} ${option} "${description}")
86 # trojita_add_plugin(target type [sources...])
87 macro(trojita_add_plugin target type)
88 if("${${type}}" STREQUAL "STATIC")
89 message(STATUS "Building static plugin ${target}")
90 add_library(${target} STATIC ${ARGN})
91 set_property(TARGET ${target} APPEND PROPERTY COMPILE_DEFINITIONS QT_STATICPLUGIN)
92 set_property(GLOBAL APPEND PROPERTY TROJITA_STATIC_PLUGINS ${target})
94 message(STATUS "Building shared plugin ${target}")
95 add_library(${target} MODULE ${ARGN})
96 install(TARGETS ${target} DESTINATION ${CMAKE_INSTALL_PLUGIN_DIR})
97 set_property(GLOBAL APPEND PROPERTY TROJITA_SHARED_PLUGINS ${target})
99 set_target_properties(${target} PROPERTIES PREFIX "")
100 set_property(TARGET ${target} APPEND PROPERTY COMPILE_DEFINITIONS BUILD_PLUGIN)
101 target_link_libraries(${target} Plugins)
103 qt5_use_modules(${target} Core)
105 target_link_libraries(${target} ${QT_QTCORE_LIBRARY})
109 # trojita_find_package(package version url description purpose [options...])
110 macro(trojita_find_package package version url description purpose)
113 if("${${arg}}" STREQUAL "ON" OR "${arg}" STREQUAL REQUIRED)
114 message(STATUS "Package ${package} is required because of ${arg}")
118 if ("${type}" STREQUAL REQUIRED)
119 find_package(${package} ${version} REQUIRED)
121 find_package(${package} ${version})
123 set_package_properties(${package} PROPERTIES URL "${url}" DESCRIPTION "${description}" TYPE ${type} PURPOSE "${purpose}")
124 if(NOT ${package}_FOUND)
126 if("${${arg}}" STREQUAL "AUTO")
127 message(STATUS "Disabling ${arg} because package ${package} was not found")
128 if(NOT ${arg} MATCHES "^${arg}$")
129 set(${arg} "${${arg}}" CACHE INTERNAL "")
132 get_property(features GLOBAL PROPERTY ENABLED_FEATURES)
133 list(REMOVE_ITEM features ${arg})
134 set_property(GLOBAL PROPERTY ENABLED_FEATURES "${features}")
135 get_property(features GLOBAL PROPERTY DISABLED_FEATURES)
136 list(FIND features ${arg} id)
138 set_property(GLOBAL APPEND PROPERTY DISABLED_FEATURES "${arg}")