Warning, /frameworks/extra-cmake-modules/modules/ECMOptionalAddSubdirectory.cmake is written in an unsupported language. File is not indexed.

0001 # SPDX-FileCopyrightText: 2007 Alexander Neundorf <neundorf@kde.org>
0002 #
0003 # SPDX-License-Identifier: BSD-3-Clause
0004 
0005 #[=======================================================================[.rst:
0006 ECMOptionalAddSubdirectory
0007 --------------------------
0008 
0009 Make subdirectories optional.
0010 
0011 ::
0012 
0013   ecm_optional_add_subdirectory(<dir>)
0014 
0015 This behaves like ``add_subdirectory()``, except that it does not complain if the
0016 directory does not exist.  Additionally, if the directory does exist, it
0017 creates an option to allow the user to skip it. The option will be named
0018 BUILD_<dir>.
0019 
0020 This is useful for "meta-projects" that combine several mostly-independent
0021 sub-projects.
0022 
0023 If the CMake variable ``DISABLE_ALL_OPTIONAL_SUBDIRECTORIES`` is set to ``TRUE`` for
0024 the first CMake run on the project, all optional subdirectories will be
0025 disabled by default (but can of course be enabled via the respective options).
0026 For example, the following will disable all optional subdirectories except the
0027 one named "foo":
0028 
0029 .. code-block:: sh
0030 
0031   cmake -DDISABLE_ALL_OPTIONAL_SUBDIRECTORIES=TRUE -DBUILD_foo=TRUE myproject
0032 
0033 Since pre-1.0.0.
0034 #]=======================================================================]
0035 
0036 function(ECM_OPTIONAL_ADD_SUBDIRECTORY _dir)
0037   get_filename_component(_fullPath ${_dir} ABSOLUTE)
0038   if(EXISTS ${_fullPath}/CMakeLists.txt)
0039     if(DISABLE_ALL_OPTIONAL_SUBDIRECTORIES)
0040       set(_DEFAULT_OPTION_VALUE FALSE)
0041     else()
0042       set(_DEFAULT_OPTION_VALUE TRUE)
0043     endif()
0044     if(DISABLE_ALL_OPTIONAL_SUBDIRS  AND NOT DEFINED  BUILD_${_dir})
0045       set(_DEFAULT_OPTION_VALUE FALSE)
0046     endif()
0047     option(BUILD_${_dir} "Build directory ${_dir}" ${_DEFAULT_OPTION_VALUE})
0048     if(BUILD_${_dir})
0049       add_subdirectory(${_dir})
0050     endif()
0051   endif()
0052 endfunction()