MacroOptionalAddSubdirectory.cmake 1.3 KB

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)