changeset 2364:ae50eccd41b7

compilation succeeds on OpenBSD
author jodogne
date Mon, 21 Aug 2017 16:28:53 +0200
parents f8ef157f2d73
children 9e0eae8a5ea4
files Core/MultiThreading/Mutex.cpp Core/SystemToolbox.cpp NEWS OrthancServer/FromDcmtkBridge.cpp Plugins/Engine/PluginsManager.cpp Plugins/Engine/SharedLibrary.cpp Resources/CMake/BoostConfiguration.cmake Resources/CMake/Compiler.cmake Resources/CMake/DcmtkConfiguration.cmake Resources/CMake/LibCurlConfiguration.cmake Resources/CMake/LibP11Configuration.cmake Resources/CMake/ZlibConfiguration.cmake UnitTestsSources/PluginsTests.cpp UnitTestsSources/UnitTestsMain.cpp
diffstat 14 files changed, 84 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/Core/MultiThreading/Mutex.cpp	Mon Aug 21 15:04:20 2017 +0200
+++ b/Core/MultiThreading/Mutex.cpp	Mon Aug 21 16:28:53 2017 +0200
@@ -38,7 +38,7 @@
 
 #if defined(_WIN32)
 #include <windows.h>
-#elif defined(__linux__) || defined(__FreeBSD_kernel__) || defined(__APPLE__) || defined(__FreeBSD__)
+#elif defined(__linux__) || defined(__FreeBSD_kernel__) || defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__)
 #include <pthread.h>
 #else
 #error Support your platform here
@@ -76,7 +76,7 @@
   }
 
 
-#elif defined(__linux__) || defined(__FreeBSD_kernel__) || defined(__APPLE__) || defined(__FreeBSD__)
+#elif defined(__linux__) || defined(__FreeBSD_kernel__) || defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__)
 
   struct Mutex::PImpl
   {
--- a/Core/SystemToolbox.cpp	Mon Aug 21 15:04:20 2017 +0200
+++ b/Core/SystemToolbox.cpp	Mon Aug 21 16:28:53 2017 +0200
@@ -67,7 +67,7 @@
 
 extern "C"
 {
-#ifdef WIN32
+#if defined(_WIN32)
 #  include <rpc.h>
 #else
 #  include <uuid/uuid.h>
@@ -157,7 +157,7 @@
   {
 #if defined(_WIN32)
     ::Sleep(static_cast<DWORD>(microSeconds / static_cast<uint64_t>(1000)));
-#elif defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD_kernel__) || defined(__FreeBSD__) || defined(__native_client__)
+#elif defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD_kernel__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__native_client__)
     usleep(microSeconds);
 #else
 #error Support your platform here
@@ -370,6 +370,13 @@
     return std::string(pathbuf);
   }
 
+#elif defined(__OpenBSD__)
+  static std::string GetPathToExecutableInternal()
+  {
+    // TODO
+    throw OrthancException(ErrorCode_NotImplemented);
+  }
+
 #else
 #error Support your platform here
 #endif
--- a/NEWS	Mon Aug 21 15:04:20 2017 +0200
+++ b/NEWS	Mon Aug 21 16:28:53 2017 +0200
@@ -1,6 +1,8 @@
 Pending changes in the mainline
 ===============================
 
+* Fix issue 64 (OpenBSD support)
+
 
 Version 1.3.0 (2017-07-19)
 ==========================
--- a/OrthancServer/FromDcmtkBridge.cpp	Mon Aug 21 15:04:20 2017 +0200
+++ b/OrthancServer/FromDcmtkBridge.cpp	Mon Aug 21 16:28:53 2017 +0200
@@ -209,7 +209,7 @@
         LOG(INFO) << "The dictionary of private tags has not been loaded";
       }
 
-#elif defined(__linux__) || defined(__FreeBSD_kernel__) || defined(__FreeBSD__)
+#elif defined(__linux__) || defined(__FreeBSD_kernel__) || defined(__FreeBSD__) || defined(__OpenBSD__)
       std::string path = DCMTK_DICTIONARY_DIR;
 
       const char* env = std::getenv(DCM_DICT_ENVIRONMENT_VARIABLE);
--- a/Plugins/Engine/PluginsManager.cpp	Mon Aug 21 15:04:20 2017 +0200
+++ b/Plugins/Engine/PluginsManager.cpp	Mon Aug 21 16:28:53 2017 +0200
@@ -49,7 +49,7 @@
 
 #ifdef WIN32
 #define PLUGIN_EXTENSION ".dll"
-#elif defined(__linux__) || defined(__FreeBSD_kernel__) || defined(__FreeBSD__)
+#elif defined(__linux__) || defined(__FreeBSD_kernel__) || defined(__FreeBSD__) || defined(__OpenBSD__)
 #define PLUGIN_EXTENSION ".so"
 #elif defined(__APPLE__) && defined(__MACH__)
 #define PLUGIN_EXTENSION ".dylib"
--- a/Plugins/Engine/SharedLibrary.cpp	Mon Aug 21 15:04:20 2017 +0200
+++ b/Plugins/Engine/SharedLibrary.cpp	Mon Aug 21 16:28:53 2017 +0200
@@ -46,7 +46,7 @@
 
 #if defined(_WIN32)
 #include <windows.h>
-#elif defined(__linux__) || (defined(__APPLE__) && defined(__MACH__)) || defined(__FreeBSD_kernel__) || defined(__FreeBSD__)
+#elif defined(__linux__) || (defined(__APPLE__) && defined(__MACH__)) || defined(__FreeBSD_kernel__) || defined(__FreeBSD__) || defined(__OpenBSD__)
 #include <dlfcn.h>
 #else
 #error Support your platform here
@@ -66,7 +66,7 @@
       throw OrthancException(ErrorCode_SharedLibrary);
     }
 
