Find_package
CMAKE_PREFIX_PATH
=> CMAKE_CURRENT_BINARY_DIR
=> CMAKE_INSTALL_PREFIX
find_package(Boost REQUIRED)
Unix 系のシステム(/usr とか)にライブラリーがインストールされている場合は使えるのだけど、 Windows ではつらい。 動かすために pkg-config や 環境変数や submodule などの仕込みが必用なことが多い。 どこから find しているかが不明瞭になるのである。
include_dir
, defines
, lib_dir
, libraries
の4つが揃えば大抵のライブラリーは使えるので、
うまくいかないときは find_package
は諦める方が速い。
INTERFACE でビルド済みライブラリを使えないかやってみるとよい。
add_library(boost INTERFACE)
target_include_directories(
boost INTERFACE ${CMAKE_CURRENT_LIST_DIR}/../include/boost-1_78)
https://cmake.org/cmake/help/latest/command/find_package.html#config-mode-search-procedure
config mode
https://cmake.org/cmake/help/latest/command/find_package.html#config-mode-search-procedure
https://cmake.org/cmake/help/latest/command/install.html
install(TARGETS <target>... [...])
install(IMPORTED_RUNTIME_ARTIFACTS <target>... [...])
install({FILES | PROGRAMS} <file>... [...])
install(DIRECTORY <dir>... [...])
install(SCRIPT <file> [...])
install(CODE <code> [...])
install(EXPORT <export-name> [...])
install(PACKAGE_INFO <package-name> [...])
install(RUNTIME_DEPENDENCY_SET <set-name> [...])
Installing
CMAKE_INSTALL_PREFIX
https://cmake.org/cmake/help/latest/variable/CMAKE_INSTALL_PREFIX.html#variable:CMAKE_INSTALL_PREFIX
default
-
/usr/local
-
C:/Program Files/${PROJECT_NAME}
commandline override
> cmake --install . --prefix "/home/myuser/installdir"
install()
install — CMake 4.0.3 Documentation