CMake 相当于什么:
gcc filename.c -o filename $(pkg-config --libs --cflags mylib)
我对$(pkg-config --libs --cflags mylib)
部分感兴趣,因为我已经有了可以编译的代码,我只需要添加mylib
库。
看看FindPkgConfig模块
src: https://cmake.org/cmake/help/latest/module/FindPkgConfig.html
CMakeLists.txt示例:
include(FindPkgConfig)
pkg_check_modules(MYLIB REQUIRED mylib)
...
add_executable(filename filename.c)
target_include_directories(filename PUBLIC ${MYLIB_INCLUDE_DIRS})
target_compile_options(filename PUBLIC ${MYLIB_CFLAGS})
target_link_libraries(filename ${MYLIB_LIBRARIES})