-#elif defined(__linux__) || (defined(__APPLE__) && defined(__MACH__)) || defined(__FreeBSD_kernel__) || defined(__FreeBSD__)
+#elif defined(__linux__) || (defined(__APPLE__) && defined(__MACH__)) || defined(__FreeBSD_kernel__) || defined(__FreeBSD__) || defined(__OpenBSD__)
     handle_ = ::dlopen(path_.c_str(), RTLD_NOW);
     if (handle_ == NULL) 
     {
@@ -92,7 +92,7 @@
     {
 #if defined(_WIN32)
       ::FreeLibrary((HMODULE)handle_);
-#elif defined(__linux__) || (defined(__APPLE__) && defined(__MACH__)) || defined(__FreeBSD_kernel__) || defined(__FreeBSD__)
+#elif defined(__linux__) || (defined(__APPLE__) && defined(__MACH__)) || defined(__FreeBSD_kernel__) || defined(__FreeBSD__) || defined(__OpenBSD__)
       ::dlclose(handle_);
 #else
 #error Support your platform here
@@ -110,7 +110,7 @@
 
 #if defined(_WIN32)
     return ::GetProcAddress((HMODULE)handle_, name.c_str());
-#elif defined(__linux__) || (defined(__APPLE__) && defined(__MACH__)) || defined(__FreeBSD_kernel__) || defined(__FreeBSD__)
+#elif defined(__linux__) || (defined(__APPLE__) && defined(__MACH__)) || defined(__FreeBSD_kernel__) || defined(__FreeBSD__) || defined(__OpenBSD__)
     return ::dlsym(handle_, name.c_str());
 #else
 #error Support your platform here
--- a/Resources/CMake/BoostConfiguration.cmake	Mon Aug 21 15:04:20 2017 +0200
+++ b/Resources/CMake/BoostConfiguration.cmake	Mon Aug 21 16:28:53 2017 +0200
@@ -55,6 +55,7 @@
       ${CMAKE_SYSTEM_NAME} STREQUAL "Darwin" OR
       ${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD" OR
       ${CMAKE_SYSTEM_NAME} STREQUAL "kFreeBSD" OR
+      ${CMAKE_SYSTEM_NAME} STREQUAL "OpenBSD" OR
       ${CMAKE_SYSTEM_NAME} STREQUAL "PNaCl" OR
       ${CMAKE_SYSTEM_NAME} STREQUAL "NaCl32" OR
       ${CMAKE_SYSTEM_NAME} STREQUAL "NaCl64")
@@ -76,6 +77,8 @@
       add_definitions(-DBOOST_HAS_SCHED_YIELD=1)
     endif()
 
+    link_libraries(iconv)
+
   elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
     list(APPEND BOOST_SOURCES
       ${BOOST_SOURCES_DIR}/libs/thread/src/win32/tss_dll.cpp
@@ -110,7 +113,8 @@
     message(FATAL_ERROR "Support your platform here")
   endif()
 
-  if (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
+  if (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin" OR
+      ${CMAKE_SYSTEM_NAME} STREQUAL "OpenBSD")
     list(APPEND BOOST_SOURCES
       ${BOOST_SOURCES_DIR}/libs/filesystem/src/utf8_codecvt_facet.cpp
       )
@@ -155,6 +159,7 @@
         ${CMAKE_SYSTEM_NAME} STREQUAL "Darwin" OR
         ${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD" OR
         ${CMAKE_SYSTEM_NAME} STREQUAL "kFreeBSD" OR
+        ${CMAKE_SYSTEM_NAME} STREQUAL "OpenBSD" OR
         ${CMAKE_SYSTEM_NAME} STREQUAL "PNaCl" OR
         ${CMAKE_SYSTEM_NAME} STREQUAL "NaCl32" OR
         ${CMAKE_SYSTEM_NAME} STREQUAL "NaCl64")
--- a/Resources/CMake/Compiler.cmake	Mon Aug 21 15:04:20 2017 +0200
+++ b/Resources/CMake/Compiler.cmake	Mon Aug 21 16:28:53 2017 +0200
@@ -57,11 +57,27 @@
 endif()
 
 
+if (${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD" OR
+    ${CMAKE_SYSTEM_NAME} STREQUAL "OpenBSD")
+  # In FreeBSD/OpenBSD, 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_CXX_FLAGS} -I/usr/local/include")
+  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 "Linux" OR
     ${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")
+    ${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD" OR
+    ${CMAKE_SYSTEM_NAME} STREQUAL "OpenBSD")
+
+  if (NOT ${CMAKE_SYSTEM_NAME} STREQUAL "OpenBSD")
+    # The "--no-undefined" linker flag makes the shared libraries
+    # (plugins ModalityWorklists and ServeFolders) fail to compile on OpenBSD
+    set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,--no-undefined")
+    set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined")
+  endif()
 
   if (NOT DEFINED ENABLE_PLUGINS_VERSION_SCRIPT OR 
       ENABLE_PLUGINS_VERSION_SCRIPT)
@@ -71,22 +87,39 @@
   # 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)
+  link_libraries(uuid pthread)
+
+  if (NOT ${CMAKE_SYSTEM_NAME} STREQUAL "OpenBSD")
+    link_libraries(rt)
+  endif()
+
+  if (NOT ${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD" AND
+      NOT ${CMAKE_SYSTEM_NAME} STREQUAL "OpenBSD")
+    link_libraries(dl)
+  endif()
 
   if (NOT ${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD")
+    # The "--as-needed" linker flag is not available on FreeBSD
     set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--as-needed")
     set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,--as-needed")
     set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--as-needed")
+  endif()
+
+  if (NOT ${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD" AND
+      NOT ${CMAKE_SYSTEM_NAME} STREQUAL "OpenBSD")
+    # FreeBSD/OpenBSD have just one single interface for file
+    # handling, which is 64bit clean, so there is no need to define macro
+    # for LFS (Large File Support).
+    # https://ohse.de/uwe/articles/lfs.html
     add_definitions(
       -D_LARGEFILE64_SOURCE=1 
       -D_FILE_OFFSET_BITS=64
       )
-    link_libraries(dl)
   endif()
 
   CHECK_INCLUDE_FILES(uuid/uuid.h HAVE_UUID_H)
   if (NOT HAVE_UUID_H)
-    message(FATAL_ERROR "Please install the uuid-dev package")
+    message(FATAL_ERROR "Please install the uuid-dev package (or e2fsprogs if OpenBSD)")
   endif()
 
 elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
@@ -146,6 +179,8 @@
     message(FATAL_ERROR "Please install the uuid-dev package")
   endif()
 
+else()
+  message(FATAL_ERROR "Support your platform here")
 endif()
 
 
@@ -156,15 +191,6 @@
 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")
-  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 (DEFINED ENABLE_PROFILING AND ENABLE_PROFILING)
   if (NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
     message(WARNING "Enabling profiling on a non-debug build will not produce full information")
--- a/Resources/CMake/DcmtkConfiguration.cmake	Mon Aug 21 15:04:20 2017 +0200
+++ b/Resources/CMake/DcmtkConfiguration.cmake	Mon Aug 21 16:28:53 2017 +0200
@@ -202,7 +202,8 @@
   if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux" OR
       ${CMAKE_SYSTEM_NAME} STREQUAL "Darwin" OR
       ${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD" OR
-      ${CMAKE_SYSTEM_NAME} STREQUAL "kFreeBSD")
+      ${CMAKE_SYSTEM_NAME} STREQUAL "kFreeBSD" OR
+      ${CMAKE_SYSTEM_NAME} STREQUAL "OpenBSD")
     list(REMOVE_ITEM DCMTK_SOURCES 
       ${DCMTK_SOURCES_DIR}/oflog/libsrc/clfsap.cc
       ${DCMTK_SOURCES_DIR}/oflog/libsrc/windebap.cc
--- a/Resources/CMake/LibCurlConfiguration.cmake	Mon Aug 21 15:04:20 2017 +0200
+++ b/Resources/CMake/LibCurlConfiguration.cmake	Mon Aug 21 16:28:53 2017 +0200
@@ -60,7 +60,8 @@
   if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux" OR
       ${CMAKE_SYSTEM_NAME} STREQUAL "Darwin" OR
       ${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD" OR
-      ${CMAKE_SYSTEM_NAME} STREQUAL "kFreeBSD")
+      ${CMAKE_SYSTEM_NAME} STREQUAL "kFreeBSD" OR
+      ${CMAKE_SYSTEM_NAME} STREQUAL "OpenBSD")
     if ("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
       SET(TMP_OS "x86_64")
     else()
--- a/Resources/CMake/LibP11Configuration.cmake	Mon Aug 21 15:04:20 2017 +0200
+++ b/Resources/CMake/LibP11Configuration.cmake	Mon Aug 21 16:28:53 2017 +0200
@@ -48,6 +48,7 @@
   if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux" OR
       ${CMAKE_SYSTEM_NAME} STREQUAL "kFreeBSD" OR
       ${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD" OR
+      ${CMAKE_SYSTEM_NAME} STREQUAL "OpenBSD" OR
       ${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
     list(APPEND LIBP11_SOURCES 
       ${LIBP11_SOURCES_DIR}/src/atfork.c
--- a/Resources/CMake/ZlibConfiguration.cmake	Mon Aug 21 15:04:20 2017 +0200
+++ b/Resources/CMake/ZlibConfiguration.cmake	Mon Aug 21 16:28:53 2017 +0200
@@ -29,6 +29,15 @@
 
   source_group(ThirdParty\\zlib REGULAR_EXPRESSION ${ZLIB_SOURCES_DIR}/.*)
 
+  if (${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD" OR
+      ${CMAKE_SYSTEM_NAME} STREQUAL "OpenBSD")
+    # "ioapi.c" from zlib (minizip) expects the "IOAPI_NO_64" macro to be set to "true"
+    # https://ohse.de/uwe/articles/lfs.html
+    add_definitions(
+      -DIOAPI_NO_64=1
+      )
+  endif()
+
 else()
   include(FindZLIB)
   include_directories(${ZLIB_INCLUDE_DIRS})
--- a/UnitTestsSources/PluginsTests.cpp	Mon Aug 21 15:04:20 2017 +0200
+++ b/UnitTestsSources/PluginsTests.cpp	Mon Aug 21 16:28:53 2017 +0200
@@ -65,8 +65,8 @@
   ASSERT_TRUE(l.HasFunction("dlclose"));
   ASSERT_FALSE(l.HasFunction("world"));
 
-#elif defined(__FreeBSD__)
-  // dlopen() in FreeBSD is supplied by libc, libc.so is
+#elif defined(__FreeBSD__) || defined(__OpenBSD__)
+  // dlopen() in FreeBSD/OpenBSD 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");
--- a/UnitTestsSources/UnitTestsMain.cpp	Mon Aug 21 15:04:20 2017 +0200
+++ b/UnitTestsSources/UnitTestsMain.cpp	Mon Aug 21 16:28:53 2017 +0200
@@ -658,7 +658,7 @@
 
 
 
-#if defined(__linux__)
+#if defined(__linux__) || defined(__OpenBSD__)
 #include <endian.h>
 #elif defined(__FreeBSD__)
 #include <machine/endian.h>
@@ -700,7 +700,7 @@
    * FreeBSD.
    **/
   
-#elif defined(__FreeBSD__)
+#elif defined(__FreeBSD__) || defined(__OpenBSD__)
 #  if _BYTE_ORDER == _BIG_ENDIAN
    ASSERT_EQ(Endianness_Big, Toolbox::DetectEndianness());
 #  else // _LITTLE_ENDIAN