find_package(Boost 1.75 REQUIRED COMPONENTS filesystem system) if(Boost_FOUND) target_link_libraries(my_app PRIVATE Boost::filesystem Boost::system) endif() CMake will automatically search standard system paths, or paths you hint via -DCMAKE_PREFIX_PATH . Not every library provides CMake configs. For those, you can use pkg-config (common on Linux):
Now go forth and link without fear! Have a library that just won’t cooperate? Drop the error message in the comments, and I’ll help you debug it.
find_package(SDL2 CONFIG REQUIRED) target_link_libraries(my_game PRIVATE SDL2::SDL2)
Example: Adding the popular fmt library: