Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2021-05-28 12:18:32


Mateusz Loskot wrote:
> Is there any list of requirements for hand-rolled CMakeLists.txt to make them
> correct for the Boost CMake?

Not yet, but I do intend to write that document.

> I maintain custom, developer-oriented and likely broken CML for GIL, and I
> don't feel comfortable sabotaging your Boost-wide CMake'ification efforts,
> but I haven't got a chance to figure all those requirements and how to fix my
> CML.

The easiest way to make a CML compatible with the Boost CMake infrastructure
is to start with the output of `boostdep --cmake gil`, in this case

```
# Generated by `boostdep --cmake gil`
# Copyright 2020 Peter Dimov
# Distributed under the Boost Software License, Version 1.0.
# https://www.boost.org/LICENSE_1_0.txt

cmake_minimum_required(VERSION 3.5...3.16)

project(boost_gil VERSION "${BOOST_SUPERPROJECT_VERSION}" LANGUAGES CXX)

add_library(boost_gil INTERFACE)
add_library(Boost::gil ALIAS boost_gil)

target_include_directories(boost_gil INTERFACE include)

target_link_libraries(boost_gil
  INTERFACE
    Boost::assert
    Boost::concept_check
    Boost::config
    Boost::container_hash
    Boost::core
    Boost::filesystem
    Boost::integer
    Boost::iterator
    Boost::mp11
    Boost::preprocessor
    Boost::type_traits
    Boost::variant2
)

if(BUILD_TESTING AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/test/CMakeLists.txt")

  add_subdirectory(test)

endif()
```

and then make sure that everything else you add is conditioned on either

if(NOT BOOST_SUPERPROJECT_VERSION)

(which means outside the Boost superproject, but you can still in principle be a subproject
in a user master project, consumed via add_subdirectory or FetchContent), or

if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)

which means you're the root project. I think that everything in your existing CML is only
intended to apply in this case.

You can omit the last three lines if you don't intend to integrate your tests in the Boost-wide
CMake testing.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk