My CMake modules, scripts, templates
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MacroOptionalAddSubdirectory.cmake 1.3KB

12345678910111213141516171819202122232425262728293031
  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
  9. # subdirectory.
  10. # This is useful if you want to compile only a subset of all
  11. # directories.
  12. # Copyright (c) 2007, Alexander Neundorf, <neundorf@kde.org>
  13. #
  14. # Redistribution and use is allowed according to the terms of the BSD license.
  15. # For details see the accompanying COPYING-CMAKE-SCRIPTS file.
  16. MACRO (MACRO_OPTIONAL_ADD_SUBDIRECTORY _dir )
  17. GET_FILENAME_COMPONENT(_fullPath ${_dir} ABSOLUTE)
  18. IF(EXISTS ${_fullPath})
  19. IF(${ARGC} EQUAL 2)
  20. OPTION(BUILD_${_dir} "Build directory ${_dir}" ${ARGV1})
  21. ELSE(${ARGC} EQUAL 2)
  22. OPTION(BUILD_${_dir} "Build directory ${_dir}" TRUE)
  23. ENDIF(${ARGC} EQUAL 2)
  24. IF(BUILD_${_dir})
  25. ADD_SUBDIRECTORY(${_dir})
  26. ENDIF(BUILD_${_dir})
  27. ENDIF(EXISTS ${_fullPath})
  28. ENDMACRO (MACRO_OPTIONAL_ADD_SUBDIRECTORY)