pkg config - githeim/windheim_archive GitHub Wiki

pkg-config is a computer program that defines and supports a unified interface for querying installed libraries for the purpose of compiling software that depends on them.

pkg-config๋Š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ํŒจํ‚ค์ง€๋ฅผ ์‚ฌ์šฉํ•ด์„œ ๋นŒ๋“œํ•˜๊ธฐ ์œ„ํ•œ ์ •๋ณด(include path, library ๋ช… ๋“ฑ๋“ฑ)๋ฅผ ์ œ๊ณตํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์ด๋‹ค. ์ด๋Š” cli ํ”„๋กœ๊ทธ๋žจ์ด์ง€๋งŒ, cmake์—์„œ๋„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค. ์ด๋ฅผ ์†Œ๊ฐœํ•œ๋‹ค.

examples

show all packages available in the system

$ pkg-config --list-all

....
xkbfile                          xkbfile - The xkbfile Library                                        
xkeyboard-config                 XKeyboardConfig - X Keyboard configuration data                      
xmu                              Xmu - Xmu Library                                                    
xmuu                             Xmuu - Mini Xmu Library                                              
xorg-server                      xorg-server - Modular X.Org X Server                                 
xorg-sgml-doctools               xorg-sgml-doctools - Stylesheets and entities for X.Org documentation
....

example

pkg-config --cflags sdl2
pkg-config --cflags libmosquitto

using pkg-config in cmake

in CMakeLists.txt or *.cmake

find_package(PkgConfig REQUIRED)               
pkg_check_modules(MOSQ libmosquitto REQUIRED)  

SET ( INCLUDE_DIR                   
        ${INCLUDE_DIR}              
        ${MOSQ_INCLUDEDIR}          
        )                           
                                    
SET ( LIBRARY_LISTS ${LIBRARY_LISTS}
  ${MOSQ_LIBRARIES}                 
  )                                 

pkg_check_modules(MOSQ libmosquitto REQUIRED)

์ด ๊ตฌ๋ฌธ์—์„œ MOSQ๋Š” ํ•ด๋‹น ํŒจํ‚ค์ง€(libmosquitto)์—์„œ ์–ป์–ด์˜ฌ ํ™˜๊ฒฝ๋ณ€์ˆ˜์— ๋Œ€ํ•œ prefix๋ฅผ ์ง€์ •ํ•œ๋‹ค.

๋”ฐ๋ผ์„œ ๊ทธ ์•„๋ž˜ ๊ตฌ๋ฌธ์ฒ˜๋Ÿผ MOSQ_INCLUDEDIR , MOSQ_LIBRARIES ๊ฐ™์€ ํ™˜๊ฒฝ๋ณ€์ˆ˜๊ฐ€ ์„ค์ •๋œ๋‹ค.