CMake 学习之使用第三方库

CMakeLists.txt:

cmake_minimum_required(VERSION 3.0.0)

project ( aes_prj )

set(INCLUDE_DIR /include)
set(LINK_DIR /lib)
set( STATIC_LIB_SOURCES
    src/Hello.cpp
)

set( EXE_SOURCES
    src/main.cpp
)

add_library( hello_world_static_library STATIC 
    ${STATIC_LIB_SOURCES}
)
include_directories(${
INCLUDE_DIR})  #去哪里找头文件 相当于gcc/clang 中的-I(i的大写字母)参数
link_directories(${LINK_DIR})  #去哪里找库文件 .so .dll .dylib 相当于gcc 中的-L参数

target_include_directories( hello_world_static_library
    PUBLIC 
        ${PROJECT_SOURCE_DIR}/include
)
target_include_directories( hello_world_exe
    PRIVATE 
        ${PROJECT_SOURCE_DIR}/include
)
add_executable( hello_world_exe ${EXE_SOURCES} )  target_link_libraries( hello_world_exe PRIVATE hello_world_static_library )

 

posted on 2025-04-14 17:17  =WinHZ  阅读(11)  评论(0)    收藏  举报

导航