cmakelist的一个例子

2024-05-14 08:35:32 浏览数 (1)

一个例子,仅做参考用:

代码语言:javascript复制
CMAKE_MINIMUM_REQUIRED(VERSION 3.12)
set(ProjName "NetworkTest")
project(${ProjName})

string(FIND ${CMAKE_CURRENT_BINARY_DIR} "/" pos0 REVERSE)
MATH(EXPR pos0 ${pos0} 1)
string(SUBSTRING ${CMAKE_CURRENT_BINARY_DIR} ${pos0} -1 fName)
string(TOLOWER ${fName} typeName)
message("typeName=${typeName}!")

set(CMAKE_C_COMPILER "/usr/bin/gcc")
set(CMAKE_CXX_COMPILER "/usr/bin/g  ")

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c  14")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -MMD")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -MP")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I.")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "x86_64")
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mavx")
elseif(${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64")
endif()
if(typeName MATCHES "debug")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0 -D_DEBUG")
    set(APP_POSTFIX "_d")
else()
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
    set(APP_POSTFIX "")
endif()

find_package(OpenCV REQUIRED)
find_package(Ceres REQUIRED)

set(Shared_DIR ${PROJECT_SOURCE_DIR}/../../Shared/)

include_directories(
  ${Shared_DIR}
  ${PROJECT_SOURCE_DIR}
)

add_executable(SocketTest
  ${PROJECT_SOURCE_DIR}/SocketTest.cpp
  ${Shared_DIR}/src/Network/SocketWrapper.cpp
)

0 人点赞