Using boost in a modern way static AND shared

I have an existing project that uses boost heavily and am converting to CMake.
As a hand crafted project it uses nuget and I just cannot figure out how to make that work and I really do not want to as the linux build does not (maintaining 2 build systems atm). I am using

    set(CMAKE_PREFIX_PATH  ${BOOST_ROOT}/stage)
    message (" Looking for boost in ${BOOST_ROOT}")
    set(Boost_NO_SYSTEM_PATHS        ON)
    find_package(Boost ${Boost_VER} CONFIG REQUIRED COMPONENTS date_time thread filesystem system regex)

I built a complete build and all the projects except one can find and use boost. That one project is /MT instead of /MD and uses boost::asio.
When I use this more modern CMake way and add the targets to the projects target_link_libraries, I am also adding the PreProcessor definitions and the include directories but I seem to be missing something.

This works for all other targets. (static,shared and an executable)

 target_link_libraries(  ${PROJECT_NAME}
   ...
    Boost::headers
    Boost::dynamic_linking
  ...

But this does not work for the staticaly linked /MT add_executable

target_link_libraries(  ${PROJECT_NAME} 
                        ...
                        Boost::headers
                        Boost::date_time
                        Boost::filesystem
                        Boost::regex
                        Boost::system
                        ...

Is this how I am suppose to bring in the properties, include paths and libnames for the statically linked boost libs?

I have not actually gotten to linking, It is compile errors about identifiers not found which I can aliviate temporarily that then shows the wrong boost library type is trying to be used and so I am thinking the includes are wrong. I tried making the command line for the buidl the same but the full paths make that not possible.

(Boost 1.76, CMAke 3.23, VS2019 V142 x64)

Thanks.

1 Like

I found in the doc that this will not work in this way. That which was found on first usage will not be overwritten on a second find and the Boost::dynamic linking works for the boost libraries and NOT the C runtime linking.

The old method is suppose to work but it still seems to ALWAYS get the library wrong.
:frowning: