Description: Modify CmakeLists for Debian
 Avoid using the boundled libraries but link the system ones.
Author: Don Armstrong <don@debian.org>
Author: Mattia Rizzolo <mattia@mapreri.org>
Author: Francois Mazen <francois@mzf.fr>
Forwarded: no
Last-Update: 2018-05-02



--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -42,7 +42,6 @@
 
 # The parsing order is significant!
 
-add_subdirectory( src/BoostParts )
 # Set these so zipios doesn't complain.
 set( Boost_DATE_TIME_LIBRARY 1 )
 set( Boost_FILESYSTEM_LIBRARY 1 )
@@ -51,21 +50,14 @@
 set( Boost_SYSTEM_LIBRARY 1 )
 set( Boost_THREAD_LIBRARY 1 )
 set( BOOST_LIBS BoostParts )
-set( BOOST_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/src/BoostParts )
 
-add_subdirectory( src/Xerces )
 set( XERCES_LIBRARIES Xerces )
-set( XERCES_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/src/Xerces )
 
 add_subdirectory( src/XercesExtensions )
 set( XERCESEXTENSIONS_LIBRARIES XercesExtensions )
 set( XERCESEXTENSIONS_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/src/XercesExtensions )
 
-add_subdirectory( src/zlib )
 add_subdirectory( src/zipios )
-if( NOT MINGW )
-    add_subdirectory( src/googlemock )
-endif()
 
 add_subdirectory( src/FlightCrew )
 set( FLIGHTCREW_LIBRARIES FlightCrew )
--- a/src/FlightCrew-cli/CMakeLists.txt
+++ b/src/FlightCrew-cli/CMakeLists.txt
@@ -63,6 +63,7 @@
 # "Print all warnings" flag for GCC
 elseif( CMAKE_COMPILER_IS_GNUCXX )
     add_definitions( -Wall )
+    set_target_properties( ${PROJECT_NAME} PROPERTIES LINK_FLAGS -Wl,--as-needed )
 endif()
 
 set_source_files_properties( main.cpp PROPERTIES COMPILE_DEFINITIONS FLIGHTCREW_FULL_VERSION="${FLIGHTCREW_FULL_VERSION}" )
--- a/src/FlightCrew/CMakeLists.txt
+++ b/src/FlightCrew/CMakeLists.txt
@@ -52,9 +52,7 @@
 
 # creating PCH's for MSVC and GCC on Linux
 include( ${CMAKE_SOURCE_DIR}/cmake_extras/CustomPCH.cmake )
-set( ALL_INCLUDES ${BoostParts_SOURCE_DIR}
-                  ${Xerces_SOURCE_DIR}
-                  ${zipios_SOURCE_DIR} )
+set( ALL_INCLUDES ${zipios_SOURCE_DIR} )
 set( GCC_PCH_TARGET gccPCH_fc )
 
 if( NOT SKIP_PCH )
@@ -67,8 +65,6 @@
 # and the headers for the linked-to libraries
 include_directories( ${CMAKE_CURRENT_SOURCE_DIR}
                      ../zipios
-                     ../BoostParts 
-                     ../Xerces
                      ../XercesExtensions
                      ../utf8-cpp
                    )
@@ -85,11 +81,29 @@
     # when they want a dll, but NOT FC_DLL_EXPORTING
     add_definitions( -DFC_DLL_EXPORTING -DFC_BUILT_AS_DLL )
     add_library( ${PROJECT_NAME} SHARED ${SOURCES} )
+    SET_TARGET_PROPERTIES(
+      ${PROJECT_NAME}
+      PROPERTIES
+      SOVERSION 0
+      VERSION 0.9.3
+      )
 else()
     add_library( ${PROJECT_NAME} STATIC ${SOURCES} )
 endif()
 
