title: How to run all sub directory CMakeList file and capture output?
body: <p>I am new to cmake file creation. I have c++ code in list of directory, each directory has its own <code>CMakeLists.txt</code> file. For compile and create executable in each directory, I have to go inside directory and execute following two command on terminal.</p>
  
  <pre><code>$ cmake .
  $ make
  </code></pre>
  
  <p>Example directory structure:
  <a href="https://i.stack.imgur.com/zbbfx.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zbbfx.png" alt="enter image description here"></a></p>
  
  <p>Each directory 1, 2 ...41 has its own `CMakeLists.txt'.</p>
  
  <p>Example inside each directory file structure:
  <a href="https://i.stack.imgur.com/oqpBn.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/oqpBn.png" alt="enter image description here"></a></p>
  
  <p>For compile and create executable in each directory, i have to follow those tow command. </p>
  
  <p>But now i have to write either python script/ cmake script to do above this action in each directory and capture the output and store in log file.</p>
  
  <p>Kindly anyone to guide me to solve my issue. Thanks in advance.</p>
  
  <p>My each directory CMakeLists.txt like this:</p>
  
  <pre><code>project(foundations)
  cmake_minimum_required(VERSION 2.6)
  
  include_directories($ENV{GMOCK_HOME}/include $ENV{GMOCK_HOME}/gtest/include)
  link_directories($ENV{GMOCK_HOME}/mybuild $ENV{GMOCK_HOME}/gtest/mybuild)
  add_definitions(-std=c++11)
  
  set(sources main.cpp RetweetCollectionTest.cpp)
  add_executable(test ${sources})
  target_link_libraries(test pthread)
  target_link_libraries(test gmock)
  target_link_libraries(test gtest)
  </code></pre>