|
| 1 | +# Based on Ryan M. Richard work in PSI4 |
| 2 | +# First of all get BOOSTVER underscore separated |
| 3 | +string(REGEX REPLACE "\\." "_" BOOSTVER ${BOOSTVER}) |
| 4 | +# Unpack Boost |
| 5 | +add_custom_command( |
| 6 | + OUTPUT boost.unpacked |
| 7 | + COMMAND tar -xzf ${PROJECT_SOURCE_DIR}/external/boost_${BOOSTVER}.tar.gz |
| 8 | + WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/external |
| 9 | + COMMENT "Unpacking Boost" |
| 10 | + DEPENDS ${PROJECT_SOURCE_DIR}/external/boost_${BOOSTVER}.tar.gz) |
| 11 | + |
| 12 | +# We are going to build only what is necessary. We need to create a custom user-config.jam file |
| 13 | +# To get boost to compile MPI we need to append "using mpi ;" to the end of the |
| 14 | +# user-config.jam file. MPI_SENT will be the command we append |
| 15 | +set(MPI_SENT "") |
| 16 | +if(ENABLE_MPI) |
| 17 | + #set(BOOST_LIBS_2_MAKE "chrono,filesystem,mpi,python,serialization,system,timer,thread") # This is in PSI4 (w/o chrono and timer) |
| 18 | + set(BOOST_LIBS_2_MAKE "chrono,filesystem,mpi,python,system,timer") |
| 19 | + set(MPI_SENT "using mpi : ${CMAKE_CXX_COMPILER} \\;") |
| 20 | +else() |
| 21 | + #set(BOOST_LIBS_2_MAKE "chrono,filesystem,python,serialization,system,timer,thread") # This is in PSI4 (w/o chrono and timer) |
| 22 | + set(BOOST_LIBS_2_MAKE "chrono,filesystem,python,system,timer") |
| 23 | +endif() |
| 24 | +if(ENABLE_TESTS) |
| 25 | + set(BOOST_LIBS_2_MAKE "${BOOST_LIBS_2_MAKE},test") |
| 26 | +endif() |
| 27 | +message(STATUS " Libraries to be built: ${BOOST_LIBS_2_MAKE}") |
| 28 | + |
| 29 | +# To get boost to be built with our compiler of choice we need these logic |
| 30 | +# statements, then we write the options to user-config.jam |
| 31 | +set(toolset "") |
| 32 | +set(cxxflags "") |
| 33 | +if(CMAKE_CXX_COMPILER_ID MATCHES Intel) |
| 34 | + if(UNIX OR APPLE) |
| 35 | + set(toolset "intel-linux") |
| 36 | + else() |
| 37 | + set(toolset "intel-windows") |
| 38 | + endif() |
| 39 | +elseif(CMAKE_CXX_COMPILER_ID MATCHES Clang) |
| 40 | + set(toolset "clang") |
| 41 | +else() |
| 42 | + if(APPLE) |
| 43 | + set(toolset "darwin") |
| 44 | + else() |
| 45 | + set(toolset "gcc") |
| 46 | + endif() |
| 47 | +endif() |
| 48 | +if(HAS_CXX11_SUPPORT) |
| 49 | + set(cxxflags "${cxxflags} ${CXX11_COMPILER_FLAGS}") |
| 50 | +endif() |
| 51 | +message(STATUS " Toolset to be used: ${toolset}") |
| 52 | + |
| 53 | +# Write the user-config.jam file |
| 54 | +file(WRITE ${PROJECT_BINARY_DIR}/external/boost_${BOOSTVER}/user-config.jam "using ${toolset} : : ${CMAKE_CXX_COMPILER} \\;") |
| 55 | +file(APPEND ${PROJECT_BINARY_DIR}/external/boost_${BOOSTVER}/user-config.jam "${MPI_SENT}") |
| 56 | + |
| 57 | +# Run bootstrap.sh to configure the build. We will install in ${PROJECT_BINARY_DIR}/external/boost |
| 58 | +add_custom_command( |
| 59 | + OUTPUT boost.configured |
| 60 | + COMMAND ./bootstrap.sh --with-toolset=${toolset} |
| 61 | + --with-libraries=${BOOST_LIBS_2_MAKE} |
| 62 | + --with-python=${PYTHON_EXECUTABLE} |
| 63 | + --prefix=${PROJECT_BINARY_DIR}/external/boost 1> boost.configured.log 2> boost.configured.err |
| 64 | + COMMAND touch boost.configured |
| 65 | + WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/external/boost_${BOOSTVER} |
| 66 | + DEPENDS boost.unpacked |
| 67 | + COMMENT "Configuring Boost") |
| 68 | + |
| 69 | +# Append the MPI-related stuff to the project-config.jam file |
| 70 | +file(APPEND ${PROJECT_BINARY_DIR}/external/boost_${BOOSTVER}/project-config.jam "${MPI_SENT}") |
| 71 | + |
| 72 | +# Build Boost |
| 73 | +add_custom_command( |
| 74 | + OUTPUT boost.built |
| 75 | + COMMAND ./b2 1> boost.built.log 2> boost.built.err |
| 76 | + COMMAND touch boost.built |
| 77 | + WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/external/boost_${BOOSTVER} |
| 78 | + DEPENDS boost.configured |
| 79 | + COMMENT "Building Boost") |
| 80 | + |
| 81 | +# Install Boost |
| 82 | +add_custom_command( |
| 83 | + OUTPUT boost.installed |
| 84 | + COMMAND ./b2 install 1> boost.installed.log 2> boost.installed.err |
| 85 | + COMMAND touch boost.installed |
| 86 | + WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/external/boost_${BOOSTVER} |
| 87 | + DEPENDS boost.built |
| 88 | + COMMENT "Installing Boost") |
| 89 | + |
| 90 | +add_custom_target(custom_boost ALL DEPENDS boost.installed) |
| 91 | + |
| 92 | +# Set variables usually set by find_package by hand |
| 93 | +set(Boost_FOUND TRUE) |
| 94 | +set(Boost_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/external/boost/include) |
| 95 | +set(Boost_LIBRARY_DIRS ${PROJECT_BINARY_DIR}/external/boost/lib) |
| 96 | +# We will link statically, so just set the Boost_<C>_LIBRARY for the static library |
| 97 | +set(Boost_CHRONO_LIBRARY ${PROJECT_BINARY_DIR}/external/boost/lib/libboost_chrono.a) |
| 98 | +set(Boost_FILESYSTEM_LIBRARY ${PROJECT_BINARY_DIR}/external/boost/lib/libboost_filesystem.a) |
| 99 | +set(Boost_PYTHON_LIBRARY ${PROJECT_BINARY_DIR}/external/boost/lib/libboost_python.a) |
| 100 | +set(Boost_SYSTEM_LIBRARY ${PROJECT_BINARY_DIR}/external/boost/lib/libboost_system.a) |
| 101 | +set(Boost_TIMER_LIBRARY ${PROJECT_BINARY_DIR}/external/boost/lib/libboost_timer.a) |
| 102 | +if(ENABLE_TESTS) |
| 103 | + set(Boost_UNIT_TEST_FRAMEWORK_LIBRARY ${PROJECT_BINARY_DIR}/external/boost/lib/libboost_unit_test_framework.a) |
| 104 | +endif() |
0 commit comments