cmake 同时编译多个cpp文件

cmake_minimum_required(VERSION 2.8)
project(coding)
file(GLOB_RECURSE EXTRA_FILES */*)
add_custom_target(${PROJECT_NAME}_OTHER_FILES ALL WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} SOURCES ${EXTRA_FILES})
file(GLOB_RECURSE code_sources "src/*.cpp")
foreach(code_src ${code_sources})
    get_filename_component(mexecutable ${code_src} NAME_WE)
    add_executable(${mexecutable} ${code_src})
endforeach()

一篇博客很好:

http://www.cnblogs.com/dverdon/p/4574221.html

https://stackoverflow.com/questions/6921695/how-can-i-build-a-c-project-with-multiple-interdependent-subdirectories

原文地址:https://www.cnblogs.com/hong2016/p/7082203.html