├── .gitignore ├── CMakeLists.txt ├── LICENSE ├── README.md ├── cmake └── SuperBuild.cmake └── src ├── CMakeLists.txt └── main.cpp /.gitignore: -------------------------------------------------------------------------------- 1 | /build/ 2 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 2.8) 2 | 3 | # Handle superbuild first 4 | option (USE_SUPERBUILD "Whether or not a superbuild should be invoked" ON) 5 | 6 | if (USE_SUPERBUILD) 7 | project (SUPERBUILD NONE) 8 | # execute the superbuild (this script will be invoked again without the 9 | # USE_SUPERBUILD option this time) 10 | include (cmake/SuperBuild.cmake) 11 | return() # stop processing this file further 12 | else() 13 | project (Blah) # <-- YOUR PROJECT NAME HERE 14 | endif() 15 | 16 | # 17 | # 18 | # 19 | 20 | set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) 21 | set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) 22 | set (CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) 23 | 24 | add_subdirectory (src) 25 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Guillaume Papin 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | cmake-superbuild 2 | ================ 3 | 4 | CMake SuperBuild template using External_Projects 5 | 6 | How does it work? 7 | ----------------- 8 | 9 | The top-level CMakeLists.txt works in a has 2 stages: 10 | 11 | 1. `USE_SUPERBUILD=ON` [the default]: Deleguates the generation to 12 | SuperBuild.cmake which will download and build the dependencies and then 13 | re-invoke the top-level CMakeLists.txt but this time with `USE_SUPERBUILD` 14 | set to `OFF`. 15 | 16 | 2. This step, when `USE_SUPERBUILD=OFF`, is the usual CMakeLists of the project, 17 | in a SuperBuild mode this will reside in the subdirectory blah of the 18 | SuperBuild directory. 19 | 20 | 21 | Example using with the default method `USE_SUPERBUILD=ON`: 22 | 23 | $ mkdir super-build && cd super-build 24 | $ cmake .. 25 | $ # assuming the Unix Makefile generator was the default 26 | $ make 27 | 28 | 29 | $ # the project build directory is resides in blah/ 30 | $ cd blah/ 31 | $ pwd 32 | <...>/cmake-superbuild/build/blah 33 | $ ./bin/blah 34 | Hello World! 35 | 36 | Example without the superbuild, the dependencies are taken care in some other 37 | ways: 38 | 39 | $ mkdir build && cd build 40 | $ # assuming a proper version of Boost has been built and resides 41 | $ # in ~/pkg/boost_1_55_0 42 | $ cmake -DUSE_SUPERBUILD=OFF -DBOOST_ROOT=~/pkg/boost_1_55_0 .. 43 | $ make 44 | $ ./bin/blah 45 | Hello World! 46 | -------------------------------------------------------------------------------- /cmake/SuperBuild.cmake: -------------------------------------------------------------------------------- 1 | include (ExternalProject) 2 | 3 | set_property (DIRECTORY PROPERTY EP_BASE Dependencies) 4 | 5 | set (DEPENDENCIES) 6 | set (EXTRA_CMAKE_ARGS) 7 | 8 | # Use static linking to avoid issues with system-wide installations of Boost. 9 | list (APPEND DEPENDENCIES ep_boost) 10 | ExternalProject_Add (ep_boost 11 | URL http://sourceforge.net/projects/boost/files/boost/1.55.0/boost_1_55_0.tar.bz2/download 12 | URL_MD5 d6eef4b4cacb2183f2bf265a5a03a354 13 | CONFIGURE_COMMAND ./bootstrap.sh --with-libraries=atomic,date_time,filesystem,program_options,system,thread 14 | BUILD_COMMAND ./b2 link=static 15 | BUILD_IN_SOURCE 1 16 | INSTALL_COMMAND "" 17 | ) 18 | list (APPEND EXTRA_CMAKE_ARGS 19 | -DBOOST_ROOT=${CMAKE_CURRENT_BINARY_DIR}/Dependencies/Source/ep_boost 20 | -DBoost_NO_SYSTEM_PATHS=ON) 21 | 22 | # FIXME add to default target "all"? 23 | ExternalProject_Add (ep_blah 24 | DEPENDS ${DEPENDENCIES} 25 | SOURCE_DIR ${PROJECT_SOURCE_DIR} 26 | CMAKE_ARGS -DUSE_SUPERBUILD=OFF ${EXTRA_CMAKE_ARGS} 27 | INSTALL_COMMAND "" 28 | BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/blah) 29 | -------------------------------------------------------------------------------- /src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | find_package (Threads REQUIRED) 2 | 3 | set (Boost_USE_STATIC_LIBS ON) 4 | # set (Boost_NO_SYSTEM_PATHS ON) 5 | find_package (Boost 1.55.0 REQUIRED COMPONENTS date_time filesystem system) 6 | 7 | include_directories (${Boost_INCLUDE_DIRS}) 8 | 9 | add_executable (blah 10 | main.cpp) 11 | 12 | target_link_libraries (blah 13 | ${Boost_LIBRARIES} 14 | ${CMAKE_THREAD_LIBS_INIT}) 15 | -------------------------------------------------------------------------------- /src/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | // New in Boost 1.55 6 | boost::any foo = 42; 7 | foo.clear(); 8 | 9 | std::cout << "Hello world!" << std::endl; 10 | return 0; 11 | } 12 | --------------------------------------------------------------------------------