From b6864e66e7e4c50163a491f5d6b44ee63bd1729a Mon Sep 17 00:00:00 2001
From: Gennady Pospelov <g.pospelov@fz-juelich.de>
Date: Thu, 5 Dec 2013 21:53:30 +0100
Subject: [PATCH] Correction in CMake for cpp user example

---
 Core/CMakeLists.txt                           |  1 +
 .../ex001_CylindersAndPrisms/CMakeLists.txt   | 22 ++------
 .../modules/FindBornAgain.cmake               | 55 +++++++++++++++----
 3 files changed, 49 insertions(+), 29 deletions(-)

diff --git a/Core/CMakeLists.txt b/Core/CMakeLists.txt
index 30f0d688da4..6fc4c1761ec 100644
--- a/Core/CMakeLists.txt
+++ b/Core/CMakeLists.txt
@@ -98,6 +98,7 @@ endif()
 install (DIRECTORY ${CMAKE_SOURCE_DIR}/Examples/ DESTINATION ${destination_examples} COMPONENT Examples FILES_MATCHING PATTERN "*.py" )
 install (DIRECTORY ${CMAKE_SOURCE_DIR}/Examples/ DESTINATION ${destination_examples} COMPONENT Examples FILES_MATCHING PATTERN "refdata*.txt" )
 install (DIRECTORY ${CMAKE_SOURCE_DIR}/Examples/ DESTINATION ${destination_examples} COMPONENT Examples FILES_MATCHING PATTERN "README")
+install (DIRECTORY ${CMAKE_SOURCE_DIR}/Examples/cpp DESTINATION ${destination_examples} COMPONENT Examples)
 # the line below copies the contains ${CMAKE_SOURCE_DIR}/bin to the bin folder of the final package
 # install (DIRECTORY ${CMAKE_SOURCE_DIR}/bin DESTINATION . COMPONENT Libraries)
 
diff --git a/Examples/cpp/ex001_CylindersAndPrisms/CMakeLists.txt b/Examples/cpp/ex001_CylindersAndPrisms/CMakeLists.txt
index 163e9228cc2..5d83c4b7a58 100644
--- a/Examples/cpp/ex001_CylindersAndPrisms/CMakeLists.txt
+++ b/Examples/cpp/ex001_CylindersAndPrisms/CMakeLists.txt
@@ -4,8 +4,6 @@ project(CylindersAndPrisms)
 
 add_executable(CylindersAndPrisms CylindersAndPrisms.cpp)
 
-#set (CMAKE_CXX_FLAGS "-g")
-
 # path to the cmake modules
 set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/modules)
 
@@ -15,37 +13,27 @@ set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/modules)
 find_package(Eigen3 3.1.0)
 
 # --- BOOST ---
-set(Boost_USE_STATIC_LIBS OFF)
-set(Boost_USE_MULTITHREADED ON)
-set(Boost_USE_STATIC_RUNTIME OFF)
-#add_definitions(-DBOOST_ALL_DYN_LINK) # line is needed for MSVC
-
 set(boost_libraries_required date_time chrono program_options iostreams system filesystem regex thread)
-
 find_package(Boost 1.48.0 COMPONENTS ${boost_libraries_required} REQUIRED)
-
 message(STATUS "Boost_INCLUDE_DIRS: ${Boost_INCLUDE_DIRS}")
 message(STATUS "Boost_LIBRARY_DIRS: ${Boost_LIBRARY_DIRS}")
 message(STATUS "Boost_LIBRARIES: ${Boost_LIBRARIES}")
 
-#-------BornAgain----------------
-find_package(BornAgain)
+# --- BornAgain ---
+find_package(BornAgain REQUIRED)
 
 #-----ROOT------------
