Contents
Go to make build easier.
- CMakeLists.txt
- like Makefile
- add_executable(
<name>
source1 [source2 …])- Adds an executable target called
<name>
to be built from the source files listed in the command invocation. - The
<name>
corresponds to the logical target name and must be globally unique within a project.
1
2
3* c++11 support
- add_compile_options() will add the options to gcc and g++
- set(CMAKE_CXX_FLAGS) works for g++ only
- Adds an executable target called
if(CMAKE_COMPILER_IS_GNUCXX)
# add_compile_options(-std=c++11)
set(CMAKE_CXX_FLAGS “${CMAKE_CXX_FLAGS} -std=c++11”)
message(STATUS “optional:-std=c++11”)
endif(CMAKE_COMPILER_IS_GNUCXX)
1 |
|
Build a single file
- a single source file is going to be built into an executable binary
1
2
3cmake_minimum_required(VERSION 2.8)
add_executable(stest single_list.cpp)
Build multiple files in sub directory
-
serveral files in different sub direcotries, build them all in the root directory, and also could build each in a sub directory.
1
2
3
4
5
6
7
8.
├── CMakeLists.txt
├── dlist
│ ├── CMakeLists.txt
│ └── double_list.cpp
└── slist
├── CMakeLists.txt
└── single_list.cpp -
slist CMakeLists.txt
1
2
3cmake_minimum_required(VERSION 2.8)
add_executable(stest single_list.cpp) -
dlist CMakeLists.txt
1
2
3cmake_minimum_required(VERSION 2.8)
add_executable(dtest double_list.cpp) -
folder root
1
2
3
4cmake_minimum_required(VERSION 2.8)
add_subdirectory(slist)
add_subdirectory(dlist)
近期评论