changeset 626:e0277d16a938

sync
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 29 Aug 2023 11:34:49 +0200
parents 7e00f78a27b1
children 842449d57b4b
files Resources/Orthanc/CMake/Compiler.cmake Resources/Orthanc/Plugins/OrthancPluginCppWrapper.cpp
diffstat 2 files changed, 30 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/Resources/Orthanc/CMake/Compiler.cmake	Tue Aug 29 11:32:44 2023 +0200
+++ b/Resources/Orthanc/CMake/Compiler.cmake	Tue Aug 29 11:34:49 2023 +0200
@@ -263,3 +263,24 @@
   # preceding batches. https://cmake.org/Bug/view.php?id=14874
   set(CMAKE_CXX_ARCHIVE_APPEND "<CMAKE_AR> <LINK_FLAGS> q <TARGET> <OBJECTS>")
 endif()
+
+
+# This function defines macro "__ORTHANC_FILE__" as a replacement to
+# macro "__FILE__", as the latter leaks the full path of the source
+# files in the binaries
+# https://stackoverflow.com/questions/8487986/file-macro-shows-full-path
+# https://twitter.com/wget42/status/1676877802375634944?s=20
+function(DefineSourceBasenameForTarget targetname)
+  # Microsoft Visual Studio is extremely slow if using
+  # "set_property()", we only enable this feature for gcc and clang
+  if (CMAKE_COMPILER_IS_GNUCXX OR
+      CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
+    get_target_property(source_files "${targetname}" SOURCES)
+    foreach(sourcefile ${source_files})
+      get_filename_component(basename "${sourcefile}" NAME)
+      set_property(
+        SOURCE "${sourcefile}" APPEND
+        PROPERTY COMPILE_DEFINITIONS "__ORTHANC_FILE__=\"${basename}\"")
+    endforeach()
+  endif()
+endfunction()
--- a/Resources/Orthanc/Plugins/OrthancPluginCppWrapper.cpp	Tue Aug 29 11:32:44 2023 +0200
+++ b/Resources/Orthanc/Plugins/OrthancPluginCppWrapper.cpp	Tue Aug 29 11:34:49 2023 +0200
@@ -1670,15 +1670,16 @@
       return true;
     }
 
+#ifdef _MSC_VER
+#define ORTHANC_SCANF sscanf_s
+#else
+#define ORTHANC_SCANF sscanf
+#endif
+
     // Parse the version
-    int aa, bb, cc;
-    if (
-#ifdef _MSC_VER
-      sscanf_s
-#else
-      sscanf
-#endif
-      (version, "%4d.%4d.%4d", &aa, &bb, &cc) != 3 ||
+    int aa, bb, cc = 0;
+    if ((ORTHANC_SCANF(version, "%4d.%4d.%4d", &aa, &bb, &cc) != 3 &&
+         ORTHANC_SCANF(version, "%4d.%4d", &aa, &bb) != 2) ||
       aa < 0 ||
       bb < 0 ||
       cc < 0)