CMake 一些语法
1.message语法 打印信息
message( [STATUS|WARNING|AUTHOR_WARNING|FATAL_ERROR|SEND_ERROR]
"message to display" ...)
可以用下述可选的关键字指定消息的类型:
(无) = 重要消息;
STATUS = 非重要消息;
WARNING = CMake 警告, 会继续执行;
AUTHOR_WARNING = CMake 警告 (dev), 会继续执行;
SEND_ERROR = CMake 错误, 继续执行,但是会跳过生成的步骤;
FATAL_ERROR = CMake 错误, 终止所有处理过程;
输出变量的值:
SET(USER_KEY, "Hello World")
MESSAGE(STATUS "this var key = ${USER_KEY}.")
caffe cmakelist 1
在caffe源码tools目录下,目录结构如下:
├── caffe.cpp
├── caffe_test_c.cpp
├── CMakeLists.txt
├── compute_image_mean.cpp
├── convert_imageset.cpp
├── extra
│ ├── extract_seconds.py
│ ├── launch_resize_and_crop_images.sh
├── extract_features.cpp
├── upgrade_net_proto_binary.cpp
├── upgrade_net_proto_text.cpp
└── upgrade_solver_proto_text.cpp
这里面的cmakelist就是把每个cpp生成一个可执行文件。
可以学习学习写法:
# Collect source files
file(GLOB_RECURSE srcs ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp)
#MESSAGE(STATUS "srcs = ${srcs}.")
MESSAGE(STATUS "Caffe_LINK = ${Caffe_LINK}")
# Build each source file independently
foreach(source ${srcs})
get_filename_component(name ${source} NAME_WE)
MESSAGE(STATUS "name = ${name}")
# caffe target already exits
if(name MATCHES "caffe")
MESSAGE(STATUS "MATCHES name = ${name}")
set(name ${name}.bin)
endif()
# target
add_executable(${name} ${source})
target_link_libraries(${name} ${Caffe_LINK})
caffe_default_properties(${name})
# set back RUNTIME_OUTPUT_DIRECTORY
caffe_set_runtime_directory(${name} "${PROJECT_BINARY_DIR}/tools")
caffe_set_solution_folder(${name} tools)
# restore output name without suffix
if(name MATCHES "caffe.bin")
set_target_properties(${name} PROPERTIES OUTPUT_NAME caffe)
endif()
# Install
install(TARGETS ${name} DESTINATION ${CMAKE_INSTALL_BINDIR})
endforeach(source)
一般独立的生成一个可执行文件写法:
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
project(test_glogs)
SET(CMAKE_BUILD_TYPE Debug)
#glog
include_directories(/data_2/lib/glog/include/)
link_directories(/data_2/lib/glog/lib)
add_executable(main main.cpp)
target_link_libraries(main glog)
set_property(TARGET main PROPERTY CXX_STANDARD 11)
好记性不如烂键盘---点滴、积累、进步!