I am having a problem with make 3.12 (windows) and cmake version 3.13.0-rc2 
(linux). I am attempting to link boost headers privately to a static library, 
which is then linked by a client executable, that I do not want to depend on 
boost.

According to the docs, the find_package(Boost) provides a target for the header 
only portion of the boost library, Boost::boost. this is the target I am using, 
and I am linking the target privately, ie

target_link_libraries(testlib PRIVATE Boost::boost)

However a the client testexe which uses testlib from the install dir with 
find_package(testlib)and links it with target_link_libraries(testexe 
testlib::testlib) is causing cmake to search for a Boost dependency for the 
testexe. As this is linked privately, it shouldn't as far as I can see.

Interestingly adding an INTERFACE IMPORTED target in testlib and using this to 
link, and the client no longer needs boost.

find_package(Boost REQUIRED)

add_library(boost INTERFACE IMPORTED)

set_property(TARGET boost PROPERTY
    INTERFACE_INCLUDE_DIRECTORIES ${Boost_INCLUDE_DIR})
target_link_libraries(testlib
    PRIVATE
        #using the imported target instead
        boost
        #Boost::boost)

this is almost identical to the lines in the Find boost source 
here<https://github.com/Kitware/CMake/blob/master/Modules/FindBoost.cmake#L2026-L2030>.
 The only difference being the target the properties are set on.

I have a workaround but I would like to know what is going on.

The complete source for the two test projects are availabe 
here<https://github.com/rmawatson/share/tree/master/cmake_boost>.

This is the output from cmake with using the Boost::boost target and the 
INTERFACE IMPORTEDtarget, which works

###using to the provided Boost::boost target

C:\Temp\cmake_boost\testlib\build>cmake ../ 
-DBOOST_ROOT=d:\sdk\boost\boost_1_68_0
-- Boost version: 1.68.0-- Configuring done
-- Generating done
-- Build files have been written to: C:/Temp/cmake_boost/testlib/build

C:\Temp\cmake_boost\testexe\build>cmake ../ 
-DCMAKE_PREFIX_PATH="C:\Temp\cmake_boost\testlib\build"-- Configuring done
CMake Error at CMakeLists.txt:6 (add_executable):
  Target "test" links to target "Boost::boost" but the target was not found.
  Perhaps a find_package() call is missing for an IMPORTED target, or an
  ALIAS target is missing?............-- Generating done
-- Build files have been written to: C:/Temp/cmake_boost/testexe/build



#When using the imported library target.

C:\Temp\cmake_boost\testlib\build>cmake ../ 
-DBOOST_ROOT=d:\sdk\boost\boost_1_68_0
-- Boost version: 1.68.0-- Configuring done
-- Generating done
-- Build files have been written to: C:/Temp/cmake_boost/testlib/build


C:\Temp\cmake_boost\testexe\build>cmake ../ 
-DCMAKE_PREFIX_PATH="C:\Temp\cmake_boost\testlib\build"-- Configuring done
-- Generating done
-- Build files have been written to: C:/Temp/cmake_boost/testexe/build

Thanks!
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake

Reply via email to