From f862009841bffaee85d6d82074ee707054ca90ae Mon Sep 17 00:00:00 2001 From: Mike-Devel Date: Wed, 2 Jan 2019 14:26:48 +0100 Subject: [PATCH] [CMake] Generate cmake target that other libraries can use (#86) Generates cmake target that other libraries can use to express their dependency on this library and retrieve any configuration information such as the include directory. --- .travis.yml | 18 ++++++++++++++++++ CMakeLists.txt | 26 ++++++++++++++++++++++++++ test/test_cmake/CMakeLists.txt | 21 +++++++++++++++++++++ test/test_cmake/main.cpp | 7 +++++++ 4 files changed, 72 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 test/test_cmake/CMakeLists.txt create mode 100644 test/test_cmake/main.cpp diff --git a/.travis.yml b/.travis.yml index 65d7f7c..de16d11 100644 --- a/.travis.yml +++ b/.travis.yml @@ -48,6 +48,24 @@ matrix: exclude: - env: TRAVIS_EMPTY_JOB_WORKAROUND=true include: + # cmake self-test + - env: TEST_CMAKE=TRUE #Only for easier identification in travis web gui + os: linux + + # skip all the unneeded steps from the normal unit test jobs + install: true + before_script: true + before_cache: true + before_cache: true + after_success: true + after_failure: true + after_script: true + script: + - mkdir __build__ && cd __build__ + - cmake ../test/test_cmake + - cmake --build . + + - env: TOOLSET=clang-3.4 - env: TOOLSET=clang-3.5 - env: TOOLSET=clang-3.6 diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..1714a43 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,26 @@ +# Copyright 2018 Mike Dev +# Distributed under the Boost Software License, Version 1.0. +# See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt +# +# NOTE: CMake support for Boost.Predef is currently experimental at best +# and the interface is likely to change in the future +# +# This file provides mininmal cmake support (no unit-tests, +# no installation) for integration into a "host" cmake project +# via the "add_subdirectory( )" command. +# +# Other cmake targets can then use the public target name +# "Boost::predef" in order to express their dependency +# on this library. I.e: +# +# target_link_libraries( PUBLIC Boost::predef ) +# + +cmake_minimum_required( VERSION 3.5 ) +project( BoostPredef ) + +add_library( boost_predef INTERFACE ) +target_include_directories( boost_predef INTERFACE include ) + +add_library( Boost::predef ALIAS boost_predef ) + diff --git a/test/test_cmake/CMakeLists.txt b/test/test_cmake/CMakeLists.txt new file mode 100644 index 0000000..b2cd0b5 --- /dev/null +++ b/test/test_cmake/CMakeLists.txt @@ -0,0 +1,21 @@ +# Copyright 2018 Mike Dev +# Distributed under the Boost Software License, Version 1.0. +# See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt +# +# NOTE: This does NOT run the unit tests for Boost.Predef. +# It only tests, if the CMakeLists.txt file in predef's +# root directory works as expected (i.e. it provides the +# target Boost::predef which in turn provides the +# correct include directory ) + +cmake_minimum_required( VERSION 3.5 ) + +project( BoostPredefCMakeSelfTest ) + +# Process cmake file at root of library and use ${CMAKE_CURRENT_BINARY_DIR}/libs/boost_predef as workspace +add_subdirectory( ../.. ${CMAKE_CURRENT_BINARY_DIR}/libs/boost_predef ) + +add_executable( boost_predef_cmake_test_prj main.cpp ) + +target_link_libraries( boost_predef_cmake_test_prj Boost::predef ) + diff --git a/test/test_cmake/main.cpp b/test/test_cmake/main.cpp new file mode 100644 index 0000000..4507ab7 --- /dev/null +++ b/test/test_cmake/main.cpp @@ -0,0 +1,7 @@ +// Dummy executable, just to make sure +// that we can find the Boost.predef header files +#include + +int main() { + +}