boostorg / program_options

Boost.org program_options module
http://boost.org/libs/program_options
110 stars 107 forks source link

Potential Cmake issue. Not able to get secondary dependency when including in own helloworld-app #119

Open bratne opened 2 years ago

bratne commented 2 years ago

I trying to include program_options in a simple testapp, by using CMake.

include(FetchContent)
FetchContent_Declare (
    boost_program_options
    GIT_REPOSITORY https://github.com/boostorg/program_options.git   
    GIT_TAG boost-1.80.0
)
FetchContent_MakeAvailable(boost_program_options)
add_executable(helloworld main.cpp)
target_link_libraries(helloworld PRIVATE boost_program_options) 

Trying to build this yields

[cmake] CMake Error at CMakeLists.txt:15 (add_executable):
[cmake]   Target "helloworld" links to target "Boost::any" but the target was not
[cmake]   found.  Perhaps a find_package() call is missing for an IMPORTED target, or
[cmake]   an ALIAS target is missing?
ngunderson commented 1 year ago

Boost::any is a separate library/target than program_options. You could add fetching https://github.com/boostorg/any.git to retrieve this target, though you may end up needing another library that Boost Program Options also depends on. You could instead try fetching the super project boost repository than has all Boost libraries, https://github.com/boostorg/boost. This will give you all Boost libraries, but you should still only have access to and build the explicit targets you link to, like (Boost::program_options).