-find_package(ROOT)
-
+find_package(ROOT REQUIRED)
 
 include_directories(
     ${Boost_INCLUDE_DIRS}
     ${EIGEN3_INCLUDE_DIR}
     ${ROOT_INCLUDE_DIR}
-    ${BA_INCLUDE_DIR}
+    ${BORNAGAIN_INCLUDE_DIR}
 )
 
 target_link_libraries(CylindersAndPrisms
     ${Boost_LIBRARIES}
-    ${BA_LIBRARY}
+    ${BORNAGAIN_LIBRARIES}
     ${ROOT_LIBRARIES}
 )
-
-
diff --git a/Examples/cpp/ex001_CylindersAndPrisms/modules/FindBornAgain.cmake b/Examples/cpp/ex001_CylindersAndPrisms/modules/FindBornAgain.cmake
index b43f891f89e..ca9df52465a 100644
--- a/Examples/cpp/ex001_CylindersAndPrisms/modules/FindBornAgain.cmake
+++ b/Examples/cpp/ex001_CylindersAndPrisms/modules/FindBornAgain.cmake
@@ -1,17 +1,48 @@
-# - Finds BornAgain instalation
-# This module sets up BornAgain information 
+# Finds BornAgain instalation
 # It defines:
-# BA_INCLUDE_DIR    PATH to the include directory
-# BA_LIBRARY_DIR      PATH to the library directory
+# BORNAGAIN_INCLUDE_DIR  PATH to the include directory
+# BORNAGAIN_LIBRARIES    BornAgain libraries
 
-if(NOT BORNAGAINSYS)
-    set(BORNAGAINSYS /usr)
-endif(NOT BORNAGAINSYS)
+set(BORNAGAINSYS $ENV{BORNAGAINSYS})
 
-set(BA_LIBRARY_DIR ${BORNAGAINSYS}/lib)
-set(BA_INCLUDE_DIR ${BORNAGAINSYS}/include/BornAgain)
+if(BORNAGAINSYS)
+    set(BORNAGAIN_LIBRARY_DIR ${BORNAGAINSYS}/lib)
+    set(BORNAGAIN_INCLUDE_DIR ${BORNAGAINSYS}/include/BornAgain)
+endif()
 
-find_library (BA_LIBRARY
-        NAMES BornAgainCore BornAgainFit
-        PATHS ${BA_LIBRARY_DIR}
+find_library (BORNAGAIN_CORE BornAgainCore
+    PATHS ${BORNAGAIN_LIBRARY_DIR}
+    HINTS ${BORNAGAIN_LIBRARY_DIR}
 )
+
+find_library (BORNAGAIN_FIT BornAgainFit
+    PATHS ${BORNAGAIN_LIBRARY_DIR}
+    HINTS ${BORNAGAIN_LIBRARY_DIR}
+)
+set(BORNAGAIN_LIBRARIES ${BORNAGAIN_CORE} ${BORNAGAIN_FIT})
+
+find_path(BORNAGAIN_INCLUDE_DIR BAVersion.h
+    /usr/include/BornAgain
+    /usr/local/include/BornAgain
+    /opt/local/include/BornAgain
+    HINTS ${BORNAGAIN_INCLUDE_DIR}
+)
+
+# 32-bits systems require special Eigen options
+execute_process(COMMAND uname -m OUTPUT_VARIABLE SYSCTL_OUTPUT)
+if(NOT ${SYSCTL_OUTPUT} MATCHES x86_64)
+    add_definitions(-DEIGEN_DONT_ALIGN_STATICALLY=1)
+endif()
+
+message(STATUS "BORNAGAIN_LIBRARIES   ${BORNAGAIN_LIBRARIES}")
+message(STATUS "BORNAGAIN_INCLUDE_DIR ${BORNAGAIN_INCLUDE_DIR}")
+mark_as_advanced(BORNAGAIN_LIBRARIES BORNAGAIN_INCLUDE_DIR)
+
+if(NOT BORNAGAIN_LIBRARIES OR NOT BORNAGAIN_INCLUDE_DIR)
+   if(BornAgain_FIND_REQUIRED)
+       message( FATAL_ERROR "FindBornAgain: can't find BornAgain header or library" )
+   endif()
+endif()
+
+
+
-- 
GitLab