-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
115 lines (100 loc) · 4.28 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#
# Cmake boost compilation script
# (C) A. Antipov, 2014
#
cmake_minimum_required (VERSION 2.8)
# define Boost_ROOT_DIR - path to Boost sources
if (NOT DEFINED Boost_ROOT_DIR)
message(FATAL_ERROR "Boost_ROOT_DIR unset. Please set Boost_ROOT_DIR to the location of boost sources")
else()
message(STATUS "Compiling boost from ${Boost_ROOT_DIR}.")
endif()
# compile using c++ compiler only
project(boost-cmake CXX)
# add modules from cmake directory
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
# add common macros
include(CommonMacros)
# get the list of boost libraries by checking existence of lib/#/src subdirectory
getsubdirs(boost_libdirs ${Boost_ROOT_DIR}/libs)
foreach(boost_dir ${boost_libdirs})
if (EXISTS ${Boost_ROOT_DIR}/libs/${boost_dir}/src)
list(APPEND boost_all_libs ${boost_dir})
endif()
endforeach()
# hacks // FIXME
list(REMOVE_ITEM boost_all_libs smart_ptr thread graph math random)
#list(REMOVE_ITEM boost_all_libs config detail mpl preprocessor tuple utility type_traits iterator)
# if no components required - build everything from boost_standard_components (somewhat biased list)
list(APPEND boost_standard_components date_time chrono filesystem mpi system serialization regex program_options exception atomic)
list(LENGTH Boost_COMPONENTS comp_len)
if (${comp_len} EQUAL 0)
set(Boost_COMPONENTS ${boost_standard_components})
endif()
# check for MPI
list(FIND Boost_COMPONENTS mpi has_no_mpi)
if (NOT ${has_no_mpi} EQUAL -1) # e.g. if we have mpi component
set(BOOST_HAS_MPI true)
find_package(MPI REQUIRED)
add_definitions(${MPI_CXX_COMPILE_FLAGS} ${MPI_C_COMPILE_FLAGS})
include_directories(${MPI_CXX_INCLUDE_PATH})
link_libraries(${MPI_CXX_LIBRARIES})
else()
list(APPEND boost_lib_glob_exclude mpi)
set(BOOST_HAS_MPI false)
endif()
# check for Python
list(FIND Boost_COMPONENTS python has_python)
if (NOT ${has_python} EQUAL -1) # e.g. if we have python component
set(BOOST_HAS_PYTHON true)
find_package(PythonLibs REQUIRED)
message(STATUS "Python includes: ${PYTHON_INCLUDE_DIRS}")
include_directories(${PYTHON_INCLUDE_DIRS})
link_libraries(${PYTHON_LIBRARIES})
else()
list(APPEND boost_lib_glob_exclude python)
set(BOOST_HAS_PYTHON false)
endif()
# include headers from "boost" subdirectory
include_directories(${Boost_ROOT_DIR})
# build boost libraries and install them along with corresponding headers
foreach(boost_lib ${Boost_COMPONENTS})
list(FIND boost_all_libs ${boost_lib} has_boost_lib)
# check if such component exists
if (${has_boost_lib} EQUAL -1)
message(FATAL_ERROR "Boost : Unknown lib ${boost_lib}")
else()
message(STATUS "Building ${boost_lib}")
set (boost_lib_dir ${Boost_ROOT_DIR}/libs/${boost_lib}/src)
file(GLOB_RECURSE SOURCES "${boost_lib_dir}/*.cpp")
# filter out python if not defined
if (NOT BOOST_HAS_PYTHON AND ${boost_lib} STREQUAL mpi)
filterlist("${SOURCES}" python filtered)
set(SOURCES ${filtered})
endif()
# filter out mpi if not defined
if (NOT BOOST_HAS_MPI)
filterlist("${SOURCES}" mpi filtered)
set(${SOURCES} ${filtered})
endif()
# compile component
add_library(boost_${boost_lib} STATIC ${SOURCES})
set_target_properties(boost_${boost_lib} PROPERTIES POSITION_INDEPENDENT_CODE ON)
# install component
install(TARGETS boost_${boost_lib} DESTINATION lib)
# install corresponding headers
install(DIRECTORY ${Boost_ROOT_DIR}/boost/${boost_lib} DESTINATION include/boost FILES_MATCHING PATTERN "*.hpp" PATTERN "*.ipp" PATTERN "*.h")
endif (${has_boost_lib} EQUAL -1)
endforeach(boost_lib ${Boost_COMPONENTS})
# install header-only parts (exclude already installed component headers)
foreach(boost_lib ${boost_all_libs})
list(APPEND all_header_excludes ${all_headers_excludes} PATTERN ${boost_lib} EXCLUDE)
endforeach(boost_lib ${boost_all_libs})
install(
DIRECTORY ${Boost_ROOT_DIR}/boost
DESTINATION include
FILES_MATCHING PATTERN "*.hpp" PATTERN "*.ipp" PATTERN "*.h"
${all_header_excludes} # exclude everything from exclude
)
### Additional installation files
configure_file("${CMAKE_SOURCE_DIR}/misc/boost_cmake.lmod.in" "${CMAKE_BINARY_DIR}/boost_cmake.lmod")