cpm-cmake / CPM.cmake

📦 CMake's missing package manager. A small CMake script for setup-free, cross-platform, reproducible dependency management.
MIT License
3.03k stars 188 forks source link

Boost modular issues #251

Closed opelx closed 3 years ago

opelx commented 3 years ago

Hi,

I try to import boost spirit modular package. Boost Spirit is a header only library and I don't want to build the tests.

Three attempts using CPM.cmake fail:

Using short form:

    ---- 8< ----
    if(DEVELOPER_EXTERNAL_BOOST_SPIRIT)
        CPMAddPackage("gh:boostorg/spirit#boost-1.76.0@1.76.0")
    endif()

    if(boost_spirit_ADDED)
        add_custom_target(boost-spirit-x3)
        set(EXTERNAL_BOOST_SPIRIT_INCLUDE ${boost_spirit_SOURCE_DIR}/include)
    endif()
    message("EXTERNAL_BOOST_SPIRIT_INCLUDE = ${EXTERNAL_BOOST_SPIRIT_INCLUDE}")
    ---- >8 ----

completes, but doesn't set _ADDED

    $ cmake .
    ...
    -- CPM: adding package spirit@1.76.0 (boost-1.76.0)                         
    EXTERNAL_BOOST_SPIRIT_INCLUDE =
    ...

CMakeCache contains only:

    boost_spirit_BINARY_DIR:STATIC=D:/My/...
    boost_spirit_SOURCE_DIR:STATIC=D:/My/...

Next approach:

    ---- 8< ----
    if(DEVELOPER_EXTERNAL_BOOST_SPIRIT)
        CPMAddPackage(
            #NAME external-boost-spirit
            GITHUB_REPOSITORY "boostorg/spirit"
            VERSION "#boost-1.76.0@1.76.0"
        )
    endif()
    ---- >8 ----

run into errors:

    $ cmake .
    ...
    -- CPM: adding package spirit@#boost-1.76.0@1.76.0 (v#boost-1.76.0@1.76.0)
    [0/7] Performing update step for 'spirit-populate'
    fatal: ambiguous argument 'v#boost-1.76.0@1.76.0': unknown revision or path not in the working tree.
    Use '--' to separate paths from revisions, like this:
    'git <command> [<revision>...] -- [<file>...]'
    error: pathspec 'v#boost-1.76.0@1.76.0' did not match any file(s) known to git
    CMake Error at D:/My/<project>/build/_deps/spirit-subbuild/spirit-populate-prefix/tmp/spirit-populate-gitupdate.cmake:201 (message):
      Failed to checkout tag: 'v#boost-1.76.0@1.76.0'

    FAILED: spirit-populate-prefix/src/spirit-populate-stamp/spirit-populate-update
    cmd.exe /C "cd /D D:\My\<project>\build\_deps\spirit-src && "C:\Program Files\CMake\bin\cmake.exe" -P D:/My/<project>/build/_deps/spirit-subbuild/spirit-populate-prefix/tmp/spirit-populate-gitupdate.cmake"
    ninja: build stopped: subcommand failed.

    CMake Error at C:/Program Files/CMake/share/cmake-3.19/Modules/FetchContent.cmake:989 (message):
      Build step for spirit failed: 1
    Call Stack (most recent call first):
      C:/Program Files/CMake/share/cmake-3.19/Modules/FetchContent.cmake:1118:EVAL:2 (__FetchContent_directPopulate)
      C:/Program Files/CMake/share/cmake-3.19/Modules/FetchContent.cmake:1118 (cmake_language)
      cmake/module/CPM.cmake:753 (FetchContent_Populate)
      cmake/module/CPM.cmake:581 (cpm_fetch_package)
      cmake/options_developer.cmake:279 (CPMAddPackage)
      CMakeLists.txt:38 (include)
    ...