-target_link_libraries( ${PROJECT_NAME} zipios BoostParts XercesExtensions )
+find_library(LIB_ZLIB z)
+find_library(BOOST_DT boost_date_time)
+find_library(BOOST_FS boost_filesystem)
+find_library(BOOST_PO boost_program_options)
+find_library(BOOST_RE boost_regex)
+find_library(BOOST_S boost_system)
+find_library(BOOST_T boost_thread)
+find_library(LIB_XERCES xerces-c)
+find_library(PTHREAD pthread)
+SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES LINK_FLAGS -Wl,--as-needed)
+target_link_libraries( ${PROJECT_NAME} ${LIB_ZLIB} ${BOOST_DT} ${BOOST_FS} ${BOOST_PO} ${BOOST_RE} ${BOOST_S} ${BOOST_T} zipios ${LIB_XERCES} XercesExtensions ${PTHREAD} )
+INSTALL(TARGETS ${PROJECT_NAME} LIBRARY DESTINATION lib COMPONENT libraries)
+INSTALL(FILES flightcrew.h exception.h DllExporting.h Result.h Misc/ErrorResultCollector.h ResultId.h ResultType.h ../XercesExtensions/NodeLocationInfo.h DESTINATION include/${PROJECT_NAME})
 
 #############################################################################
 
@@ -126,8 +140,6 @@
 	endif()
 endif()
 
-# needed for correct Xerces header inclusion
-add_definitions( -DXERCES_STATIC_LIBRARY )
 
 #############################################################################
 
--- a/src/FlightCrew-gui/CMakeLists.txt
+++ b/src/FlightCrew-gui/CMakeLists.txt
@@ -82,7 +82,6 @@
 include_directories( BEFORE
                      ${CMAKE_CURRENT_SOURCE_DIR}
                      ${CMAKE_CURRENT_BINARY_DIR}
-                     ${BoostParts_SOURCE_DIR}
                      ${FlightCrew_SOURCE_DIR}
                      ${XercesExtensions_SOURCE_DIR}
                      )
@@ -134,6 +133,7 @@
 # "Print all warnings" flag for GCC
 elseif( CMAKE_COMPILER_IS_GNUCXX )
     add_definitions( -Wall )
+    set_target_properties( ${PROJECT_NAME} PROPERTIES LINK_FLAGS -Wl,--as-needed )
 endif()
 
 set_source_files_properties( MainWindow.cpp PROPERTIES COMPILE_DEFINITIONS FLIGHTCREW_FULL_VERSION="${FLIGHTCREW_FULL_VERSION}" )
@@ -159,6 +159,10 @@
                         WORKING_DIRECTORY ${WORK_DIR}
                         DEPENDS addframeworks )
                 
+elseif(DEBIAN)
+        # these rules are so that we don't do any crazy installer
+        #  building which we've stripped out anyway
+        set( WORK_DIR "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}" )
 # For Linux and Windows, provide binary installers.
 # For this to work on Linux, InstallJammer needs to be installed and on the system path.
 # For this to work on Windows, Inno Setup's iscc compiler needs to be installed and on the system path.
--- a/src/FlightCrew/tests/CMakeLists.txt
+++ b/src/FlightCrew/tests/CMakeLists.txt
@@ -41,12 +41,12 @@
 # That means that subdirs inherit the include_directories of their parents.
 # So techincally we don't need to include Xerces etc.
 include_directories( ${CMAKE_CURRENT_BINARY_DIR} 
-                     ${CMAKE_CURRENT_SOURCE_DIR} 
-                     ../../BoostParts 
-                     ../../Xerces 
                      ../../XercesExtensions 
-                     ../../googlemock/include
-                     ../../googlemock/gtest/include
+                     /usr/src/googletest/googlemock/include
+                     /usr/src/googletest/googlemock
+                     /usr/src/googletest/googletest/include
+                     /usr/src/googletest/googletest
+                     ${CMAKE_CURRENT_SOURCE_DIR}
                    )
 
 link_directories ( ${PROJECT_BINARY_DIR}/lib ) 
@@ -55,7 +55,7 @@
 
 # creating PCH's for MSVC and GCC on Linux
 include( ${CMAKE_SOURCE_DIR}/cmake_extras/CustomPCH.cmake )
