Merge "Enable non-standard SMTP AUTH LOGIN"
[trojita.git] / cmake / TrojitaOption.cmake
blob6e5e0bb3a7c6e7e658a10d7b03c33cd4a1b5ec06
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)
22         foreach(d ${depends})
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}")
27             endif()
28         endforeach()
29         if(${option}_AVAILABLE)
30             if(${option} MATCHES "^${option}$")
31                 set(${option} "${default}" CACHE STRING "${description}" FORCE)
32             else()
33                 set(${option} "${${option}}" CACHE STRING "${description}" FORCE)
34             endif()
35             set_property(CACHE ${option} PROPERTY STRINGS ${ARGN})
36         else()
37             if(NOT ${option} MATCHES "^${option}$")
38                 set(${option} "${${option}}" CACHE INTERNAL "${description}")
39             endif()
40             set(${option} ${force})
41         endif()
42     else()
43         set(${option} "${${option}_ISSET}")
44     endif()
45 endmacro()
47 # trojita_option(option description default [depends])
48 macro(trojita_option option description default)
49     set(depends ${ARGN})
50     trojita_string_option(${option} "${description}" ${default} "${depends}" OFF AUTO ON OFF)
51     add_feature_info(${option} ${option} "${description}")
52 endmacro()
54 # trojita_plugin_option(option description [depends] [STATIC])
55 macro(trojita_plugin_option option description)
56     set(depends)
57     set(default "AUTO")
58     foreach(arg ${ARGN})
59         if("${arg}" STREQUAL "STATIC")
60             set(default "STATIC")
61         else()
62             list(APPEND depends "${arg}")
63         endif()
64     endforeach()
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}")
70             endif()
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")
76             endif()
77             if(NOT ${option} MATCHES "^${option}$")
78                 set(${option} "${${option}}" CACHE INTERNAL "${description}")
79             endif()
80             set(${option} OFF)
81         endif()
82     endif()
83     add_feature_info(${option} ${option} "${description}")
84 endmacro()
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})
93     else()
94         message(STATUS "Building shared plugin ${target}")
95         add_library(${target} MODULE ${ARGN})
96         install(TARGETS ${target} DESTINATION ${CMAKE_INSTALL_PLUGIN_DIR})
97     endif()
98     set_target_properties(${target} PROPERTIES PREFIX "")
99     set_property(TARGET ${target} APPEND PROPERTY COMPILE_DEFINITIONS BUILD_PLUGIN)
100     target_link_libraries(${target} Plugins)
101     if (WITH_QT5)
102         qt5_use_modules(${target} Core)
103     else()
104         target_link_libraries(${target} ${QT_QTCORE_LIBRARY})
105     endif()
106 endmacro()
108 # trojita_find_package(package version url description purpose [options...])
109 macro(trojita_find_package package version url description purpose)
110     set(type OPTIONAL)
111     foreach(arg ${ARGN})
112         if("${${arg}}" STREQUAL "ON" OR "${arg}" STREQUAL REQUIRED)
113             message(STATUS "Package ${package} is required because of ${arg}")
114             set(type REQUIRED)
115         endif()
116     endforeach()
117     if ("${type}" STREQUAL REQUIRED)
118         find_package(${package} ${version} REQUIRED)
119     else()
120         find_package(${package} ${version})
121     endif()
122     set_package_properties(${package} PROPERTIES URL "${url}" DESCRIPTION "${description}" TYPE ${type} PURPOSE "${purpose}")
123     if(NOT ${package}_FOUND)
124         foreach(arg ${ARGN})
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 "")
129                 endif()
130                 set(${arg} OFF)
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)
136                 if(id EQUAL -1)
137                     set_property(GLOBAL APPEND PROPERTY DISABLED_FEATURES "${arg}")
138                 endif()
139             endif()
140         endforeach()
141     endif()
142 endmacro()
144 # trojita_check_qt4_module(module [options...])
145 macro(trojita_check_qt4_module module)
146     if(NOT QT_${module}_FOUND)
147         foreach(arg ${ARGN})
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 "")
155                 endif()
156                 set(${arg} OFF)
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)
162                 if(id EQUAL -1)
163                     set_property(GLOBAL APPEND PROPERTY DISABLED_FEATURES "${arg}")
164                 endif()
165             endif()
166         endforeach()
167     endif()
168 endmacro()