Clion Add External Library [Instant Hacks]
find_package(PkgConfig REQUIRED) pkg_check_modules(LIBUSB REQUIRED libusb-1.0) target_link_libraries(my_app PRIVATE $LIBUSB_LIBRARIES) target_include_directories(my_app PRIVATE $LIBUSB_INCLUDE_DIRS) Best for: Automatically downloading libraries from GitHub during configuration.
find_package(SDL2 CONFIG REQUIRED) target_link_libraries(my_game PRIVATE SDL2::SDL2) clion add external library
include(FetchContent) FetchContent_Declare( fmt GIT_REPOSITORY https://github.com/fmtlib/fmt.git GIT_TAG master ) FetchContent_MakeAvailable(fmt) target_link_libraries(my_app PRIVATE fmt::fmt) For those, you can use pkg-config (common on
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): complex dependencies with many variants (OpenCV
The IDE’s CMake cache viewer will show you exactly where FetchContent stored the library ( cmake-build-debug/_deps/ ), and code navigation works instantly. Method 5: vcpkg – The Missing Package Manager Best for: Large, complex dependencies with many variants (OpenCV, PCL, CGAL).
vcpkg install sdl2 Then in CMake: