Backport lots of new features from the 1.41.0 branch.
[boost:cmake.git] / libs / CMakeLists.txt
1 #
2 # Copyright Troy D. Straszheim
3 #
4 # Distributed under the Boost Software License, Version 1.0.
5 # See http://www.boost.org/LICENSE_1_0.txt
6 #
7 # Find each subdirectory containing a CMakeLists.txt file, and include
8 # it. This avoids the need to manually list which libraries in Boost
9 # have CMakeLists.txt files.
10
11 # return a list of directories that we should add_subdirectory()
12 macro(BOOST_COLLECT_SUBPROJECT_DIRECTORY_NAMES dirname varname filename)
13   file(GLOB globbed RELATIVE "${dirname}" "${dirname}/*/${filename}")
14   foreach(file ${globbed})
15     get_filename_component(dir ${file} PATH)
16     set(${varname} ${${varname}} ${dir})
17   endforeach()
18 endmacro()
19
20 # Find all of the subdirectories with .cmake files in them. These are
21 # the libraries with dependencies.
22 boost_collect_subproject_directory_names(${BOOST_LIBS_PARENT_DIR} BOOST_MODULE_DIRS "module.cmake")
23 foreach(subdir ${BOOST_MODULE_DIRS})
24   include("${BOOST_LIBS_PARENT_DIR}/${subdir}/module.cmake")
25 endforeach(subdir)
26
27 # Find all of the subdirectories with CMakeLists.txt files in
28 # them. This contains all of the Boost libraries.
29 boost_collect_subproject_directory_names(${BOOST_LIBS_PARENT_DIR} BOOST_SUBPROJECT_DIRS "CMakeLists.txt")
30
31 # Add all of the Boost projects in reverse topological order, so that
32 # a library's dependencies show up before the library itself.
33 set(CPACK_INSTALL_CMAKE_COMPONENTS_ALL)
34 list(SORT BOOST_SUBPROJECT_DIRS)
35 topological_sort(BOOST_SUBPROJECT_DIRS BOOST_ _DEPENDS)
36
37 #
38 # Sanity-check for typos: all projects in BUILD_PROJECTS must exist
39 #
40 if (NOT BUILD_PROJECTS STREQUAL "ALL")
41   foreach(project ${BUILD_PROJECTS})
42     list(FIND BOOST_SUBPROJECT_DIRS ${project} THIS_SUBPROJECT_DIRS_INDEX)
43     if (THIS_SUBPROJECT_DIRS_INDEX LESS 0)
44       message(FATAL_ERROR "Nonexistant project \"${project}\" specified in BUILD_PROJECTS")
45     endif()
46   endforeach()
47 endif()
48
49 #
50 # include only directories of projects in BUILD_PROJECTS
51 #
52 message(STATUS "")
53 message(STATUS "Reading boost project directories...")
54 message(STATUS "")
55 foreach(subdir ${BOOST_SUBPROJECT_DIRS})
56   list(FIND BUILD_PROJECTS ${subdir} THIS_BUILD_PROJECTS_INDEX)
57   if ((THIS_BUILD_PROJECTS_INDEX GREATER -1) OR (BUILD_PROJECTS STREQUAL "ALL"))
58     message(STATUS "+ ${subdir}")
59     add_subdirectory(${BOOST_LIBS_PARENT_DIR}/${subdir} ${CMAKE_BINARY_DIR}/libs/${subdir})
60   endif()
61 endforeach()
62
63 # Write out a GraphViz file containing inter-library dependencies. 
64 set(BOOST_DEPENDENCY_GRAPHVIZ_FILE "${Boost_BINARY_DIR}/dependencies.dot")
65 file(WRITE ${BOOST_DEPENDENCY_GRAPHVIZ_FILE} "digraph boost {\n")
66 foreach(SUBDIR ${BOOST_SUBPROJECT_DIRS})
67   string(TOUPPER "BOOST_${SUBDIR}_COMPILED_LIB" BOOST_COMPILED_LIB_VAR)
68   if (${BOOST_COMPILED_LIB_VAR})
69     file(APPEND ${BOOST_DEPENDENCY_GRAPHVIZ_FILE} "  \"${SUBDIR}\" [style=\"filled\" fillcolor=\"#A3A27C\" shape=\"box\"];\n ")
70   endif (${BOOST_COMPILED_LIB_VAR})
71   string(TOUPPER "BOOST_${SUBDIR}_DEPENDS" DEPENDS_VAR)
72   if(DEFINED ${DEPENDS_VAR})
73     foreach(DEP ${${DEPENDS_VAR}})
74       file(APPEND ${BOOST_DEPENDENCY_GRAPHVIZ_FILE} 
75         "  \"${SUBDIR}\" -> \"${DEP}\";\n")
76     endforeach()
77   endif()
78 endforeach()
79 file(APPEND ${BOOST_DEPENDENCY_GRAPHVIZ_FILE} "  \"test\" [style=\"filled\" fillcolor=\"#A3A27C\" shape=\"box\"];\n ")
80 file(APPEND ${BOOST_DEPENDENCY_GRAPHVIZ_FILE} "}\n")