changeset 4097:99e2054d1e8d

fix unit tests for orthanc framework
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 01 Jul 2020 11:15:29 +0200
parents d633e5bb7ba3
children 64e92ffbba0f
files OrthancFramework/Resources/CMake/DownloadOrthancFramework.cmake OrthancFramework/SharedLibrary/CMakeLists.txt OrthancFramework/UnitTestsSources/CMakeLists.txt
diffstat 3 files changed, 29 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancFramework/Resources/CMake/DownloadOrthancFramework.cmake	Wed Jul 01 08:42:21 2020 +0200
+++ b/OrthancFramework/Resources/CMake/DownloadOrthancFramework.cmake	Wed Jul 01 11:15:29 2020 +0200
@@ -505,28 +505,36 @@
       ${ORTHANC_FRAMEWORK_ROOT}
       )
   endif()
+
+  if (${ORTHANC_FRAMEWORK_INCLUDE_DIR} STREQUAL "ORTHANC_FRAMEWORK_INCLUDE_DIR-NOTFOUND")
+    message(FATAL_ERROR "Cannot locate the OrthancFramework.h header")
+  endif()
   
   message("Orthanc framework include dir: ${ORTHANC_FRAMEWORK_INCLUDE_DIR}")
   include_directories(${ORTHANC_FRAMEWORK_INCLUDE_DIR})
   
-  set(CMAKE_REQUIRED_INCLUDES "${ORTHANC_FRAMEWORK_INCLUDE_DIR}")
+  if ("${ORTHANC_FRAMEWORK_LIBDIR}" STREQUAL "")
+    set(ORTHANC_FRAMEWORK_LIBRARIES OrthancFramework)
+  else()
+    if (MSVC)
+      set(Suffix ".lib")
+      set(Prefix "")
+    else()
+      list(GET CMAKE_FIND_LIBRARY_PREFIXES 0 Prefix)
+      list(GET CMAKE_FIND_LIBRARY_SUFFIXES 0 Suffix)
+    endif()
+    set(ORTHANC_FRAMEWORK_LIBRARIES ${ORTHANC_FRAMEWORK_LIBDIR}/${Prefix}OrthancFramework${Suffix})
+  endif()
 
-  if (NOT "${ORTHANC_FRAMEWORK_LIBDIR}" STREQUAL "")
-    set(CMAKE_REQUIRED_LIBRARIES "-L${ORTHANC_FRAMEWORK_LIBDIR} -lOrthancFramework")
-  else()
-    set(CMAKE_REQUIRED_LIBRARIES "OrthancFramework")
-  endif()
+  set(CMAKE_REQUIRED_INCLUDES "${ORTHANC_FRAMEWORK_INCLUDE_DIR}")
+  set(CMAKE_REQUIRED_LIBRARIES "${ORTHANC_FRAMEWORK_LIBRARIES}")
   
   check_cxx_symbol_exists("Orthanc::InitializeFramework" "OrthancFramework.h" HAVE_ORTHANC_FRAMEWORK)
-  if(NOT HAVE_ORTHANC_FRAMEWORK)
+  if (NOT HAVE_ORTHANC_FRAMEWORK)
     message(FATAL_ERROR "Cannot find the Orthanc framework")
   endif()
 
   if (NOT "${ORTHANC_FRAMEWORK_ROOT}" STREQUAL "")
     include_directories(${ORTHANC_FRAMEWORK_ROOT})
   endif()
-
-  if (NOT "${ORTHANC_FRAMEWORK_LIBDIR}" STREQUAL "")
-    link_directories(${ORTHANC_FRAMEWORK_LIBDIR})
-  endif()
 endif()
--- a/OrthancFramework/SharedLibrary/CMakeLists.txt	Wed Jul 01 08:42:21 2020 +0200
+++ b/OrthancFramework/SharedLibrary/CMakeLists.txt	Wed Jul 01 11:15:29 2020 +0200
@@ -462,7 +462,11 @@
   if (CMAKE_TOOLCHAIN_FILE)
     # Take absolute path to the toolchain
     get_filename_component(TMP ${CMAKE_TOOLCHAIN_FILE} REALPATH BASE ${CMAKE_SOURCE_DIR}/..)
-    list(APPEND Flags -DCMAKE_TOOLCHAIN_FILE=${TMP})
+    list(APPEND Flags
+      -DCMAKE_TOOLCHAIN_FILE=${TMP}
+      -DLSB_CC=${LSB_CC}
+      -DLSB_CXX=${LSB_CXX}
+      )
   endif()
 
   # Build the unit tests, linking them against the just-created
--- a/OrthancFramework/UnitTestsSources/CMakeLists.txt	Wed Jul 01 08:42:21 2020 +0200
+++ b/OrthancFramework/UnitTestsSources/CMakeLists.txt	Wed Jul 01 11:15:29 2020 +0200
@@ -9,8 +9,6 @@
 set(STATIC_BUILD OFF CACHE BOOL "Static build of the third-party libraries (necessary for Windows)")
 set(UNIT_TESTS_WITH_HTTP_CONNEXIONS ON CACHE BOOL "Allow unit tests to make HTTP requests")
 set(USE_GOOGLE_TEST_DEBIAN_PACKAGE OFF CACHE BOOL "Use the sources of Google Test shipped with libgtest-dev (Debian only)")
-set(USE_SYSTEM_GOOGLE_TEST ON CACHE BOOL "Use the system version of Google Test")
-set(USE_SYSTEM_JSONCPP ON CACHE BOOL "Use the system version of JsonCpp")
 
 if (UNIT_TESTS_WITH_HTTP_CONNEXIONS)
   add_definitions(-DUNIT_TESTS_WITH_HTTP_CONNEXIONS=1)
@@ -23,12 +21,15 @@
   set(ENABLE_LUA ON)
   set(ENABLE_PUGIXML ON)
   set(ENABLE_SQLITE ON)
+
+  set(USE_SYSTEM_GOOGLE_TEST ON CACHE BOOL "Use the system version of Google Test")
+else()
+  set(USE_SYSTEM_GOOGLE_TEST OFF CACHE INTERNAL "")
 endif()
   
 set(ENABLE_GOOGLE_TEST ON)
 include(${CMAKE_SOURCE_DIR}/../Resources/CMake/DownloadOrthancFramework.cmake)
 include(${CMAKE_SOURCE_DIR}/../Resources/CMake/GoogleTestConfiguration.cmake)
-include(${CMAKE_SOURCE_DIR}/../Resources/CMake/JsonCppConfiguration.cmake)
 
 add_definitions(
   -DORTHANC_UNIT_TESTS_LINK_FRAMEWORK=1
@@ -60,9 +61,7 @@
   ${GOOGLE_TEST_SOURCES}
   )
 
-target_link_libraries(UnitTests OrthancFramework)
-set_target_properties(UnitTests PROPERTIES BUILD_WITH_INSTALL_RPATH TRUE)
-set_target_properties(UnitTests PROPERTIES INSTALL_RPATH ${ORTHANC_FRAMEWORK_LIBDIR})
+target_link_libraries(UnitTests ${ORTHANC_FRAMEWORK_LIBRARIES})
 
 install(TARGETS UnitTests
   DESTINATION ${ORTHANC_FRAMEWORK_LIBDIR}