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})
98 set_target_properties(${target} PROPERTIES PREFIX "")
99 set_property(TARGET ${target} APPEND PROPERTY COMPILE_DEFINITIONS BUILD_PLUGIN)
100 target_link_libraries(${target} Plugins)
102 qt5_use_modules(${target} Core)
104 target_link_libraries(${target} ${QT_QTCORE_LIBRARY})
108 # trojita_find_package(package version url description purpose [options...])
109 macro(trojita_find_package package version url description purpose)
112 if("${${arg}}" STREQUAL "ON" OR "${arg}" STREQUAL REQUIRED)
113 message(STATUS "Package ${package} is required because of ${arg}")
117 if ("${type}" STREQUAL REQUIRED)
118 find_package(${package} ${version} REQUIRED)
120 find_package(${package} ${version})
122 set_package_properties(${package} PROPERTIES URL "${url}" DESCRIPTION "${description}" TYPE ${type} PURPOSE "${purpose}")
123 if(NOT ${package}_FOUND)
125 if("${${arg}}" STREQUAL "AUTO")
126 message(STATUS "Disabling ${arg} because package ${package} was not found")
127 if(NOT ${arg} MATCHES "^${arg}$")
128 set(${arg} "${${arg}}" CACHE INTERNAL "")
131 get_property(features GLOBAL PROPERTY ENABLED_FEATURES)
132 list(REMOVE_ITEM features ${arg})
133 set_property(GLOBAL PROPERTY ENABLED_FEATURES "${features}")
134 get_property(features GLOBAL PROPERTY DISABLED_FEATURES)
135 list(FIND features ${arg} id)
137 set_property(GLOBAL APPEND PROPERTY DISABLED_FEATURES "${arg}")
144 # trojita_check_qt4_module(module [options...])
145 macro(trojita_check_qt4_module module)
146 if(NOT QT_${module}_FOUND)
148 if("${${arg}}" STREQUAL "ON" OR "${arg}" STREQUAL REQUIRED)
149 message(STATUS "Qt4 module ${module} is required because of ${arg}")
150 message(FATAL_ERROR "Qt4 module ${module} was not found")
151 elseif("${${arg}}" STREQUAL "AUTO")
152 message(STATUS "Disabling ${arg} because Qt4 module ${module} was not found")
153 if(NOT ${arg} MATCHES "^${arg}$")
154 set(${arg} "${${arg}}" CACHE INTERNAL "")
157 get_property(features GLOBAL PROPERTY ENABLED_FEATURES)
158 list(REMOVE_ITEM features ${arg})
159 set_property(GLOBAL PROPERTY ENABLED_FEATURES "${features}")
160 get_property(features GLOBAL PROPERTY DISABLED_FEATURES)
161 list(FIND features ${arg} id)
163 set_property(GLOBAL APPEND PROPERTY DISABLED_FEATURES "${arg}")