我正在努力制作一个CMakeList.txt文件来反映一个简单的典型makefile。原文在这里http://pastebin.com/S9Czr1pt。
我尝试了很多东西(比如SET(SOURCE ...和SET(HEADERS ...)来添加/ src,/ lib和/ / third-party // include),但我没有运气。
任何人都可以帮助我或指向做这件事的教程吗?
答案 0 :(得分:0)
这只是一个蓝色的骨架 - 请参阅CMake documentation了解每个功能的详细信息:
cmake_minimum_required(VERSION 2.6)
# Project name, can be used as target name too
project(Example)
# Search all .cpp files within src - recursive!
# You can add all source files by hand here too
file(GLOB_RECURSE SRCS "src/*.cpp")
# Add include path (you can also add it's sub directories
include_directories("include")
# Search for packages -- PLEASE NOTE: many libraries provide alternative's to this
# which often provide more functionality
find_package(PkgConfig REQUIRED)
# TODO: add proper pkg modul search info's and change the variable's name
pkg_search_module(PACKAGE_NO1 ...)
# Show some messages (optional)
if( (PACKAGE_NO1 )
include_directories(${(PACKAGE_NO1_INCLUDE_DIRS})
message(STATUS "Using OpenSSL ${(PACKAGE_NO1_VERSION}")
else()
# do error handling
endif()
# Add compiler flags
add_definitions(-std=c++11 -Wall) # -g O3 etc are added according to Release / Debug compilation
# Build a executable target (1st param: Target name; 2nd: source files)
add_executable(${PROJECT_NAME} ${SRCS})