cmake语法基础

cmake use

  • 主目录下CMakeLists
cmake_minimum_required(VERSION 3.9.5)
project(exchange)

message(${PROJECT_SOURCE_DIR})

set(CMAKE_C_COMPILER "gcc")
set(CMAKE_CXX_COMPILER "g++")
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -Wno-deprecated -Wall")

# 遍历
foreach(flag ${CMAKE_CXX_FLAGS})
    message(${flag})
endforeach()

# pkg-config
find_package(PkgConfig)

# generate lib
#SET(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)
#aux_source_directory(. DIR_INC)
#add_library(hellolib ${DIR_INC})

pkg_search_module(OPENCV REQUIRED opencv)
message(${OPENCV_LIBRARIES})
message(${OPENCV_INCLUDE_DIRS})

aux_source_directory(. DIR_MAIN)
include_directories(${PROJECT_SOURCE_DIR}/inc)
link_directories(${PROJECT_SOURCE_DIR}/lib)
# add_subdirectory(inc) # 在上面生成lib或者创建子文件夹,这个文件夹用来生成lib库

add_executable(exchange
        ${DIR_MAIN})

target_link_libraries(
        exchange
        test
        thosttraderapi_se
)

  • inc目录下用于生成lib库的CMakeLists
cmake_minimum_required(VERSION 3.9.5)

# generate lib
SET(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)
aux_source_directory(. DIR_INC)
add_library(hellolib ${DIR_INC})

你可能感兴趣的:(cmake语法基础)