changeset 1337:afaa55d42ddd

FreeBSD support
author jodogne
date Tue, 31 Mar 2015 11:40:29 +0200
parents a80e811ec619
children 3f4297d01a14
files CMakeLists.txt Core/MultiThreading/Mutex.cpp Core/Toolbox.cpp LinuxCompilation.txt NEWS Plugins/Engine/PluginsManager.cpp Plugins/Engine/SharedLibrary.cpp Resources/CMake/BoostConfiguration.cmake Resources/CMake/Compiler.cmake Resources/CMake/DcmtkConfiguration.cmake Resources/CMake/GoogleLogConfiguration.cmake Resources/CMake/LibCurlConfiguration.cmake Resources/CMake/MongooseConfiguration.cmake THANKS UnitTestsSources/PluginsTests.cpp UnitTestsSources/UnitTestsMain.cpp
diffstat 16 files changed, 98 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/CMakeLists.txt	Mon Mar 30 16:18:46 2015 +0200
+++ b/CMakeLists.txt	Tue Mar 31 11:40:29 2015 +0200
@@ -345,7 +345,7 @@
   OrthancServer/main.cpp
   )
 
-target_link_libraries(Orthanc ServerLibrary CoreLibrary ${STATIC_LUA} ${STATIC_GOOGLE_LOG})
+target_link_libraries(Orthanc ServerLibrary CoreLibrary ${STATIC_LUA} ${STATIC_GOOGLE_LOG} ${DCMTK_LIBRARIES})
 
 if (${OPENSSL_SOURCES_LENGTH} GREATER 0)
   target_link_libraries(Orthanc OpenSSL)
@@ -374,7 +374,7 @@
   ${GTEST_SOURCES}
   ${ORTHANC_UNIT_TESTS_SOURCES}
   )
-target_link_libraries(UnitTests ServerLibrary CoreLibrary ${STATIC_LUA} ${STATIC_GOOGLE_LOG})
+target_link_libraries(UnitTests ServerLibrary CoreLibrary ${STATIC_LUA} ${STATIC_GOOGLE_LOG} ${DCMTK_LIBRARIES})
 
 if (${OPENSSL_SOURCES_LENGTH} GREATER 0)
   target_link_libraries(UnitTests OpenSSL)
@@ -431,7 +431,8 @@
     )
 
   if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux" OR
-      ${CMAKE_SYSTEM_NAME} STREQUAL "kFreeBSD")
+      ${CMAKE_SYSTEM_NAME} STREQUAL "kFreeBSD" OR
+      ${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD")
     set_target_properties(OrthancClient
       PROPERTIES LINK_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined -Wl,--as-needed -Wl,--version-script=${ORTHANC_ROOT}/OrthancCppClient/SharedLibrary/Laaw/VersionScript.map"
       )
--- a/Core/MultiThreading/Mutex.cpp	Mon Mar 30 16:18:46 2015 +0200
+++ b/Core/MultiThreading/Mutex.cpp	Tue Mar 31 11:40:29 2015 +0200
@@ -37,7 +37,7 @@
 
 #if defined(_WIN32)
 #include <windows.h>
-#elif defined(__linux) || defined(__FreeBSD_kernel__) || defined(__APPLE__)
+#elif defined(__linux) || defined(__FreeBSD_kernel__) || defined(__APPLE__) || defined(__FreeBSD__)
 #include <pthread.h>
 #else
 #error Support your platform here
@@ -75,7 +75,7 @@
   }
 
 
