From c4d8de6ecf1c97c2e18a8de72728c7ef55b3b336 Mon Sep 17 00:00:00 2001
From: Gennady Pospelov <g.pospelov@fz-juelich.de>
Date: Tue, 27 Oct 2015 10:21:08 +0100
Subject: [PATCH] Global option BORNAGAIN_TIFF_SUPPORT in cmake machinery was
 added.

---
 CMakeLists.txt                                |  8 +--
 Core/CMakeLists.txt                           |  5 +-
 Core/InputOutput/OutputDataReadFactory.cpp    |  3 +
 Core/InputOutput/OutputDataReadStrategy.cpp   |  3 +
 Core/InputOutput/OutputDataReadStrategy.h     |  2 +
 Core/InputOutput/OutputDataWriteFactory.cpp   |  2 +
 Core/InputOutput/OutputDataWriteStrategy.cpp  |  3 +-
 Core/InputOutput/OutputDataWriteStrategy.h    |  3 +
 Core/InputOutput/TiffHandler.cpp              |  4 +-
 Core/InputOutput/TiffHandler.h                |  3 +
 .../FunctionalTests/TestPyCore/CMakeLists.txt |  5 ++
 .../TestPyCore/intensitydata_io.py            | 19 ------
 .../TestPyCore/intensitydata_io_tiff.py       | 67 +++++++++++++++++++
 ThirdParty/CMakeLists.txt                     | 10 +++
 ThirdParty/RootMinimizers/CMakeLists.txt      |  4 +-
 cmake/modules/SearchInstalledSoftware.cmake   |  5 +-
 16 files changed, 113 insertions(+), 33 deletions(-)
 create mode 100644 Tests/FunctionalTests/TestPyCore/intensitydata_io_tiff.py
 create mode 100644 ThirdParty/CMakeLists.txt

diff --git a/CMakeLists.txt b/CMakeLists.txt
index ff1dcc2e5fd..3edc19ad8d2 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -20,6 +20,7 @@ option(BORNAGAIN_APPLE_BUNDLE "Create a Mac OS X bundle" OFF)
 option(BORNAGAIN_OPENMPI "Build with OpenMPI support" OFF)
 option(BORNAGAIN_RELEASE "Special option for making release" OFF)
 option(BORNAGAIN_CRASHHADLER "Additional machinery to send crash reports" OFF)
+option(BORNAGAIN_TIFF_SUPPORT "Tiff files read/write support" ON)
 
 #--- Including macros ---
 set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules)
@@ -36,14 +37,9 @@ if(BORNAGAIN_MANPAGE)
     add_subdirectory(man)
 endif()
 
-if(NOT TIFF_FOUND)
-add_subdirectory(ThirdParty/libtiff)
-endif()
+add_subdirectory(ThirdParty)
 add_subdirectory(Core)
-add_subdirectory(ThirdParty/gtest)
-
 add_subdirectory(Tests/UnitTests/TestCore)
-add_subdirectory(ThirdParty/RootMinimizers)
 add_subdirectory(Fit)
 add_subdirectory(Tests/UnitTests/TestFit)
 
diff --git a/Core/CMakeLists.txt b/Core/CMakeLists.txt
index c0afbd35484..264d549066f 100644
--- a/Core/CMakeLists.txt
+++ b/Core/CMakeLists.txt
@@ -66,6 +66,9 @@ if(BORNAGAIN_OPENMPI)
     add_definitions(-DBORNAGAIN_OPENMPI)
 endif()
 