-set( ALL_INCLUDES ${gtest_SOURCE_DIR}/include ${BoostParts_SOURCE_DIR} )
+set( ALL_INCLUDES /usr/src/googletest/googletest/include ${BoostParts_SOURCE_DIR} )
 
 set( GCC_PCH_TARGET gccPCH_tests )
 
@@ -65,7 +65,12 @@
 
 add_executable( ${PROJECT_NAME} ${TEST_SOURCES} )
 
-target_link_libraries( ${PROJECT_NAME} FlightCrew gmock )
+add_library( GOOGLE_MOCK_LIB STATIC
+    /usr/src/googletest/googlemock/src/gmock-all.cc
+    /usr/src/googletest/googletest/src/gtest-all.cc
+)
+
+target_link_libraries( ${PROJECT_NAME} FlightCrew GOOGLE_MOCK_LIB )
 
 #############################################################################
 
@@ -100,9 +105,6 @@
     add_dependencies( ${PROJECT_NAME} ${GCC_PCH_TARGET} )
 endif()
 
-# needed for correct Xerces header inclusion
-add_definitions( -DXERCES_STATIC_LIBRARY )
-
 #############################################################################
 
 # The test executable expects a "test_data" dir in its working directory.
--- a/src/XercesExtensions/CMakeLists.txt
+++ b/src/XercesExtensions/CMakeLists.txt
@@ -15,15 +15,14 @@
 
 # We need to pick up the stdafx.h file
 # and the headers for the linked-to libraries
-include_directories( ${CMAKE_CURRENT_SOURCE_DIR}
-                     ${XERCES_INCLUDE_DIRS}
-                     ${BOOST_INCLUDE_DIRS} )
+include_directories( ${CMAKE_CURRENT_SOURCE_DIR})
 
 link_directories ( ${PROJECT_BINARY_DIR}/lib ) 
 
 add_library( ${PROJECT_NAME} STATIC ${SOURCES} )
 
-target_link_libraries( ${PROJECT_NAME} ${XERCES_LIBRARIES} )
+find_library(LIB_XERCES xerces-c)
+target_link_libraries( ${PROJECT_NAME} ${LIB_XERCES} )
 
 #############################################################################
 
@@ -45,11 +44,7 @@
 
 # "Print all warnings" flag for GCC
 elseif( CMAKE_COMPILER_IS_GNUCXX )
+    SET_TARGET_PROPERTIES( ${PROJECT_NAME} PROPERTIES COMPILE_FLAGS -fPIC)
     add_definitions( -Wall )
 endif()
 
-# needed for correct Xerces header inclusion
-if( FORCE_BUNDLED_COPIES OR NOT XERCES_FOUND)
-    add_definitions( -DXERCES_STATIC_LIBRARY )
-endif()
-
--- a/src/zipios/CMakeLists.txt
+++ b/src/zipios/CMakeLists.txt
@@ -25,7 +25,14 @@
 
 add_library( ${PROJECT_NAME} STATIC ${SOURCES} )
 
-target_link_libraries( ${PROJECT_NAME} zlib BoostParts )
+find_library(LIB_ZLIB z)
+find_library(BOOST_DT boost_date_time)
+find_library(BOOST_FS boost_filesystem)
+find_library(BOOST_PO boost_program_options)
+find_library(BOOST_RE boost_regex)
+find_library(BOOST_S boost_system)
+find_library(BOOST_T boost_thread)
+target_link_libraries( ${PROJECT_NAME} ${LIB_ZLIB} ${BOOST_DT} ${BOOST_FS} ${BOOST_PO} ${BOOST_RE} ${BOOST_S} ${BOOST_T})
 
 #############################################################################
 
@@ -44,6 +51,7 @@
 
 # "Print all warnings" flag for GCC
 elseif( CMAKE_COMPILER_IS_GNUCXX )
+    SET_TARGET_PROPERTIES( ${PROJECT_NAME} PROPERTIES COMPILE_FLAGS -fPIC)
     add_definitions( -Wall )
 endif()
 
