-2

How to write one Cmake file that compile all my sub-directories each with its own executable?

       /Project
            Cmakelist.txt
            /project 1
                /src
                  .cpp
                /include
                  .h
            /project 2
                /src
                  .cpp
                /include
                  .h
SergeyA
  • 61,605
  • 5
  • 78
  • 137
M.H
  • 1
  • 2
  • Doesn't `add_subdirectory` fit the bill? – SergeyA Apr 26 '16 at 16:32
  • @SergeyA I am newbie in Cmake, I have come across add_subdirectory, but don't know how to set the executable for each project – M.H Apr 26 '16 at 16:34
  • Every subdirectory will have it's own CMakeLists.txt, with own `add_executable`. – SergeyA Apr 26 '16 at 16:55
  • @Sergey I did as you said, I am getting error that I cant include_directories(include) multiple times, what should i do, beside then renaming the include folder in each project differently – M.H Apr 26 '16 at 17:43

1 Answers1

-1

Include this in every CmakeList.txt subfolder

cmake_minimum_required(VERSION 3.5.2)
project(project1)
set(SRC "src/name.cpp" "include/name2.h")

add_executable(project1 ${SRC})
target_include_directories (project1 PRIVATE include)

And this in the CmakeList.txt root directory

cmake_minimum_required(VERSION 3.5.2)
project(project)
add_subdirectory(project1)
add_subdirectory(project2)

...add more if you want

you can also delete the header files from set, it will also work

M.H
  • 1
  • 2