Help us understand the problem. What is going on with this article?

CMake で pkg-config を使う

More than 3 years have passed since last update.

http://www.cmake.org/cmake/help/v3.0/module/FindPkgConfig.html

標準で提供されている 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}
    )
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away