Mastering Cmake Pdf ~repack~ -
if(MyLib_FOUND AND NOT TARGET MyLib::MyLib) add_library(MyLib::MyLib UNKNOWN IMPORTED) set_target_properties(MyLib::MyLib PROPERTIES IMPORTED_LOCATION "$MyLib_LIBRARY" INTERFACE_INCLUDE_DIRECTORIES "$MyLib_INCLUDE_DIR" ) endif() 1. Generator Expressions Evaluated during build system generation, not during CMake configuration.
find_path(MyLib_INCLUDE_DIR mylib.h PATHS /usr/include /usr/local/include) find_library(MyLib_LIBRARY mylib PATHS /usr/lib /usr/local/lib) include(FindPackageHandleStandardArgs) find_package_handle_standard_args(MyLib DEFAULT_MSG MyLib_LIBRARY MyLib_INCLUDE_DIR) mastering cmake pdf
find_package(OpenCV 4.5 REQUIRED) target_link_libraries(my_app PRIVATE opencv::core opencv::imgproc) # Propagates includes automatically cmake/FindMyLib.cmake : mastering cmake pdf
add_library(math STATIC add.cpp multiply.cpp) target_include_directories(math PUBLIC $CMAKE_CURRENT_SOURCE_DIR/include) target_compile_features(math PUBLIC cxx_std_17) option(BUILD_MATH_EXAMPLES "Build math examples" OFF) if(BUILD_MATH_EXAMPLES) add_executable(calc_example examples/calc.cpp) target_link_libraries(calc_example PRIVATE math) endif() mastering cmake pdf
add_custom_command( OUTPUT $CMAKE_CURRENT_BINARY_DIR/version.h COMMAND $CMAKE_COMMAND -DVERSION=$PROJECT_VERSION -P write_version.cmake DEPENDS write_version.cmake COMMENT "Generating version.h" ) add_custom_target(generate_version DEPENDS $CMAKE_CURRENT_BINARY_DIR/version.h) add_dependencies(my_app generate_version) toolchain_arm.cmake :