title: CMake setup advice for complicated build process (including externalProject)
body: <p>I have an application with a mildly complicated build process, and as a bit of a newb to CMake, I was wondering if anyone could provide me with any pointers.</p>
  
  <p>At preset, the application consists of a single executable, built from a source tree provided in the src and include folders.</p>
  
  <p>It requires a few libraries to work, the big ones being Boost and Python. Python is embedded in the application, and Boost requires knowledge of the custom python install at compile time. I also use Qt, but I'm just linking against the system Qt for this.</p>
  
  <p>What I'd like to have at the end is a stage folder, containing the compiled executable, and a lib folder with the required boost and python libraries.</p>
  
  <p>At present, I have a single CMakeLists.txt file, and I am using ExternalProject to build Boost and Python from bzipped tarballs of their source. It gets a little messy where I copy out the compiled libs from the prefixed install directories.</p>
  
  <p>Things are working, but I have a feeling I'm doing things very backwards. I sometimes see multiple CMakeLists in nested subdirectories but don't know how they would relate to my project. Would anyone who has worked on similarly scoped projects be able to weigh in and give me some pointers?</p>
  
  <p>I should add that I hope to include Windows as a platform in the near future, and that things are currently running on Linux.</p>
  
  <p>Note: This is my current CMakeLists.txt, I realise that boost isn't configured and that things aren't fully moved to the stage folder. I have been doing this manually, but I wanted to ask before I dig myself much deeper :)</p>
  
  <p>Thanks!</p>
  
  <p>CmakeList.txt</p>
  
  <pre><code>cmake_minimum_required(VERSION 2.6)
  
  set(CMAKE_BUILD_TYPE Debug)
  
  set(PROJ_NAME "mwave")
  project(${PROJ_NAME})
  
  include_directories("include")
  include(ExternalProject)
  
  # Add cmake dir to cmake module path so custom find modules will work
  set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake  ${CMAKE_MODULE_PATH})
  
  #Build Python via External Project
  ExternalProject_Add(
      Python
      PREFIX ${CMAKE_CURRENT_BINARY_DIR}/external/python
      URL ${CMAKE_CURRENT_SOURCE_DIR}/extern/Python-3.3.0.tar.bz2
      URL_MD5 2dbff60afed2b5f66adf6f77dac9e139
      UPDATE_COMMAND ""
      CONFIGURE_COMMAND ./configure -q --prefix=${CMAKE_CURRENT_BINARY_DIR}/external/python --enable-shared
      BUILD_COMMAND make
      BUILD_IN_SOURCE 1
      INSTALL_COMMAND make install
  )
  
  # Manually copy the compiled python files and dirs to our stage folder
  add_custom_command(TARGET Python PRE_BUILD
                      COMMAND ${CMAKE_COMMAND} -E copy_directory
                      ${CMAKE_CURRENT_BINARY_DIR}/external/python/lib/pkgconfig
                      ${CMAKE_CURRENT_BINARY_DIR}/stage/lib/pkgconfig)
  
  add_custom_command(TARGET Python PRE_BUILD
                      COMMAND ${CMAKE_COMMAND} -E copy_directory
                      ${CMAKE_CURRENT_BINARY_DIR}/external/python/lib/python3.3
                      ${CMAKE_CURRENT_BINARY_DIR}/stage/lib/python3.3)
  
  add_custom_command(TARGET Python PRE_BUILD
                      COMMAND ${CMAKE_COMMAND} -E copy
                      ${CMAKE_CURRENT_BINARY_DIR}/external/python/lib/libpython3.so
                      ${CMAKE_CURRENT_BINARY_DIR}/stage/lib/libpython3.so)
  
  add_custom_command(TARGET Python PRE_BUILD
                      COMMAND ${CMAKE_COMMAND} -E copy
                      ${CMAKE_CURRENT_BINARY_DIR}/external/python/lib/libpython3.3m.so.1.0
                      ${CMAKE_CURRENT_BINARY_DIR}/stage/lib/libpython3.3m.so.1.0)
  
  add_custom_command(TARGET Python PRE_BUILD
                      COMMAND ${CMAKE_COMMAND} -E create_symlink
                      libpython3.3m.so.1.0
                      ${CMAKE_CURRENT_BINARY_DIR}/stage/lib/libpython3.3m.so)
  
  
  
  #Python 
  set(PYTHON_INCLUDE_DIRS "${CMAKE_CURRENT_BINARY_DIR}/external/python/include/python3.3m")
  set(PYTHON_LIBRARIES "${CMAKE_CURRENT_BINARY_DIR}/external/python/lib/libpython3.3m.so" "pthread" "m" "util" "readline")
  
  
  #Build boost via External Project
  ExternalProject_Add(
      Boost
      DEPENDS Python
      PREFIX ${CMAKE_CURRENT_BINARY_DIR}/external/boost
      URL ${CMAKE_CURRENT_SOURCE_DIR}/extern/boost_1_51_0_mwave.tar.bz2
      URL_MD5 fe203a243e451b4dd4754c7b283b1db9
      UPDATE_COMMAND ./bootstrap.sh --with-libraries=python,system,thread,program_options
      CONFIGURE_COMMAND ""
      BUILD_COMMAND ./b2
      BUILD_IN_SOURCE 1
      INSTALL_COMMAND ""
  )
  #Boost (workaround until external project is working)
  set(Boost_INCLUDE_DIRS "/opt/mwave/include")
  set(Boost_LIBRARIES "/opt/mwave/lib/libboost_python3.so" "/opt/mwave/lib/libboost_program_options.so")
  
  
  #OpenImageIO
  set(OIIO_PATH "/opt/mwave/oiio/dist/linux64.debug")
  find_package(OIIO REQUIRED)
  
  #Qt4
  find_package(Qt4 REQUIRED)
  set(QT_USE_QTOPENGL TRUE)
  include(${QT_USE_FILE})
  add_definitions(${QT_DEFINITIONS})
  
  #OpenGL
  find_package(OpenGL REQUIRED)
  
  find_package(GLEW REQUIRED)
  
  # Mwave app
  set(HEADERS
          "include/Application.h"
          "include/ImageChannel.h"
          "include/CompDag.h"
          "include/Dag.h"
          "include/Gui/DagView.h"
          "include/Gui/DagScene.h"
          "include/Gui/MainWindow.h"
          "include/Gui/GLViewer.h"
          "include/Gui/Nodes/GNodeEdge.h"
          "include/Gui/Nodes/GNodeLabel.h"
          "include/Gui/Nodes/GNodeCacheStatus.h"
          "include/Gui/Nodes/GNode.h"
          "include/Gui/Nodes/GRead.h"
          "include/Gui/Nodes/GViewer.h"
          "include/MwaveException.h"
          "include/Nodes/Node.h"
          "include/Nodes/Read.h"
          "include/Nodes/Viewer.h"
          "include/mwave.h"
          "include/main.h"
          "include/shaders.h"
  )
  
  set(QOBJECT_HEADERS
          "include/Gui/QCompDag.h"
          "include/Gui/QPythonEditor.h"
          "include/Gui/ViewerWidget.h"
  )
  
  set(SOURCES
          "src/Application.cpp"
          "src/CompDag.cpp"
          "src/main.cpp"
          "src/mwave.cpp"
          "src/Dag.cpp"
          "src/Gui/DagView.cpp"
          "src/Gui/DagScene.cpp"
          "src/Gui/MainWindow.cpp"
          "src/Gui/QPythonEditor.cpp"
          "src/Gui/GLViewer.cpp"
          "src/Gui/ViewerWidget.cpp"
          "src/Gui/Nodes/GNode.cpp"
          "src/Gui/Nodes/GNodeEdge.cpp"
          "src/Gui/QCompDag.cpp"
          "src/Nodes/Node.cpp"
          "src/Nodes/Read.cpp"
          "src/Nodes/Viewer.cpp"
  )
  
  QT4_WRAP_CPP(HEADERS_MOC ${QOBJECT_HEADERS})
  
  ## Compiler flags
  if(CMAKE_COMPILER_IS_GNUCXX)
      set(CMAKE_CXX_FLAGS "-O2")        ## Optimize
      set(CMAKE_CXX_FLAGS "-O3")        ## Optimize More
  endif()
  
  include_directories(${PYTHON_INCLUDE_DIRS}
                      ${Boost_INCLUDE_DIRS}
                      ${GLEW_INCLUDE_PATH}
                      ${OPENGL_INCLUDE_DIR}
                      ${OIIO_INCLUDE_DIR}
  )
  
  add_executable(mwave WIN32 ${HEADERS} ${HEADERS_MOC} ${SOURCES})
  set_target_properties(mwave PROPERTIES OUTPUT_NAME mwave.bin)
  
  target_link_libraries(  mwave
                          ${PYTHON_LIBRARIES}
                          ${Boost_LIBRARIES}
                          ${OIIO_LIBRARIES}
                          ${GLEW_LIBRARY}
                          ${OPENGL_LIBRARIES}
                          ${QT_LIBRARIES})
  </code></pre>