-#elif defined(__linux) || defined(__FreeBSD_kernel__) || defined(__APPLE__)
+#elif defined(__linux) || defined(__FreeBSD_kernel__) || defined(__APPLE__) || defined(__FreeBSD__)
 
   struct Mutex::PImpl
   {
--- a/Core/Toolbox.cpp	Mon Mar 30 16:18:46 2015 +0200
+++ b/Core/Toolbox.cpp	Tue Mar 31 11:40:29 2015 +0200
@@ -59,7 +59,7 @@
 #include <limits.h>      /* PATH_MAX */
 #endif
 
-#if defined(__linux) || defined(__FreeBSD_kernel__)
+#if defined(__linux) || defined(__FreeBSD_kernel__) || defined(__FreeBSD__)
 #include <limits.h>      /* PATH_MAX */
 #include <signal.h>
 #include <unistd.h>
@@ -116,7 +116,7 @@
   {
 #if defined(_WIN32)
     ::Sleep(static_cast<DWORD>(microSeconds / static_cast<uint64_t>(1000)));
-#elif defined(__linux) || defined(__APPLE__) || defined(__FreeBSD_kernel__)
+#elif defined(__linux) || defined(__APPLE__) || defined(__FreeBSD_kernel__) || defined(__FreeBSD__)
     usleep(microSeconds);
 #else
 #error Support your platform here
@@ -503,7 +503,7 @@
     return std::string(&buffer[0]);
   }
 
-#elif defined(__linux) || defined(__FreeBSD_kernel__)
+#elif defined(__linux) || defined(__FreeBSD_kernel__) || defined(__FreeBSD__)
   static std::string GetPathToExecutableInternal()
   {
     std::vector<char> buffer(PATH_MAX + 1);
--- a/LinuxCompilation.txt	Mon Mar 30 16:18:46 2015 +0200
+++ b/LinuxCompilation.txt	Tue Mar 31 11:40:29 2015 +0200
@@ -219,6 +219,17 @@
 
 
 
+SUPPORTED - FreeBSD 10.1
+------------------------
+
+# pkg install jsoncpp pugixml lua51 curl googletest dcmtk cmake \
+              e2fsprogs-libuuid glog boost-libs sqlite3 python libiconv
+
+# cmake -DALLOW_DOWNLOADS=ON \
+        -DUSE_SYSTEM_MONGOOSE=OFF \
+        -DDCMTK_LIBRARIES="dcmdsig;charls;dcmjpls" \
+	~/Orthanc
+
 
 
 Other Linux distributions?
--- a/NEWS	Mon Mar 30 16:18:46 2015 +0200
+++ b/NEWS	Tue Mar 31 11:40:29 2015 +0200
@@ -1,6 +1,7 @@
 Pending changes in the mainline
 ===============================
 
+* Support of FreeBSD
 * Prevent freeze on C-FIND if no DICOM tag is to be returned
 * Fix issue 30 (QR response missing "Query/Retrieve Level" (008,0052))
 
--- a/Plugins/Engine/PluginsManager.cpp	Mon Mar 30 16:18:46 2015 +0200
+++ b/Plugins/Engine/PluginsManager.cpp	Tue Mar 31 11:40:29 2015 +0200
@@ -42,7 +42,7 @@
 
 #ifdef WIN32
 #define PLUGIN_EXTENSION ".dll"
-#elif defined(__linux) || defined(__FreeBSD_kernel__)
+#elif defined(__linux) || defined(__FreeBSD_kernel__) || defined(__FreeBSD__)
 #define PLUGIN_EXTENSION ".so"
 #elif defined(__APPLE__) && defined(__MACH__)
 #define PLUGIN_EXTENSION ".dylib"
--- a/Plugins/Engine/SharedLibrary.cpp	Mon Mar 30 16:18:46 2015 +0200
+++ b/Plugins/Engine/SharedLibrary.cpp	Tue Mar 31 11:40:29 2015 +0200
@@ -36,7 +36,7 @@
 
 #if defined(_WIN32)
 #include <windows.h>
-#elif defined(__linux) || (defined(__APPLE__) && defined(__MACH__)) || defined(__FreeBSD_kernel__)
+#elif defined(__linux) || (defined(__APPLE__) && defined(__MACH__)) || defined(__FreeBSD_kernel__) || defined(__FreeBSD__)
 #include <dlfcn.h>
 #else
 #error Support your platform here
@@ -58,7 +58,7 @@
       throw OrthancException(ErrorCode_SharedLibrary);
     }
 
-#elif defined(__linux) || (defined(__APPLE__) && defined(__MACH__)) || defined(__FreeBSD_kernel__)
+#elif defined(__linux) || (defined(__APPLE__) && defined(__MACH__)) || defined(__FreeBSD_kernel__) || defined(__FreeBSD__)
     handle_ = ::dlopen(path.c_str(), RTLD_NOW);
     if (handle_ == NULL) 
     {
@@ -84,7 +84,7 @@
     {
 #if defined(_WIN32)
       ::FreeLibrary((HMODULE)handle_);
-#elif defined(__linux) || (defined(__APPLE__) && defined(__MACH__)) || defined(__FreeBSD_kernel__)
+#elif defined(__linux) || (defined(__APPLE__) && defined(__MACH__)) || defined(__FreeBSD_kernel__) || defined(__FreeBSD__)
       ::dlclose(handle_);
 #else
 #error Support your platform here
@@ -102,7 +102,7 @@
 
 #if defined(_WIN32)
     return ::GetProcAddress((HMODULE)handle_, name.c_str());
-#elif defined(__linux) || (defined(__APPLE__) && defined(__MACH__)) || defined(__FreeBSD_kernel__)
+#elif defined(__linux) || (defined(__APPLE__) && defined(__MACH__)) || defined(__FreeBSD_kernel__) || defined(__FreeBSD__)
     return ::dlsym(handle_, name.c_str());
 #else
 #error Support your platform here
--- a/Resources/CMake/BoostConfiguration.cmake	Mon Mar 30 16:18:46 2015 +0200
+++ b/Resources/CMake/BoostConfiguration.cmake	Tue Mar 31 11:40:29 2015 +0200
@@ -56,6 +56,7 @@
 
   if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux" OR
       ${CMAKE_SYSTEM_NAME} STREQUAL "Darwin" OR
+      ${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD" OR
       ${CMAKE_SYSTEM_NAME} STREQUAL "kFreeBSD")
     list(APPEND BOOST_SOURCES
       ${BOOST_SOURCES_DIR}/libs/thread/src/pthread/once.cpp
--- a/Resources/CMake/Compiler.cmake	Mon Mar 30 16:18:46 2015 +0200
+++ b/Resources/CMake/Compiler.cmake	Tue Mar 31 11:40:29 2015 +0200
@@ -41,25 +41,24 @@
 
 
 if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux" OR
-    ${CMAKE_SYSTEM_NAME} STREQUAL "kFreeBSD")
-  if ("${CMAKE_SYSTEM_VERSION}" STREQUAL "LinuxStandardBase")
-    SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --lsb-target-version=${LSB_TARGET_VERSION} -I${LSB_PATH}/include")
-    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --lsb-target-version=${LSB_TARGET_VERSION} -nostdinc++ -I${LSB_PATH}/include -I${LSB_PATH}/include/c++ -I${LSB_PATH}/include/c++/backward -fpermissive")
-    SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} --lsb-target-version=${LSB_TARGET_VERSION} -L${LSB_LIBPATH}")
-  endif()
-
-  add_definitions(
-    -D_LARGEFILE64_SOURCE=1 
-    -D_FILE_OFFSET_BITS=64
-    )
-  set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--as-needed")
+    ${CMAKE_SYSTEM_NAME} STREQUAL "kFreeBSD" OR
+    ${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD")
   set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,--no-undefined")
   set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined")
 
   # Remove the "-rdynamic" option
   # http://www.mail-archive.com/cmake@cmake.org/msg08837.html
   set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
-  link_libraries(uuid pthread rt dl)
+  link_libraries(uuid pthread rt)
+
+  if (NOT ${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD")
+    set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--as-needed")
+    add_definitions(
+      -D_LARGEFILE64_SOURCE=1 
+      -D_FILE_OFFSET_BITS=64
+      )
+    link_libraries(dl)
+  endif()
 
 elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
   add_definitions(
@@ -82,6 +81,22 @@
 endif()
 
 
+if ("${CMAKE_SYSTEM_VERSION}" STREQUAL "LinuxStandardBase")
+  SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --lsb-target-version=${LSB_TARGET_VERSION} -I${LSB_PATH}/include")
+  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --lsb-target-version=${LSB_TARGET_VERSION} -nostdinc++ -I${LSB_PATH}/include -I${LSB_PATH}/include/c++ -I${LSB_PATH}/include/c++/backward -fpermissive")
+  SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} --lsb-target-version=${LSB_TARGET_VERSION} -L${LSB_LIBPATH}")
+endif()
+
+
+if (${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD")
+  # In FreeBSD, the "/usr/local/" folder contains the ports and need to be imported
+  SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -I/usr/local/include")
+  SET(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -I/usr/local/include -I/usr/local/include/jsoncpp")
+  SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L/usr/local/lib")
+  SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -L/usr/local/lib")
+endif()
+
+
 if (${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
   CHECK_INCLUDE_FILES(rpc.h HAVE_UUID_H)
 else()
@@ -92,6 +107,7 @@
   message(FATAL_ERROR "Please install the uuid-dev package")
 endif()
 
+
 if (${STATIC_BUILD})
   add_definitions(-DORTHANC_STATIC=1)
 else()
--- a/Resources/CMake/DcmtkConfiguration.cmake	Mon Mar 30 16:18:46 2015 +0200
+++ b/Resources/CMake/DcmtkConfiguration.cmake	Tue Mar 31 11:40:29 2015 +0200
@@ -93,6 +93,7 @@
   AUX_SOURCE_DIRECTORY(${DCMTK_SOURCES_DIR}/oflog/libsrc DCMTK_SOURCES)
   if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux" OR
       ${CMAKE_SYSTEM_NAME} STREQUAL "Darwin" OR
+      ${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD" OR
       ${CMAKE_SYSTEM_NAME} STREQUAL "kFreeBSD")
     list(REMOVE_ITEM DCMTK_SOURCES 
       ${DCMTK_SOURCES_DIR}/oflog/libsrc/windebap.cc
@@ -163,7 +164,6 @@
   list(APPEND DCMTK_LIBRARIES "${tmp}")
 
   include_directories(${DCMTK_INCLUDE_DIR})
-  link_libraries(${DCMTK_LIBRARIES})
 
   add_definitions(
     -DHAVE_CONFIG_H=1
--- a/Resources/CMake/GoogleLogConfiguration.cmake	Mon Mar 30 16:18:46 2015 +0200
+++ b/Resources/CMake/GoogleLogConfiguration.cmake	Tue Mar 31 11:40:29 2015 +0200
@@ -30,6 +30,7 @@
 
   if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux" OR
       ${CMAKE_SYSTEM_NAME} STREQUAL "Darwin" OR
+      ${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD" OR
       ${CMAKE_SYSTEM_NAME} STREQUAL "kFreeBSD")
     set(ac_cv_have_unistd_h 1)
     set(ac_cv_have_stdint_h 1)
@@ -96,6 +97,7 @@
 
   if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux" OR
       ${CMAKE_SYSTEM_NAME} STREQUAL "Darwin" OR
+      ${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD" OR
       ${CMAKE_SYSTEM_NAME} STREQUAL "kFreeBSD")
     if ("${CMAKE_SYSTEM_VERSION}" STREQUAL "LinuxStandardBase")
       # Install the specific configuration for LSB SDK
--- a/Resources/CMake/LibCurlConfiguration.cmake	Mon Mar 30 16:18:46 2015 +0200
+++ b/Resources/CMake/LibCurlConfiguration.cmake	Tue Mar 31 11:40:29 2015 +0200
@@ -42,6 +42,7 @@
 
   if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux" OR
       ${CMAKE_SYSTEM_NAME} STREQUAL "Darwin" OR
+      ${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD" OR
       ${CMAKE_SYSTEM_NAME} STREQUAL "kFreeBSD")
     if ("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
       SET(TMP_OS "x86_64")
--- a/Resources/CMake/MongooseConfiguration.cmake	Mon Mar 30 16:18:46 2015 +0200
+++ b/Resources/CMake/MongooseConfiguration.cmake	Tue Mar 31 11:40:29 2015 +0200
@@ -24,7 +24,7 @@
 
   # Patch mongoose
   execute_process(
-    COMMAND patch mongoose.c ${MONGOOSE_PATCH}
+    COMMAND patch -N mongoose.c ${MONGOOSE_PATCH}
     WORKING_DIRECTORY ${MONGOOSE_SOURCES_DIR}
     )
 
--- a/THANKS	Mon Mar 30 16:18:46 2015 +0200
+++ b/THANKS	Tue Mar 31 11:40:29 2015 +0200
@@ -28,6 +28,7 @@
 * Vincent Kersten <vincent1234567@gmail.com>, for DICOMDIR in the GUI.
 * Emsy Chan <emlscs@yahoo.com>, for various contributions
   and sample DICOM files.
+* Mikhail <mp39590@gmail.com>, for FreeBSD support.
 
 
 Thanks also to all the contributors active in our Google Group:
--- a/UnitTestsSources/PluginsTests.cpp	Mon Mar 30 16:18:46 2015 +0200
+++ b/UnitTestsSources/PluginsTests.cpp	Tue Mar 31 11:40:29 2015 +0200
@@ -55,6 +55,16 @@
   ASSERT_TRUE(l.HasFunction("dlclose"));
   ASSERT_FALSE(l.HasFunction("world"));
 
+#elif defined(__FreeBSD__)
+  // dlopen() in FreeBSD is supplied by libc, libc.so is
+  // a ldscript, so we can't actually use it. Use thread
+  // library instead - if it works - dlopen() is good.
+  SharedLibrary l("libpthread.so");
+  ASSERT_THROW(l.GetFunction("world"), OrthancException);
+  ASSERT_TRUE(l.GetFunction("pthread_create") != NULL);
+  ASSERT_TRUE(l.HasFunction("pthread_cancel"));
+  ASSERT_FALSE(l.HasFunction("world"));
+
 #elif defined(__APPLE__) && defined(__MACH__)
   SharedLibrary l("libdl.dylib");
   ASSERT_THROW(l.GetFunction("world"), OrthancException);
--- a/UnitTestsSources/UnitTestsMain.cpp	Mon Mar 30 16:18:46 2015 +0200
+++ b/UnitTestsSources/UnitTestsMain.cpp	Tue Mar 31 11:40:29 2015 +0200
@@ -45,6 +45,7 @@
 #include "../Core/Uuid.h"
 #include "../OrthancServer/OrthancInitialization.h"
 
+
 using namespace Orthanc;
 
 
@@ -668,19 +669,29 @@
 
 #if defined(__linux)
 #include <endian.h>
+#elif defined(__FreeBSD__)
+#include <machine/endian.h>
 #endif
 
+
 TEST(Toolbox, Endianness)
 {
   // Parts of this test come from Adam Conrad
   // http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=728822#5
 
-#if defined(_WIN32)
+
+  /**
+   * Windows and OS X are assumed to always little-endian.
+   **/
+  
+#if defined(_WIN32) || defined(__APPLE__)
   ASSERT_EQ(Endianness_Little, Toolbox::DetectEndianness());
 
-#elif defined(__APPLE__)
-  ASSERT_EQ(Endianness_Little, Toolbox::DetectEndianness());
 
+  /**
+   * Linux.
+   **/
+  
 #elif defined(__linux) || defined(__FreeBSD_kernel__)
 
 #if !defined(__BYTE_ORDER)
@@ -693,6 +704,18 @@
   ASSERT_EQ(Endianness_Little, Toolbox::DetectEndianness());
 #  endif
 
+  
+  /**
+   * FreeBSD.
+   **/
+  
+#elif defined(__FreeBSD__)
+#  if _BYTE_ORDER == _BIG_ENDIAN
+   ASSERT_EQ(Endianness_Big, Toolbox::DetectEndianness());
+#  else // _LITTLE_ENDIAN
+   ASSERT_EQ(Endianness_Little, Toolbox::DetectEndianness());
+#  endif
+
 #else
 #error Support your platform here
 #endif