changeset 100:27dc762e3dc8

getting rid of static dcmtk for debian
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 03 Oct 2012 09:33:25 +0200
parents 52ed88d3096a
children 428784e59dcd
files CMakeLists.txt Resources/CMake/DcmtkConfiguration.cmake Resources/CMake/Log4CPlusConfiguration.cmake Resources/Configuration.json Resources/log4cplus-patch.diff UnitTests/main.cpp
diffstat 6 files changed, 120 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/CMakeLists.txt	Sat Sep 29 11:24:57 2012 +0200
+++ b/CMakeLists.txt	Wed Oct 03 09:33:25 2012 +0200
@@ -46,6 +46,7 @@
 include(${CMAKE_SOURCE_DIR}/Resources/CMake/JsonCppConfiguration.cmake)
 include(${CMAKE_SOURCE_DIR}/Resources/CMake/LibCurlConfiguration.cmake)
 include(${CMAKE_SOURCE_DIR}/Resources/CMake/LibPngConfiguration.cmake)
+include(${CMAKE_SOURCE_DIR}/Resources/CMake/Log4CPlusConfiguration.cmake)
 
 
 if (${CMAKE_COMPILER_IS_GNUCXX})
--- a/Resources/CMake/DcmtkConfiguration.cmake	Sat Sep 29 11:24:57 2012 +0200
+++ b/Resources/CMake/DcmtkConfiguration.cmake	Wed Oct 03 09:33:25 2012 +0200
@@ -1,7 +1,7 @@
 # We always statically link against DCMTK 3.6.0, as there are many
 # differences wrt. DCMTK 3.5.x.
 
-if (ON) ## ${STATIC_BUILD})
+if (${STATIC_BUILD})
   SET(DCMTK_SOURCES_DIR ${CMAKE_BINARY_DIR}/dcmtk-3.6.0)
   DownloadPackage("ftp://dicom.offis.de/pub/dicom/offis/software/dcmtk/dcmtk360/dcmtk-3.6.0.zip" "${DCMTK_SOURCES_DIR}" "" "")
 
@@ -17,8 +17,9 @@
   AUX_SOURCE_DIRECTORY(${DCMTK_SOURCES_DIR}/dcmnet/libsrc THIRD_PARTY_SOURCES)
   AUX_SOURCE_DIRECTORY(${DCMTK_SOURCES_DIR}/dcmdata/libsrc THIRD_PARTY_SOURCES)
   AUX_SOURCE_DIRECTORY(${DCMTK_SOURCES_DIR}/ofstd/libsrc THIRD_PARTY_SOURCES)
+
+  # Source for the logging facility of DCMTK
   AUX_SOURCE_DIRECTORY(${DCMTK_SOURCES_DIR}/oflog/libsrc THIRD_PARTY_SOURCES)