using with 'name':

    ---- 8< ----
    if(DEVELOPER_EXTERNAL_BOOST_SPIRIT)
        CPMAddPackage(
            NAME external-boost-spirit
            GITHUB_REPOSITORY "boostorg/spirit"
            VERSION "#boost-1.76.0@1.76.0"
        )
    endif()
    ---- >8 ----

again with errors:

    $ cmake .
    ...
    -- CPM: adding package external-boost-spirit@#boost-1.76.0@1.76.0 (v#boost-1.76.0@1.76.0)                                                                                                                                     
    [1/9] Creating directories for 'external-boost-spirit-populate'                                                                                                                                                               ...
    [1/9] Performing download step (git clone) for 'external-boost-spirit-populate'                                                                                                                                               
    Cloning into 'external-boost-spirit-src'...                                                                                                                                                                                   
    error: pathspec 'v' did not match any file(s) known to git                                                                                                                                                                    
    CMake Error at external-boost-spirit-subbuild/external-boost-spirit-populate-prefix/tmp/external-boost-spirit-populate-gitclone.cmake:40 (message):                                                                           
      Failed to checkout tag: 'v#boost-1.76.0@1.76.0'                                                                                                                                                                             

    FAILED: external-boost-spirit-populate-prefix/src/external-boost-spirit-populate-stamp/external-boost-spirit-populate-download                                                                                                
    cmd.exe /C "cd /D D:\My\<project>\build\_deps && "C:\Program Files\CMake\bin\cmake.exe" -P D:/My/<project>/build/_deps/external-boost-spirit-subbuild/external-boost-spirit-populate-prefix/tmp/external-boost-spirit-populate-gitclone.cmake && "C:\Program Files\CMake\bin\cmake.exe" -E touch D:/My/<project>/build/_deps/external-boost-spirit-subbuild/external-boost-spirit-populate-prefix/src/external-boost-spirit-populate-stamp/external-boost-spirit-populate-download"                                                                                                                                                                                                       
    ninja: build stopped: subcommand failed.                                                                                                                                                                                      

    CMake Error at C:/Program Files/CMake/share/cmake-3.19/Modules/FetchContent.cmake:989 (message):                                                                                                                              
      Build step for external-boost-spirit failed: 1                                                                                                                                                                              
    Call Stack (most recent call first):                                                                                                                                                                                          
      C:/Program Files/CMake/share/cmake-3.19/Modules/FetchContent.cmake:1118:EVAL:2 (__FetchContent_directPopulate)                                                                                                              
      C:/Program Files/CMake/share/cmake-3.19/Modules/FetchContent.cmake:1118 (cmake_language)                                                                                                                                    
      cmake/module/CPM.cmake:753 (FetchContent_Populate)                                                                                                                                                                          
      cmake/module/CPM.cmake:581 (cpm_fetch_package)                                                                                                                                                                              
      cmake/options_developer.cmake:279 (CPMAddPackage)                                                                                                                                                                           
      CMakeLists.txt:38 (include)                                                                                                                                                                                                 

    -- Configuring incomplete, errors occurred!       

The suggested "gh:Orphis/boost-cmake" repos doesn't seem to get update for 3 years and sticks with boost 1.67.0.

So, how to cope with those modules? CPM is from today's master.

Andres6936 commented 3 years ago
I have tested the code and it works.

....

CPMAddPackage(
        NAME SPIRIT
        GITHUB_REPOSITORY boostorg/spirit
        GIT_TAG boost-1.76.0
        OPTIONS
          "BUILD_TESTING OFF"
)

...
opelx commented 3 years ago

Thank you for your fast answer. This gave me the hint into the right direction. The CMake relevant part is:

option(DEVELOPER_EXTERNAL_BOOST_SPIRIT "boost.spirit" ON)
mark_as_advanced(DEVELOPER_EXTERNAL_BOOST_SPIRIT)

