CMake的使用例子
程序员文章站
2022-05-31 21:38:22
...
根目录
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
PROJECT(sdk)
if(NOT CMAKE_BUILD_TYPE)
SET(CMAKE_BUILD_TYPE "Release")
endif()
SET(CXX_FLAGS
-Wall
-Wextra
-Werror
-Wno-unused-parameter
# -Wold-style-cast
# -Wshadow
-std=c++0x
)
if(CMAKE_BUILD_BITS EQUAL 32)
LIST(APPEND CXX_FLAGS "-m32")
endif()
STRING(REPLACE ";" " " CMAKE_CXX_FLAGS "${CXX_FLAGS}")
SET(CMAKE_CXX_COMPILER "g++")
SET(CMAKE_CXX_FLAGS_DEBUG "-g -O0")
SET(CMAKE_CXX_FLAGS_RELEASE "-O2 -finline-limit=1000 -DNDEBUG")
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR})
STRING(TOUPPER ${CMAKE_BUILD_TYPE} BUILD_TYPE)
MESSAGE(STATUS "CXX_FLAGS = " ${CMAKE_CXX_FLAGS} " " ${CMAKE_CXX_FLAGS_${BUILD_TYPE}})
ADD_SUBDIRECTORY(xustd/base)
#ADD_SUBDIRECTORY(xustd/net)
子目录
SET(SRCS
condition.cpp
condition2.cpp
datetime.cpp
dirpath.cpp
log.cpp
mutex.cpp
sock.cpp
sockaddr.cpp
string.cpp
thread.cpp
timer.cpp
)
ADD_LIBRARY(xustd ${SRCS})
TARGET_LINK_LIBRARiES(xustd pthread rt)
if(NOT CMAKE_BUILD_NO_EXAMPLES)
ADD_SUBDIRECTORY(tests)
endif()
子目录
ADD_EXECUTABLE(test_atomic test_atomic.cpp)
TARGET_LINK_LIBRARIES(test_atomic xustd)
下一篇: 发布自己的模块到npm