11
12

More than 5 years have passed since last update.

CMake で pkg-config を使う

Posted at

標準で提供されている pkg-config 用のモジュールを使う。

  1. find_package() で PkgConfig を指定する
    • 実体は cmake 標準の FindPkgConfig.cmake モジュール
  2. pkg_check_modules() で探したいライブラリーを指定する
    • ここで検索結果に名前をつけることであとで参照できる
  3. 2 でつけた名前を使って -I オプションや -l オプションの指定をひっぱりだす

サンプル見たほうが早い。

CMakeLists.txt
# load the module to use pkg-config
find_package(PkgConfig)

# search library with pkg-config and name its results "LIBSAMPLE"
pkg_check_modules(LIBSAMPLE REQUIRED libsample)

# use the variable <RESULTNAME>_INCLUDE_DIRS to get include paths
include_directories(${LIBSAMPLE_INCLUDE_DIRS})

add_executable(sample
    main.cpp
    )

# use the variable <RESULTNAME>_LIBRARIES to get library paths
target_link_libraries(sample
    ${LIBSAMPLE_LIBRARIES}
    )
11
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
12