if(DEVELOPER_EXTERNAL_BOOST_SPIRIT)
    CPMAddPackage(
            NAME external-boost-spirit
            GITHUB_REPOSITORY boostorg/spirit
            GIT_TAG boost-1.76.0
            OPTIONS "BUILD_TESTING OFF"
    )
    message(STATUS "boost_spirit_ADDED = ${boost_spirit_ADDED}")
    if(boost_spirit_SOURCE_DIR)
        add_custom_target(external-boost-spirit)
        set(EXTERNAL_BOOST_SPIRIT_INCLUDE_DIR ${boost_spirit_SOURCE_DIR}/include)
    else()
        message(FATAL_ERROR "Failure in external Boost's optional module 'Spirit'")
    endif()
    message(STATUS "EXTERNAL_BOOST_SPIRIT_INCLUDE_DIR = ${EXTERNAL_BOOST_SPIRIT_INCLUDE_DIR}")
endif()

option(DEVELOPER_EXTERNAL_BOOST_TEST "boost.test" ON)
mark_as_advanced(DEVELOPER_EXTERNAL_BOOST_TEST)

if(DEVELOPER_EXTERNAL_BOOST_TEST)
    CPMAddPackage(
        NAME external-boost-test
        GITHUB_REPOSITORY boostorg/test
        GIT_TAG boost-1.76.0
        OPTIONS "BUILD_TESTING OFF"
    )
    message(STATUS "boost_test_ADDED = ${boost_test_ADDED}")
    if(boost_test_SOURCE_DIR)
        add_custom_target(external-boost-test)
        set(EXTERNAL_BOOST_TEST_INCLUDE_DIR ${boost_test_SOURCE_DIR}/include)
    else()
        message(FATAL_ERROR "Failure in external Boost's optional module 'Test'")
    endif()
    message(STATUS "EXTERNAL_BOOST_TEST_INCLUDE_DIR = ${EXTERNAL_BOOST_TEST_INCLUDE_DIR}")
endif()

and with

> cmake .
-- CPM: adding package external-boost-spirit@ (boost-1.76.0)
-- boost_spirit_ADDED =
-- EXTERNAL_BOOST_SPIRIT_INCLUDE_DIR = D:/<project>/build/_deps/external-boost-spirit-src/include
-- CPM: adding package external-boost-test@ (boost-1.76.0)
-- boost_test_ADDED =
CMake Error at cmake/external_optional.cmake:56 (message):
  Failure in external Boost's optional module 'Test'
Call Stack (most recent call first):
  CMakeLists.txt:40 (include)

the CMakeCache.txt still contains only:

//Value Computed by CMake
boost_spirit_BINARY_DIR:STATIC=D:/<project>/build/_deps/external-boost-spirit-build

//Value Computed by CMake
boost_spirit_SOURCE_DIR:STATIC=D:/<project>/build/_deps/external-boost-spirit-src

so there is no boost_spirit_ADDED - or even the vars for Boost test 'boosttest'

I restarted several time with removed build directory and new cmake call without success. CMake is:

> cmake --version   
cmake version 3.19.6

The project structure is:

{ROOT]/CMakeLists.txt:

    ...    
    list(APPEND
        CMAKE_MODULE_PATH
            ${PROJECT_SOURCE_DIR}/cmake
            ${PROJECT_SOURCE_DIR}/cmake/module
    )
    ...
    # [cpm-cmake/CPM.cmake](https://github.com/cpm-cmake/CPM.cmake)
    include(cmake/module/CPM.cmake) # FixMe full path

    ...
    include(external_optional)
    ...

{ROOT]/cmake/module/CPM.cmake:

    see top of posting

So, what could go be wrong here. For some reasons I have to explicit use the path to CPM.cmake, even if it should be in the module PATH.

Andres6936 commented 3 years ago

This repository Boost Test not have support to CMake. Therefore, you cannot send options to it as you can with Boost Spirit.

Replace the called to Boost Test with this:

CPMAddPackage(
        NAME external-boost-test
        GITHUB_REPOSITORY boostorg/test
        GIT_TAG boost-1.76.0
    )
opelx commented 3 years ago

Thanks for your help!