1 # - MACRO_OPTIONAL_ADD_SUBDIRECTORY() combines ADD_SUBDIRECTORY() with an OPTION()
2 # MACRO_OPTIONAL_ADD_SUBDIRECTORY( <dir> )
3 # If you use MACRO_OPTIONAL_ADD_SUBDIRECTORY() instead of ADD_SUBDIRECTORY(),
4 # this will have two effects
5 # 1 - CMake will not complain if the directory doesn't exist
6 # This makes sense if you want to distribute just one of the subdirs
7 # in a source package, e.g. just one of the subdirs in kdeextragear.
8 # 2 - If the directory exists, it will offer an option to skip the
10 # This is useful if you want to compile only a subset of all
13 # If the CMake variable DISABLE_ALL_OPTIONAL_SUBDIRECTORIES is set to TRUE
14 # for the first CMake run on the project, all optional subdirectories will be disabled
15 # by default (but can of course be enabled via the respective options).
16 # E.g. the following will disable all optional subdirectories except the one named "kcalc":
17 # $ cmake -DDISABLE_ALL_OPTIONAL_SUBDIRECTORIES=TRUE -DBUILD_kcalc=TRUE <srcdir>
19 # Copyright (c) 2007, Alexander Neundorf, <neundorf@kde.org>
21 # Redistribution and use is allowed according to the terms of the BSD license.
22 # For details see the accompanying COPYING-CMAKE-SCRIPTS file.
25 MACRO (MACRO_OPTIONAL_ADD_SUBDIRECTORY _dir )
26 GET_FILENAME_COMPONENT(_fullPath ${_dir} ABSOLUTE)
27 IF(EXISTS ${_fullPath})
28 IF(DISABLE_ALL_OPTIONAL_SUBDIRECTORIES)
29 SET(_DEFAULT_OPTION_VALUE FALSE)
30 ELSE(DISABLE_ALL_OPTIONAL_SUBDIRECTORIES)
31 SET(_DEFAULT_OPTION_VALUE TRUE)
32 ENDIF(DISABLE_ALL_OPTIONAL_SUBDIRECTORIES)
33 IF(DISABLE_ALL_OPTIONAL_SUBDIRS AND NOT DEFINED BUILD_${_dir})
34 SET(_DEFAULT_OPTION_VALUE FALSE)
35 ENDIF(DISABLE_ALL_OPTIONAL_SUBDIRS AND NOT DEFINED BUILD_${_dir})
36 OPTION(BUILD_${_dir} "Build directory ${_dir}" ${_DEFAULT_OPTION_VALUE})
38 ADD_SUBDIRECTORY(${_dir})
40 ENDIF(EXISTS ${_fullPath})
41 ENDMACRO (MACRO_OPTIONAL_ADD_SUBDIRECTORY)