From 1b6adc81733cff83b806f6387b3fd94f68371d27 Mon Sep 17 00:00:00 2001
From: Andreas Schenk <andreas_schenk@hms.harvard.edu>
Date: Thu, 19 Jul 2012 10:13:02 -0400
Subject: [PATCH] modified cmake files to allow out of source build

---
 cmake_support/OST.cmake            | 22 ++++++++++++++++------
 deployment/CMakeLists.txt          |  2 +-
 modules/gfx/pymod/CMakeLists.txt   |  2 +-
 modules/gfx/src/CMakeLists.txt     |  4 ++--
 modules/gui/pymod/CMakeLists.txt   |  4 ++--
 modules/gui/share/CMakeLists.txt   |  4 ++--
 modules/mol/alg/src/CMakeLists.txt |  4 ++--
 scripts/CMakeLists.txt             |  2 +-
 8 files changed, 27 insertions(+), 17 deletions(-)

diff --git a/cmake_support/OST.cmake b/cmake_support/OST.cmake
index 70305fbb0..49ffbabe7 100644
--- a/cmake_support/OST.cmake
+++ b/cmake_support/OST.cmake
@@ -101,6 +101,10 @@ endmacro()
 #-------------------------------------------------------------------------------
 macro(stage_headers HEADERS HEADER_INSTALL_DIR TARGET SUB)
   set(FROM_DIR "./")
