Warning, /pim/trojita/cmake/TrojitaOption.cmake is written in an unsupported language. File is not indexed.

0001 # Based on CMakeDependentOption.cmake
0002 #=============================================================================
0003 # Copyright 2006-2009 Kitware, Inc.
0004 # Copyright 2013 Pali Rohár <pali.rohar@gmail.com>
0005 #
0006 # Distributed under the OSI-approved BSD License (the "License");
0007 # see accompanying file Copyright.txt for details.
0008 #
0009 # This software is distributed WITHOUT ANY WARRANTY; without even the
0010 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
0011 # See the License for more information.
0012 #=============================================================================
0013 # (To distribute this file outside of CMake, substitute the full
0014 #  License text for the above reference.)
0015 
0016 include(FeatureSummary)
0017 
0018 # trojita_string_option(option description default depends force [options...])
0019 macro(trojita_string_option option description default depends force)
0020     if(${option}_ISSET MATCHES "^${option}_ISSET$")
0021         set(${option}_AVAILABLE 1)
0022         foreach(d ${depends})
0023             string(REGEX REPLACE " +" ";" CMAKE_DEPENDENT_OPTION_DEP "${d}")
0024             if(NOT (${CMAKE_DEPENDENT_OPTION_DEP}))
0025                 set(${option}_AVAILABLE 0)
0026                 message(STATUS "Disabling ${option} because of ${CMAKE_DEPENDENT_OPTION_DEP}")
0027             endif()
0028         endforeach()
0029         if(${option}_AVAILABLE)
0030             if(${option} MATCHES "^${option}$")
0031                 set(${option} "${default}" CACHE STRING "${description}" FORCE)
0032             else()
0033                 set(${option} "${${option}}" CACHE STRING "${description}" FORCE)
0034             endif()
0035             set_property(CACHE ${option} PROPERTY STRINGS ${ARGN})
0036         else()
0037             if(NOT ${option} MATCHES "^${option}$")
0038                 set(${option} "${${option}}" CACHE INTERNAL "${description}")
0039             endif()
0040             set(${option} ${force})
0041         endif()
0042     else()
0043         set(${option} "${${option}_ISSET}")
0044     endif()
0045 endmacro()
0046 
0047 # trojita_option(option description default [depends])
0048 macro(trojita_option option description default)
0049     set(depends ${ARGN})
0050     trojita_string_option(${option} "${description}" ${default} "${depends}" OFF AUTO ON OFF)
0051     add_feature_info(${option} ${option} "${description}")
0052 endmacro()
0053 
0054 # trojita_plugin_option(option description [depends] [STATIC])
0055 macro(trojita_plugin_option option description)
0056     set(depends)
0057     set(default "AUTO")
0058     foreach(arg ${ARGN})
0059         if("${arg}" STREQUAL "STATIC")
0060             set(default "STATIC")
0061         else()
0062             list(APPEND depends "${arg}")
0063         endif()
0064     endforeach()
0065     trojita_string_option(${option} "${description}" ${default} "${depends}" OFF AUTO STATIC ON OFF)
0066     if(NOT WITH_SHARED_PLUGINS)
0067         if("${${option}}" STREQUAL "AUTO")
0068             if(NOT ${option} MATCHES "^${option}$")
0069                 set(${option} "${${option}}" CACHE INTERNAL "${description}")
0070             endif()
0071             set(${option} "STATIC")
0072         elseif(NOT "${${option}}" STREQUAL "STATIC")
0073             message(STATUS "Disabling ${option} because of NOT WITH_SHARED_PLUGINS")
0074             if("${${option}}" STREQUAL "ON")
0075                 message(FATAL_ERROR "Plugin ${option} is disabled")
0076             endif()
0077             if(NOT ${option} MATCHES "^${option}$")
0078                 set(${option} "${${option}}" CACHE INTERNAL "${description}")
0079             endif()
0080             set(${option} OFF)
0081         endif()
0082     endif()
0083     add_feature_info(${option} ${option} "${description}")
0084 endmacro()
0085 
0086 # trojita_add_plugin(target type [sources...])
0087 macro(trojita_add_plugin target type)
0088     if("${${type}}" STREQUAL "STATIC")
0089         message(STATUS "Building static plugin ${target}")
0090         add_library(${target} STATIC ${ARGN})
0091         set_property(TARGET ${target} APPEND PROPERTY COMPILE_DEFINITIONS QT_STATICPLUGIN)
0092         set_property(GLOBAL APPEND PROPERTY TROJITA_STATIC_PLUGINS ${target})
0093     else()
0094         message(STATUS "Building shared plugin ${target}")
0095         add_library(${target} MODULE ${ARGN})
0096         install(TARGETS ${target} DESTINATION ${CMAKE_INSTALL_PLUGIN_DIR})
0097         set_property(GLOBAL APPEND PROPERTY TROJITA_SHARED_PLUGINS ${target})
0098     endif()
0099     set_target_properties(${target} PROPERTIES PREFIX "")
0100     set_property(TARGET ${target} APPEND PROPERTY COMPILE_DEFINITIONS BUILD_PLUGIN)
0101     target_link_libraries(${target} Plugins)
0102     if (WITH_QT5)
0103         qt5_use_modules(${target} Core)
0104     else()
0105         target_link_libraries(${target} ${QT_QTCORE_LIBRARY})
0106     endif()
0107 endmacro()
0108 
0109 # trojita_find_package(package version url description purpose [options...])
0110 macro(trojita_find_package package version url description purpose)
0111     set(type OPTIONAL)
0112     foreach(arg ${ARGN})
0113         if("${${arg}}" STREQUAL "ON" OR "${arg}" STREQUAL REQUIRED)
0114             message(STATUS "Package ${package} is required because of ${arg}")
0115             set(type REQUIRED)
0116         endif()
0117     endforeach()
0118     if ("${type}" STREQUAL REQUIRED)
0119         find_package(${package} ${version} REQUIRED)
0120     else()
0121         find_package(${package} ${version})
0122     endif()
0123     set_package_properties(${package} PROPERTIES URL "${url}" DESCRIPTION "${description}" TYPE ${type} PURPOSE "${purpose}")
0124     if(NOT ${package}_FOUND)
0125         foreach(arg ${ARGN})
0126             if("${${arg}}" STREQUAL "AUTO")
0127                 message(STATUS "Disabling ${arg} because package ${package} was not found")
0128                 if(NOT ${arg} MATCHES "^${arg}$")
0129                     set(${arg} "${${arg}}" CACHE INTERNAL "")
0130                 endif()
0131                 set(${arg} OFF)
0132                 get_property(features GLOBAL PROPERTY ENABLED_FEATURES)
0133                 list(REMOVE_ITEM features ${arg})
0134                 set_property(GLOBAL PROPERTY ENABLED_FEATURES "${features}")
0135                 get_property(features GLOBAL PROPERTY DISABLED_FEATURES)
0136                 list(FIND features ${arg} id)
0137                 if(id EQUAL -1)
0138                     set_property(GLOBAL APPEND PROPERTY DISABLED_FEATURES "${arg}")
0139                 endif()
0140             endif()
0141         endforeach()
0142     endif()
0143 endmacro()