Created
July 6, 2017 14:36
-
-
Save baishuai/7da37fdee04ad72b598190bfe584ae46 to your computer and use it in GitHub Desktop.
CMakeLists.txt add_executable for each subdir in src
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cmake_minimum_required(VERSION 3.7) | |
project(fragmentsdemo) | |
set(CMAKE_CXX_STANDARD 11) | |
macro(SUBDIRLIST result curdir) | |
file(GLOB children ${curdir}/*) | |
set(dirlist "") | |
foreach (child ${children}) | |
message(STATUS ${child}) | |
if (IS_DIRECTORY ${child}) | |
list(APPEND dirlist ${child}) | |
endif () | |
endforeach () | |
set(${result} ${dirlist}) | |
endmacro() | |
SUBDIRLIST(SUBDIRS src) | |
foreach (subdir ${SUBDIRS}) | |
file(GLOB F_SOURCES ${subdir}/*.cpp) | |
file(GLOB F_HEADERS ${subdir}/*.h) | |
if (F_SOURCES) | |
string(REPLACE ${CMAKE_SOURCE_DIR}/src/ "" TARGET_NAME ${subdir}) | |
add_executable(${TARGET_NAME} ${F_SOURCES} ${F_HEADERS}) | |
message(STATUS "add target ${TARGET_NAME} ${F_SOURCES} ${F_HEADERS}") | |
endif () | |
endforeach () | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment