cmake - How can I make a CMakeList.txt belong to certain target or a folder? -


i give following example illustrate question. projects have following structure:

cmakelists.txt dir1 dir2 dir3 

in cmakelists.txt, have following definitions:

macro(obtain_sublist result _curdir)   set(curdir ${${_curdir}})   file(glob children relative ${curdir} ${curdir}/*)   set(dirlist "")     foreach(child ${children})     if(is_directory ${curdir}/${child})         list(append dirlist ${child})     endif()   endforeach()   set(${result} ${dirlist}) endmacro()  set(curdir ${cmake_current_source_dir}) obtain_sublist(subdir curdir) foreach(var ${subdir})     add_subdirectory(${var}) endforeach() 

within each subdirectories (dir1, dir2 , dir3) targets built. when project built visual studio, can observe each target corresponding cmakelists.txt, used create target. however, top cmakelists.txt in example unseen in project not create target. there way include cmakelists.txt in project? if possible, can put in folder? thanks.

it should appear in all_build target think.

if want, can create custom target hold it. in top-level cmakelists.txt:

add_custom_target(cmakefiles sources ${cmake_source_dir}/cmakelists.txt) 

or add existing target in 1 or more or subdirs. so, in subdir cmakelists.txt add:

add_executable(dir1 dir1.cpp ${cmake_source_dir}/cmakelists.txt) 

you can create sub-folders of target in vs solution (which need not relate actual filesystem folders) using source_group:

source_group("root" files ${cmake_source_dir}/cmakelists.txt) 

Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

c# - two queries in same method -