cmake_minimum_required(VERSION 3.0)
project(3rd)
find_package(Boost)
if(Boost_FOUND)
message(STATUS "boost found!")
else()
message(FATAL_ERROR "cannot find Boost")
endif()
add_executable(3rd main.cpp)
target_link_libraries(3rd boost_filesystem boost_system)
cmake_minimum_required(VERSION 3.0)
project(3rd)
find_package(Boost COMPONENTS filesystem system)
if(Boost_FOUND)
message(STATUS "boost found!")
else()
message(FATAL_ERROR "cannot find Boost")
endif()
add_executable(3rd main.cpp)
target_link_libraries(3rd PRIVATE Boost::filesystem)
两种方法效果相同,区别在于find_package时是否需要传入COMPONENTS参数,以及target_link_libraries的使用方法