+if(BORNAGAIN_TIFF_SUPPORT)
+    add_definitions(-DBORNAGAIN_TIFF_SUPPORT)
+endif()
 
 # --- making library ---------
 add_library(
@@ -96,8 +99,6 @@ target_link_libraries(
     ${TIFF_LIBRARIES}
 )
 
-message(INFO "XXX lib ${TIFF_LIBRARIES} include ${TIFF_INCLUDE_DIR}")
-
 if(BORNAGAIN_OPENMPI)
     include_directories(${MPI_INCLUDE_PATH})
     target_link_libraries(${library_name} ${MPI_LIBRARIES})
diff --git a/Core/InputOutput/OutputDataReadFactory.cpp b/Core/InputOutput/OutputDataReadFactory.cpp
index 085f7c7b340..0d4e7c97d11 100644
--- a/Core/InputOutput/OutputDataReadFactory.cpp
+++ b/Core/InputOutput/OutputDataReadFactory.cpp
@@ -36,10 +36,13 @@ IOutputDataReadStrategy *OutputDataReadFactory::getReadStrategy(const std::strin
         result = new OutputDataReadINTStrategy();
     }
 
+#ifdef BORNAGAIN_TIFF_SUPPORT
     else if(OutputDataIOHelper::isTiffFile(file_name)) {
        result = new OutputDataReadTiffStrategy();
     }
 
+#endif // BORNAGAIN_TIFF_SUPPORT
+
     else {
         throw LogicErrorException("OutputDataReadFactory::getReader() -> Error. "
                 "Don't know how to read file '" + file_name+std::string("'"));
diff --git a/Core/InputOutput/OutputDataReadStrategy.cpp b/Core/InputOutput/OutputDataReadStrategy.cpp
index ce1543a6b31..8f318df0b3b 100644
--- a/Core/InputOutput/OutputDataReadStrategy.cpp
+++ b/Core/InputOutput/OutputDataReadStrategy.cpp
@@ -47,6 +47,7 @@ OutputData<double > *OutputDataReadINTStrategy::readOutputData(std::istream &inp
 
 // ----------------------------------------------------------------------------
 
+#ifdef BORNAGAIN_TIFF_SUPPORT
 OutputDataReadTiffStrategy::OutputDataReadTiffStrategy()
     : m_d(new TiffHandler)
 {
@@ -63,3 +64,5 @@ OutputData<double> *OutputDataReadTiffStrategy::readOutputData(std::istream &inp
     m_d->read(input_stream);
     return m_d->getOutputData()->clone();
 }
+
+#endif // BORNAGAIN_TIFF_SUPPORT
diff --git a/Core/InputOutput/OutputDataReadStrategy.h b/Core/InputOutput/OutputDataReadStrategy.h
index e687a9b2894..c8c98d42ffa 100644
--- a/Core/InputOutput/OutputDataReadStrategy.h
+++ b/Core/InputOutput/OutputDataReadStrategy.h
@@ -42,6 +42,7 @@ public:
     OutputData<double > *readOutputData(std::istream& input_stream);
 };
 
+#ifdef BORNAGAIN_TIFF_SUPPORT
 
 class TiffHandler;
 
@@ -58,6 +59,7 @@ public:
 private:
     TiffHandler *m_d;
 };
+#endif // BORNAGAIN_TIFF_SUPPORT
 
 #endif // OUTPUTDATAREADSTRATEGY_H
 
diff --git a/Core/InputOutput/OutputDataWriteFactory.cpp b/Core/InputOutput/OutputDataWriteFactory.cpp
index 10992c8f742..6d0145ccf2d 100644
--- a/Core/InputOutput/OutputDataWriteFactory.cpp
+++ b/Core/InputOutput/OutputDataWriteFactory.cpp
@@ -33,9 +33,11 @@ IOutputDataWriteStrategy *OutputDataWriteFactory::getWriteStrategy(const std::st
         result = new OutputDataWriteINTStrategy();
     }
 
+#ifdef BORNAGAIN_TIFF_SUPPORT
     else if(OutputDataIOHelper::isTiffFile(file_name)) {
         result = new OutputDataWriteTiffStrategy();
     }
+#endif // BORNAGAIN_TIFF_SUPPORT
 
     else {
         throw LogicErrorException("OutputDataWriteFactory::getWriter() -> Error. "
diff --git a/Core/InputOutput/OutputDataWriteStrategy.cpp b/Core/InputOutput/OutputDataWriteStrategy.cpp
index 7cf2c7e1b39..137e8e32d21 100644
--- a/Core/InputOutput/OutputDataWriteStrategy.cpp
+++ b/Core/InputOutput/OutputDataWriteStrategy.cpp
@@ -53,7 +53,7 @@ void OutputDataWriteINTStrategy::writeOutputData(const OutputData<double> &data,
 // ----------------------------------------------------------------------------
 
 
-
+#ifdef BORNAGAIN_TIFF_SUPPORT
 
 OutputDataWriteTiffStrategy::OutputDataWriteTiffStrategy()
     : m_d(new TiffHandler)
@@ -72,5 +72,6 @@ void OutputDataWriteTiffStrategy::writeOutputData(const OutputData<double> &data
     m_d->write(data, output_stream);
 }
 
+#endif
 
 
diff --git a/Core/InputOutput/OutputDataWriteStrategy.h b/Core/InputOutput/OutputDataWriteStrategy.h
index 6f8784b9928..42ef6b2ddd3 100644
--- a/Core/InputOutput/OutputDataWriteStrategy.h
+++ b/Core/InputOutput/OutputDataWriteStrategy.h
@@ -46,6 +46,8 @@ public:
     virtual void writeOutputData(const OutputData<double> &data, std::ostream &output_stream);
 };
 
+#ifdef BORNAGAIN_TIFF_SUPPORT
+
 class TiffHandler;
 
 //! @class OutputDataWriteTiffStrategy
@@ -61,6 +63,7 @@ private:
     TiffHandler *m_d;
 };
 
+#endif // BORNAGAIN_TIFF_SUPPORT
 
 #endif // OUTPUTDATAWRITESTRATEGY_H
 
diff --git a/Core/InputOutput/TiffHandler.cpp b/Core/InputOutput/TiffHandler.cpp
index f092c1d322a..52dcb331547 100644
--- a/Core/InputOutput/TiffHandler.cpp
+++ b/Core/InputOutput/TiffHandler.cpp
@@ -12,6 +12,7 @@
 //! @authors   C. Durniak, M. Ganeva, G. Pospelov, W. Van Herck, J. Wuttke
 //
 // ************************************************************************** //
+#ifdef BORNAGAIN_TIFF_SUPPORT
 #include "TiffHandler.h"
 #include "Exceptions.h"
 #include "Utils.h"
@@ -209,5 +210,4 @@ void TiffHandler::create_output_data()
     m_data->addAxis("y", m_height, 0.0, double(m_height));
 }
 
-
-
+#endif // BORNAGAIN_TIFF_SUPPORT
diff --git a/Core/InputOutput/TiffHandler.h b/Core/InputOutput/TiffHandler.h
index a786155c1af..8b1b37bc7c1 100644
--- a/Core/InputOutput/TiffHandler.h
+++ b/Core/InputOutput/TiffHandler.h
@@ -16,6 +16,8 @@
 #ifndef TIFFHANDLER_H
 #define TIFFHANDLER_H
 
+#ifdef BORNAGAIN_TIFF_SUPPORT
+
 #include "WinDllMacros.h"
 #include "OutputData.h"
 #include <string>
@@ -53,6 +55,7 @@ private:
     boost::scoped_ptr<OutputData<double> > m_data;
 };
 
+#endif // BORNAGAIN_TIFF_SUPPORT
 
 #endif
 
diff --git a/Tests/FunctionalTests/TestPyCore/CMakeLists.txt b/Tests/FunctionalTests/TestPyCore/CMakeLists.txt
index 62a7d0c7bb7..6848f0fa616 100644
--- a/Tests/FunctionalTests/TestPyCore/CMakeLists.txt
+++ b/Tests/FunctionalTests/TestPyCore/CMakeLists.txt
@@ -54,6 +54,11 @@ set(list_of_python_tests
 #    "transform_BoxComposition.py" # broken, problems with absoprtion in FormFactorTruncatedSphere
 )
 
+if(BORNAGAIN_TIFF_SUPPORT)
+    list(APPEND list_of_python_tests "intensitydata_io_tiff.py")
+endif()
+
+
 foreach(_test ${list_of_python_tests})
     add_test(${_test} ${PYTHON_EXECUTABLE} "${CMAKE_BINARY_DIR}/Tests/FunctionalTests/TestPyCore/${_test}")
 endforeach()
diff --git a/Tests/FunctionalTests/TestPyCore/intensitydata_io.py b/Tests/FunctionalTests/TestPyCore/intensitydata_io.py
index 6dc32309370..d507f9bc6e3 100644
--- a/Tests/FunctionalTests/TestPyCore/intensitydata_io.py
+++ b/Tests/FunctionalTests/TestPyCore/intensitydata_io.py
@@ -148,24 +148,5 @@ class OutputDataIOTest(unittest.TestCase):
         newdata = IntensityDataIOFactory.readOutputData("tmp.int.bz2")
         self.assertTrue(is_the_same_data(data, newdata))
 
-    def test_SaveToTiff(self):
-        data = IntensityData()
-        data.addAxis(FixedBinAxis("x", 10, 0.0, 10.0))
-        data.addAxis(FixedBinAxis("y", 5, 0.0, 5.0))
-        fill_data(data)
-
-        IntensityDataIOFactory.writeOutputData(data, "tmp.tif")
-        newdata = IntensityDataIOFactory.readOutputData("tmp.tif")
-        self.assertTrue(is_the_same_data(data, newdata))
-
-        IntensityDataIOFactory.writeOutputData(data, "tmp.tif.gz")
-        newdata = IntensityDataIOFactory.readOutputData("tmp.tif.gz")
-        self.assertTrue(is_the_same_data(data, newdata))
-
-        IntensityDataIOFactory.writeOutputData(data, "tmp.tif.bz2")
-        newdata = IntensityDataIOFactory.readOutputData("tmp.tif.bz2")
-        self.assertTrue(is_the_same_data(data, newdata))
-
-
 if __name__ == '__main__':
     unittest.main()
diff --git a/Tests/FunctionalTests/TestPyCore/intensitydata_io_tiff.py b/Tests/FunctionalTests/TestPyCore/intensitydata_io_tiff.py
new file mode 100644
index 00000000000..bf0069538cc
--- /dev/null
+++ b/Tests/FunctionalTests/TestPyCore/intensitydata_io_tiff.py
@@ -0,0 +1,67 @@
+# Functional test: tests of IO operations with the IntensityData object
+
+import sys
+import os
+import unittest
+import numpy
+import math
+import time
+
+sys.path.append(os.path.abspath(
+                os.path.join(os.path.split(__file__)[0],
+                '..', '..', '..', 'lib')))
+
+from libBornAgainCore import *
+
+
+def fill_data(data):
+    """
+    Fills intensity data with some numbers
+    """
+    for i in range(0, data.getAllocatedSize()):
+        data[i] = i
+
+
+def is_the_same_data(data1, data2):
+    """
+    Checks if two data are identical
+    """
+    if data1.getAllocatedSize() != data2.getAllocatedSize():
+        return False
+    if data1.getRank() != data2.getRank():
+        return False
+    for i in range(0, data1.getRank()):
+        if data1.getAxis(i) != data2.getAxis(i):
+            return False
+    for i in range(0, data1.getAllocatedSize()):
+        if data1[i] != data2[i]:
+            return False
+
+    return True
+
+
+class OutputDataIOTiffTest(unittest.TestCase):
+    """
+    Test serialization of IntensityData into TIFF format
+    """
+    def test_SaveToTiff(self):
+        data = IntensityData()
+        data.addAxis(FixedBinAxis("x", 10, 0.0, 10.0))
+        data.addAxis(FixedBinAxis("y", 5, 0.0, 5.0))
+        fill_data(data)
+
+        IntensityDataIOFactory.writeOutputData(data, "tmp.tif")
+        newdata = IntensityDataIOFactory.readOutputData("tmp.tif")
+        self.assertTrue(is_the_same_data(data, newdata))
+
+        IntensityDataIOFactory.writeOutputData(data, "tmp.tif.gz")
+        newdata = IntensityDataIOFactory.readOutputData("tmp.tif.gz")
+        self.assertTrue(is_the_same_data(data, newdata))
+
+        IntensityDataIOFactory.writeOutputData(data, "tmp.tif.bz2")
+        newdata = IntensityDataIOFactory.readOutputData("tmp.tif.bz2")
+        self.assertTrue(is_the_same_data(data, newdata))
+
+
+if __name__ == '__main__':
+    unittest.main()
diff --git a/ThirdParty/CMakeLists.txt b/ThirdParty/CMakeLists.txt
new file mode 100644
index 00000000000..d572b249fa5
--- /dev/null
+++ b/ThirdParty/CMakeLists.txt
@@ -0,0 +1,10 @@
+# Compilation of ThirdParty dependencies
+
+if(BORNAGAIN_TIFF_SUPPORT)
+    if(NOT TIFF_FOUND)
+        add_subdirectory(libtiff)
+    endif()
+endif()
+
+add_subdirectory(gtest)
+add_subdirectory(RootMinimizers)
diff --git a/ThirdParty/RootMinimizers/CMakeLists.txt b/ThirdParty/RootMinimizers/CMakeLists.txt
index b3686366313..a7323b1df76 100644
--- a/ThirdParty/RootMinimizers/CMakeLists.txt
+++ b/ThirdParty/RootMinimizers/CMakeLists.txt
@@ -34,8 +34,8 @@ add_library(
     STATIC
     ${source_files} ${include_files}
 )
-set(${library_name}_INCLUDE_DIRS ${include_dirs} PARENT_SCOPE)
-set(${library_name}_LIBRARY ${library_name} PARENT_SCOPE)
+set(${library_name}_INCLUDE_DIRS ${include_dirs} CACHE INTERNAL "")
+set(${library_name}_LIBRARY ${library_name} CACHE INTERNAL "")
 
 # --- external dependencies ---
 include_directories(${GSL_INCLUDE_DIR})
diff --git a/cmake/modules/SearchInstalledSoftware.cmake b/cmake/modules/SearchInstalledSoftware.cmake
index e3c72cc08f7..bb290fd19c8 100644
--- a/cmake/modules/SearchInstalledSoftware.cmake
+++ b/cmake/modules/SearchInstalledSoftware.cmake
@@ -39,7 +39,8 @@ find_package(GSL REQUIRED)
 # -----------------------------------------------------------------------------
 # Tiff
 # -----------------------------------------------------------------------------
-#find_package(TIFF)
+if(BORNAGAIN_TIFF_SUPPORT)
+find_package(TIFF)
 
 # check if tiff setup contains C++ version of library too
 # i.e. TIFF_LIBRARIES should be /usr/lib64/libtiff.so;/usr/lib64/libtiffxx.so
@@ -68,6 +69,8 @@ if(TIFF_FOUND)
 else()
     message(STATUS "No TIFF library found, local version will be build.")
 endif()
+endif()
+
 
 
 # --- Python ---
-- 
GitLab