+  set(_HDR_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/${SUB}")
+  foreach(_HDR ${HEADERS})
+    list(APPEND _ABS_HEADER_NAMES ${_HDR_SOURCE_DIR}/${_HDR})
+  endforeach()
   # introduce a helper target to make sure the headers are staged before
   # building the library
   string(REPLACE "/" "_" _SUB_NO_SLASH "${SUB}")
@@ -113,8 +117,8 @@ macro(stage_headers HEADERS HEADER_INSTALL_DIR TARGET SUB)
   endif()
   add_custom_target("${_TARGET_NAME}" COMMENT "")
   set(HEADER_DIR "${HEADER_STAGE_PATH}/${HEADER_INSTALL_DIR}")
-  copy_if_different("${FROM_DIR}" "${HEADER_DIR}"
-                    "${HEADERS}" ""
+  copy_if_different("" "${HEADER_DIR}"
+                    "${_ABS_HEADER_NAMES}" ""
                     "${_TARGET_NAME}")
   add_dependencies("${TARGET}" "${_TARGET_NAME}")
   set_target_properties("${_TARGET_NAME}" PROPERTIES
@@ -269,7 +273,7 @@ macro(module)
           install(FILES ${_ABS_HEADER_NAMES} DESTINATION
                   "include/${_HEADER_OUTPUT_DIR}/${_DIR}")
           set(_HDR_STAGE_DIR "${_HEADER_OUTPUT_DIR}/${_DIR}")
-          stage_headers("${_ABS_HEADER_NAMES}" "${_HDR_STAGE_DIR}" 
+          stage_headers("${_HEADERS}" "${_HDR_STAGE_DIR}" 
                         "${_LIB_NAME}" "${_DIR}")
           set(_HEADERS)
         else()
@@ -287,7 +291,7 @@ macro(module)
       install(FILES ${_ABS_HEADER_NAMES} DESTINATION
               "include/${_HEADER_OUTPUT_DIR}")
       set(_HDR_STAGE_DIR "${_HEADER_OUTPUT_DIR}")
-      stage_headers("${_ABS_HEADER_NAMES}" "${_HDR_STAGE_DIR}" 
+      stage_headers("${_HEADERS}" "${_HDR_STAGE_DIR}" 
                     "${_LIB_NAME}" "")
     endif()
   endif()
@@ -415,7 +419,7 @@ macro(script)
     if (NOT _ARG_INPUT)
       message(FATAL_ERROR "script() can only substitute when INPUT is present.")    
     endif()
-    substitute(IN_FILE ${_INPUT} OUT_FILE ${_ARG_NAME} 
+    substitute(IN_FILE "${CMAKE_CURRENT_SOURCE_DIR}/${_INPUT}" OUT_FILE ${_ARG_NAME} 
                DICT ${_ARG_SUBSTITUTE})
   endif()
   install(FILES ${_ARG_NAME} DESTINATION ${_ARG_OUTPUT_DIR} 
@@ -579,6 +583,7 @@ macro(pymod)
           set(_ABS_PY_FILES)
           set(_PY_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/${_DIR}")
           foreach(_PY ${_PY_FILES})
+            MESSAGE("${_DIR}:${_PY}")
             list(APPEND _ABS_PY_FILES "${_PY_SOURCE_DIR}/${_PY}")
           endforeach()
           install(FILES ${_ABS_PY_FILES} DESTINATION
@@ -600,7 +605,12 @@ macro(pymod)
       if (_ARG_UI)
         add_dependencies("${_LIB_NAME}_pymod" "${_LIB_NAME}_ui"})
       endif()
-      copy_if_different("./" "${PYMOD_STAGE_DIR}" "${_PY_FILES}" "TARGETS"
+      set(_ABS_PY_FILES)
+      set(_PY_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
+      foreach(_PY ${_PY_FILES})
+        list(APPEND _ABS_PY_FILES "${_PY_SOURCE_DIR}/${_PY}")
+      endforeach()
+      copy_if_different("./" "${PYMOD_STAGE_DIR}" "${_ABS_PY_FILES}" "TARGETS"
                         "${_LIB_NAME}_pymod")
       add_dependencies("_${_LIB_NAME}" "${_LIB_NAME}_pymod")
       compile_py_files(_${_LIB_NAME} ${PYMOD_STAGE_DIR} ${_PY_FILES})
diff --git a/deployment/CMakeLists.txt b/deployment/CMakeLists.txt
index 96945a7a5..1a5558547 100644
--- a/deployment/CMakeLists.txt
+++ b/deployment/CMakeLists.txt
@@ -3,6 +3,6 @@
 include(Deployment)
 set(SUBST_DIC OST_VERSION="${OST_VERSION}")
 add_custom_target(deploymnt ALL)
-substitute(IN_FILE README.html.in OUT_FILE README.html 
+substitute(IN_FILE ${CMAKE_CURRENT_SOURCE_DIR}/README.html.in OUT_FILE README.html 
                DICT ${SUBST_DIC})
 add_subdirectory(win)
diff --git a/modules/gfx/pymod/CMakeLists.txt b/modules/gfx/pymod/CMakeLists.txt
index a3d8b251d..0ee14167c 100644
--- a/modules/gfx/pymod/CMakeLists.txt
+++ b/modules/gfx/pymod/CMakeLists.txt
@@ -26,7 +26,7 @@ pymod(NAME gfx CPP ${OST_GFX_PYMOD_SOURCES} PY __init__.py py_gfx_obj.py)
 set(GRADIENT_FILE
   gradients.xml
 )
-copy_if_different("./" "${STAGE_DIR}/share/openstructure/scene" 
+copy_if_different("${CMAKE_CURRENT_SOURCE_DIR}" "${STAGE_DIR}/share/openstructure/scene" 
                   "${GRADIENT_FILE}" "PRESET GRADIENTS" _ost_gfx)
                   
 install(FILES ${GRADIENT_FILE} DESTINATION "share/openstructure/scene")
\ No newline at end of file
diff --git a/modules/gfx/src/CMakeLists.txt b/modules/gfx/src/CMakeLists.txt
index 7a92969a9..57cf1601f 100644
--- a/modules/gfx/src/CMakeLists.txt
+++ b/modules/gfx/src/CMakeLists.txt
@@ -269,7 +269,7 @@ if (USE_SHADER)
     shader/material_toon1.glsl
     shader/material_toon2.glsl
   )
-  copy_if_different("./" "${SHARED_DATA_PATH}/shader" "${SHADER_FILES}" 
+  copy_if_different("${CMAKE_CURRENT_SOURCE_DIR}" "${SHARED_DATA_PATH}/shader" "${SHADER_FILES}" 
                     "SHADER_TARGETS" ost_gfx)  
   install(FILES ${SHADER_FILES} DESTINATION "share/openstructure/shader")
 endif(USE_SHADER)
@@ -277,7 +277,7 @@ set(TEXTURE_FILES
   test_texture.png
   glyph_texture.png
 )
-copy_if_different("./" "${SHARED_DATA_PATH}/textures" "${TEXTURE_FILES}" 
+copy_if_different("${CMAKE_CURRENT_SOURCE_DIR}" "${SHARED_DATA_PATH}/textures" "${TEXTURE_FILES}" 
                   "TEXTURE_TARGETS" ost_gfx)  
 
 install(FILES ${TEXTURE_FILES} DESTINATION "share/openstructure/textures")
diff --git a/modules/gui/pymod/CMakeLists.txt b/modules/gui/pymod/CMakeLists.txt
index 9a623a9a1..122745ba4 100644
--- a/modules/gui/pymod/CMakeLists.txt
+++ b/modules/gui/pymod/CMakeLists.txt
@@ -104,7 +104,7 @@ set(PRESET_FILES
   scene/presets.xml
   scene/loaders.xml
 )
-copy_if_different("./" "${STAGE_DIR}/share/openstructure/scene" 
+copy_if_different("${CMAKE_CURRENT_SOURCE_DIR}" "${STAGE_DIR}/share/openstructure/scene" 
                   "${PRESET_FILES}" "IMMUTABLE_FILES" _ost_gui)
 install(FILES ${PRESET_FILES} DESTINATION "share/openstructure/scene")
 
@@ -114,7 +114,7 @@ set(INSPECTOR_ICONS
   scene/icons/render_icon.png
   scene/icons/tool_icon.png
 )
-copy_if_different("./" "${STAGE_DIR}/share/openstructure/scene/icons" 
+copy_if_different("${CMAKE_CURRENT_SOURCE_DIR}" "${STAGE_DIR}/share/openstructure/scene/icons" 
                   "${INSPECTOR_ICONS}" "ICONS_FOR_INSPECTOR" _ost_gui)
 install(FILES ${INSPECTOR_ICONS} DESTINATION "share/openstructure/scene/icons")
 
diff --git a/modules/gui/share/CMakeLists.txt b/modules/gui/share/CMakeLists.txt
index 816af7f80..de3daf8d8 100644
--- a/modules/gui/share/CMakeLists.txt
+++ b/modules/gui/share/CMakeLists.txt
@@ -23,11 +23,11 @@ set(GUI_IMAGES
 )
 
 add_custom_target(scene_icons ALL)
-copy_if_different("./" "${STAGE_DIR}/share/openstructure/gui/icons" 
+copy_if_different("${CMAKE_CURRENT_SOURCE_DIR}" "${STAGE_DIR}/share/openstructure/gui/icons" 
                   "${GUI_ICONS}" "ICONS_FOR_GUI" scene_icons)
 install(FILES ${GUI_ICONS} DESTINATION "share/openstructure/gui/icons")
 
 add_custom_target(gui_images ALL)
-copy_if_different("./" "${STAGE_DIR}/share/openstructure/gui/images" 
+copy_if_different("${CMAKE_CURRENT_SOURCE_DIR}" "${STAGE_DIR}/share/openstructure/gui/images" 
                   "${GUI_IMAGES}" "IMAGES_FOR_GUI" gui_images)
 install(FILES ${GUI_IMAGES} DESTINATION "share/openstructure/gui/images")
\ No newline at end of file
diff --git a/modules/mol/alg/src/CMakeLists.txt b/modules/mol/alg/src/CMakeLists.txt
index 146717ace..b91dd1e42 100644
--- a/modules/mol/alg/src/CMakeLists.txt
+++ b/modules/mol/alg/src/CMakeLists.txt
@@ -48,12 +48,12 @@ module(NAME mol_alg SOURCES ${OST_MOL_ALG_SOURCES}
        DEPENDS_ON ${MOL_ALG_DEPS}
        LINK ${BOOST_PROGRAM_OPTIONS})
 
-copy_if_different("." "${STAGE_DIR}/share/openstructure"
+copy_if_different("${CMAKE_CURRENT_SOURCE_DIR}" "${STAGE_DIR}/share/openstructure"
                   "atom_scattering_properties.txt" "ATOM_SCATTERING_PROPS"
                   "ost_mol_alg")
 install(FILES "atom_scattering_properties.txt" DESTINATION "share/openstructure/")
 
-copy_if_different("." "${STAGE_DIR}/share/openstructure"
+copy_if_different("${CMAKE_CURRENT_SOURCE_DIR}" "${STAGE_DIR}/share/openstructure"
                   "stereo_chemical_props.txt" "STEREO_CHEMICAL_PROPS"
                   "ost_mol_alg")
 install(FILES "stereo_chemical_props.txt" DESTINATION "share/openstructure/")
diff --git a/scripts/CMakeLists.txt b/scripts/CMakeLists.txt
index 0b6b429a4..652d98238 100644
--- a/scripts/CMakeLists.txt
+++ b/scripts/CMakeLists.txt
@@ -37,7 +37,7 @@ if (NOT ENABLE_STATIC)
   if (ENABLE_GUI)
     list(APPEND INIT_SCRIPTS init.py)
   endif()
-  copy_if_different("./" "${STAGE_DIR}/${LIB_DIR}/openstructure" 
+  copy_if_different("${CMAKE_CURRENT_SOURCE_DIR}" "${STAGE_DIR}/${LIB_DIR}/openstructure" 
                   "${INIT_SCRIPTS}" "python init scripts" ost_scripts)
 
   install(FILES ${INIT_SCRIPTS} DESTINATION "${LIB_DIR}/openstructure")
-- 
GitLab