-
   if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
     list(REMOVE_ITEM THIRD_PARTY_SOURCES 
       ${DCMTK_SOURCES_DIR}/oflog/libsrc/windebap.cc
@@ -38,7 +39,7 @@
 
   # This fixes crashes related to the destruction of the DCMTK OFLogger
   # http://support.dcmtk.org/docs-snapshot/file_macros.html
-  add_definitions(-DLOG4CPLUS_DISABLE_FATAL=1)
+  #add_definitions(-DLOG4CPLUS_DISABLE_FATAL=1)
 
   include_directories(
     #${DCMTK_SOURCES_DIR}
@@ -50,6 +51,9 @@
     )
 
   source_group(ThirdParty\\Dcmtk REGULAR_EXPRESSION ${DCMTK_SOURCES_DIR}/.*)
+
+  set(DCMTK_BUNDLES_LOG4CPLUS 1)
+
 else()
   include(FindDCMTK)
 
@@ -59,4 +63,14 @@
   add_definitions(
     -DHAVE_CONFIG_H=1
     )
+
+  message("${DCMTK_DIR}/oflog")
+  
+  IF (EXISTS "${DCMTK_DIR}/oflog")
+    set(DCMTK_BUNDLES_LOG4CPLUS 1)
+  else()
+    set(DCMTK_BUNDLES_LOG4CPLUS 0)
+  endif()
 endif()
+
+message("DCMTK includes its own copy of Log4Cplus: ${DCMTK_BUNDLES_LOG4CPLUS}")
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Resources/CMake/Log4CPlusConfiguration.cmake	Wed Oct 03 09:33:25 2012 +0200
@@ -0,0 +1,56 @@
+add_definitions(
+  -DDCMTK_BUNDLES_LOG4CPLUS=${DCMTK_BUNDLES_LOG4CPLUS}
+  )
+
+if (DCMTK_BUNDLES_LOG4CPLUS)
+  message("DCMTK already bundles its own copy of Log4CPlus")
+
+elseif (STATIC_BUILD)
+  SET(LOG4CPLUS_SOURCES_DIR ${CMAKE_BINARY_DIR}/log4cplus-1.0.4.1)
+  DownloadPackage("http://downloads.sourceforge.net/project/log4cplus/log4cplus-stable/1.0.4/log4cplus-1.0.4.1.tar.gz" "${LOG4CPLUS_SOURCES_DIR}" "" "")
+
+  execute_process(
+    COMMAND patch src/factory.cxx ${CMAKE_SOURCE_DIR}/Resources/log4cplus-patch.diff
+    WORKING_DIRECTORY ${LOG4CPLUS_SOURCES_DIR}
+    )
+
+  AUX_SOURCE_DIRECTORY(${LOG4CPLUS_SOURCES_DIR}/src THIRD_PARTY_SOURCES)
+
+  add_definitions(
+    -DLOG4CPLUS_STATIC=1
+    -DINSIDE_LOG4CPLUS=1
+    -DLOG4CPLUS_DECLSPEC_EXPORT=
+    -DLOG4CPLUS_DECLSPEC_IMPORT=
+    )
+
+  if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
+    add_definitions(
+      -DLOG4CPLUS_HAVE_STDIO_H=1
+      -DLOG4CPLUS_HAVE_UNISTD_H=1
+      -DLOG4CPLUS_HAVE_SYSLOG_H=1
+      -DLOG4CPLUS_HAVE_NETDB_H=1
+      -DLOG4CPLUS_HAVE_ERRNO_H=1
+      -DLOG4CPLUS_HAVE_STAT=1
+      -DLOG4CPLUS_HAVE_SYS_STAT_H=1
+      )
+    file(WRITE ${LOG4CPLUS_SOURCES_DIR}/include/log4cplus/config/defines.hxx "// Empty file")
+
+    list(REMOVE_ITEM THIRD_PARTY_SOURCES 
+      ${LOG4CPLUS_SOURCES_DIR}/src/socket-win32.cxx
+      )
+
+  elseif (${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
+    list(REMOVE_ITEM THIRD_PARTY_SOURCES 
+      ${LOG4CPLUS_SOURCES_DIR}/src/socket-unix.cxx
+      )
+    
+  endif()
+
+  include_directories(${LOG4CPLUS_SOURCES_DIR}/include)
+
+  source_group(ThirdParty\\Log4Cplus REGULAR_EXPRESSION ${LOG4CPLUS_SOURCES_DIR}/.*)
+
+else()
+  message(FATAL_ERROR "Dynamic log4cplus")
+  
+endif()
--- a/Resources/Configuration.json	Sat Sep 29 11:24:57 2012 +0200
+++ b/Resources/Configuration.json	Wed Oct 03 09:33:25 2012 +0200
@@ -37,7 +37,7 @@
      **/
 
     // Whether remote hosts can connect to the HTTP server
-    "RemoteAccessAllowed" : false,
+    "RemoteAccessAllowed" : true,
 
     // Whether or not SSL is enabled
     "SslEnabled" : false,
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Resources/log4cplus-patch.diff	Wed Oct 03 09:33:25 2012 +0200
@@ -0,0 +1,10 @@
+--- log4cplus-1.0.4.1/src/factory.cxx   2010-05-28 11:06:51.000000000 +0200
++++ factory.cxx    2012-10-02 11:43:31.808439489 +0200
+@@ -35,7 +35,7 @@
+ #  if defined (LOG4CPLUS_HAVE_WIN32_CONSOLE)
+ #    include <log4cplus/win32consoleappender.h>
+ #  endif
+-#  include <log4cplus/Win32DebugAppender.h>
++#  include <log4cplus/win32debugappender.h>
+ #endif
+ 
--- a/UnitTests/main.cpp	Sat Sep 29 11:24:57 2012 +0200
+++ b/UnitTests/main.cpp	Wed Oct 03 09:33:25 2012 +0200
@@ -279,8 +279,43 @@
   printf("[%s]\n", Toolbox::GetDirectoryOfExecutable().c_str());
 }
 
+
+
+#if DCMTK_BUNDLES_LOG4CPLUS == 0
+#include <log4cplus/logger.h>
+#include <log4cplus/consoleappender.h>
+#include <log4cplus/fileappender.h>
+#include <log4cplus/configurator.h>
+#else
+#include <dcmtk/oflog/logger.h>
+#include <dcmtk/oflog/consap.h>
+#include <dcmtk/oflog/fileap.h>
+//#include <dcmtk/oflog/configurator.h>
+#endif
+
+
+static log4cplus::Logger logger(log4cplus::Logger::getInstance("UnitTests"));
+
+TEST(Logger, Basic)
+{
+  LOG4CPLUS_INFO(logger, "I say hello");
+}
+
+
 int main(int argc, char **argv)
 {
+  using namespace log4cplus;
+  SharedAppenderPtr myAppender(new ConsoleAppender());
+  //SharedAppenderPtr myAppender(new FileAppender("UnitTests.log"));
+#if DCMTK_BUNDLES_LOG4CPLUS == 0
+  std::auto_ptr<Layout> myLayout(new TTCCLayout());
+#else
+  OFauto_ptr<Layout> myLayout(new TTCCLayout());
+#endif
+  myAppender->setLayout(myLayout);
+  Logger::getRoot().addAppender(myAppender);
+  Logger::getRoot().setLogLevel(INFO_LOG_LEVEL);
+
   OrthancInitialize();
   ::testing::InitGoogleTest(&argc, argv);
   int result = RUN_ALL_TESTS();