I have this CMakeLists.txt
set(Boost_USE_STATIC_LIBS ON)
find_package(Boost REQUIRED COMPONENTS json)
include_directories(${BOOST_INCLUDE_DIRS})
target_link_libraries(<Target> PRIVATE Boost::json)
But I get cmake warnings
[cmake] CMake Warning at C:/Program Files/CMake/share/cmake3.20/Modules/FindBoost.cmake:2185 (message):
[cmake] No header defined for json; skipping header check (note: header-only
[cmake] libraries have no designated component)
The project can configure and build tho. ~~But the compile_command.json
I found didn't actually link to the static library, which clearly indicate it is not found and was compiled as header only library.~~
EDIT: I found it actually links to libboost_json-mt.a
in the generated build.ninja
file, so it is weird the fact that cmake does not find the static library in the find_package
call.
build MyTest.exe MyTest[1]_tests.cmake: CXX_EXECUTABLE_LINKER__MyTest_Debug CMakeFiles/MyTest.dir/test.cpp.obj CMakeFiles/MyTest.dir/BasicStructures/Uri.cpp.obj | C$:/msys64/mingw64/lib/libgtest_main.dll.a C$:/msys64/mingw64/lib/libboost_json-mt.a C$:/msys64/mingw64/lib/libgtest.dll.a C$:/msys64/mingw64/lib/libboost_container-mt.a
FLAGS = -g
LINK_LIBRARIES = C:/msys64/mingw64/lib/libgtest_main.dll.a C:/msys64/mingw64/lib/libboost_json-mt.a C:/msys64/mingw64/lib/libgtest.dll.a C:/msys64/mingw64/lib/libboost_container-mt.a -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32
OBJECT_DIR = CMakeFiles\MyTest.dir
POST_BUILD = cmd.exe /C "cd /D C:\Users\Peter\Desktop\LspCpp\build && "C:\Program Files\CMake\bin\cmake.exe" -D TEST_TARGET=MyTest -D TEST_EXECUTABLE=C:/Users/Peter/Desktop/LspCpp/build/MyTest.exe -D TEST_EXECUTOR= -D TEST_WORKING_DIR=C:/Users/Peter/Desktop/LspCpp/build -D TEST_EXTRA_ARGS= -D TEST_PROPERTIES= -D TEST_PREFIX= -D TEST_SUFFIX= -D NO_PRETTY_TYPES=FALSE -D NO_PRETTY_VALUES=FALSE -D TEST_LIST=MyTest_TESTS -D CTEST_FILE=C:/Users/Peter/Desktop/LspCpp/build/MyTest[1]_tests.cmake -D TEST_DISCOVERY_TIMEOUT=5 -D TEST_XML_OUTPUT_DIR= -P "C:/Program Files/CMake/share/cmake-3.20/Modules/GoogleTestAddTests.cmake""
PRE_LINK = cd .
RESTAT = 1
TARGET_FILE = MyTest.exe
TARGET_IMPLIB = libMyTest.dll.a
TARGET_PDB = MyTest.exe.dbg