]> Creatis software - gdcm.git/commitdiff
ENH: properly handle compiler that does not have __FUNCTION__
authormalaterre <malaterre>
Fri, 7 Jan 2005 21:09:42 +0000 (21:09 +0000)
committermalaterre <malaterre>
Fri, 7 Jan 2005 21:09:42 +0000 (21:09 +0000)
CMakeLists.txt
gdcmConfigure.h.in
src/gdcmDebug.h
src/gdcmDicomDir.cxx

index 23ba5c0801014654093015683694f01d48d7ce99..5ff95b1b256b019901b458e1c1ab8a9607bdcb79 100644 (file)
@@ -27,6 +27,30 @@ SET (EXECUTABLE_OUTPUT_PATH ${GDCM_BINARY_DIR}/bin CACHE PATH "Single output dir
 SET (LIBRARY_OUTPUT_PATH ${GDCM_BINARY_DIR}/bin CACHE PATH "Single output directory for building all libraries.")
 MARK_AS_ADVANCED(LIBRARY_OUTPUT_PATH EXECUTABLE_OUTPUT_PATH)
 
+#-----------------------------------------------------------------------------
+# Test if compiler defines __FUNCTION__
+IF("GDCM_COMPILER_HAS_FUNCTION" MATCHES "^GDCM_COMPILER_HAS_FUNCTION$")
+  MESSAGE(STATUS "Checking support for __FUNCTION__ in compiler")
+  TRY_COMPILE(GDCM_COMPILER_HAS_FUNCTION
+              ${GDCM_BINARY_DIR}/CMakeTmp/Function
+              ${GDCM_SOURCE_DIR}/gdcmTestFUNCTION.cxx
+              OUTPUT_VARIABLE OUTPUT)
+  IF(GDCM_COMPILER_HAS_FUNCTION)
+    MESSAGE(STATUS "Checking support for __FUNCTION__ -- yes")
+    SET(GDCM_COMPILER_HAS_FUNCTION 1 CACHE INTERNAL "Support for extention C __FUNCTION__")
+    WRITE_FILE(${CMAKE_BINARY_DIR}/CMakeOutput.log
+      "Determining if the C compiler supports __FUNCTION__ "
+      "passed with the following output:\n"
+      "${OUTPUT}\n" APPEND)
+  ELSE(GDCM_COMPILER_HAS_FUNCTION)
+    MESSAGE(STATUS "Checking support for __FUNCTION__ -- no")
+    SET(GDCM_COMPILER_HAS_FUNCTION 0 CACHE INTERNAL "Support for extension C __FUNCTION__")
+    WRITE_FILE(${CMAKE_BINARY_DIR}/CMakeError.log
+      "Determining if the C compiler supports __FUNCTION__ "
+      "failed with the following output:\n"
+      "${OUTPUT}\n" APPEND)
+  ENDIF(GDCM_COMPILER_HAS_FUNCTION)
+ENDIF("GDCM_COMPILER_HAS_FUNCTION" MATCHES "^GDCM_COMPILER_HAS_FUNCTION$")
 #-----------------------------------------------------------------------------
 # Build directory on which many applications depend
 SUBDIRS(
index 473e5bd10b59a7a4b12dd09767feccfb1c5b91bb..3a6f66c47cdae7c0b20c1cd3d0cd58bdfbd87b58 100644 (file)
@@ -34,6 +34,9 @@
 /* This was important as long as GDCM is LGPL */
 #cmakedefine BUILD_SHARED_LIBS
 
+/* GDCM uses __FUNCTION__ which is not ANSI C, but C99 */
+#cmakedefine GDCM_COMPILER_HAS_FUNCTION
+
 
 /*--------------------------------------------------------------------------*/
 /* GDCM Versioning                                                          */
index a46a60bb6fb731bbe6de29edf8ad66d4a9f7777d..44660c097ae7a329a71c6641a394ce7da0807915 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDebug.h,v $
   Language:  C++
-  Date:      $Date: 2005/01/07 20:31:36 $
-  Version:   $Revision: 1.14 $
+  Date:      $Date: 2005/01/07 21:09:42 $
+  Version:   $Revision: 1.15 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -57,9 +57,17 @@ public:
 
 // __FUNCTION is not always defined by preprocessor
 // In c++ we should use __PRETTY_FUNCTION__ instead...
-#ifndef __GNUC__
-#  define __FUNCTION__ "<unknow>"
-#endif
+#ifdef GDCM_COMPILER_HAS_FUNCTION
+// Handle particular case for GNU C++ which also defines __PRETTY_FUNCTION__
+// which is a lot nice in C++
+#ifdef __GNUC__
+#  define GDCM_FUNCTION __PRETTY_FUNCTION__
+#else
+#  define GDCM_FUNCTION __FUNCTION__ 
+#endif //__GNUC__
+#else
+#  define GDCM_FUNCTION "<unknow>"
+#endif //GDCM_COMPILER_HAS_FUNCTION
 
 /**
  * \brief   Debug
@@ -71,7 +79,7 @@ public:
    {                                                       \
    std::ostringstream osmacro;                             \
    osmacro << "Debug: In " __FILE__ ", line " << __LINE__  \
-           << ", function " << __FUNCTION__ << '\n'        \
+           << ", function " << GDCM_FUNCTION << '\n'       \
            << msg << "\n\n";                               \
    std::cerr << osmacro.str() << std::endl;                \
    }                                                       \
@@ -87,7 +95,7 @@ public:
    {                                                        \
    std::ostringstream osmacro;                              \
    osmacro << "Verbose: In " __FILE__ ", line " << __LINE__ \
-           << ", function " << __FUNCTION__ << "\n"         \
+           << ", function " << GDCM_FUNCTION << "\n"        \
            << msg << "\n\n";                                \
    std::cerr << osmacro.str() << std::endl;                 \
    }                                                        \
@@ -103,7 +111,7 @@ public:
    {                                                      \
    std::ostringstream osmacro;                            \
    osmacro << "Error: In " __FILE__ ", line " << __LINE__ \
-           << ", function " << __FUNCTION__ << '\n'       \
+           << ", function " << GDCM_FUNCTION << '\n'      \
            << msg << "\n\n";                              \
    std::cerr << osmacro.str() << std::endl;               \
    exit(1);                                               \
@@ -122,7 +130,7 @@ public:
    {                                                       \
    std::ostringstream osmacro;                             \
    osmacro << "Assert: In " __FILE__ ", line " << __LINE__ \
-           << ", function " << __FUNCTION__                \
+           << ", function " << GDCM_FUNCTION               \
            << "\n\n";                                      \
    std::cerr << osmacro.str() << std::endl;                \
    assert ( arg );                                         \
index c12a9a6f13c99970bba07ff357267faa5b789b41..a68960f0653f00e919086be3940d289806cf7403 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDicomDir.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/01/07 19:20:38 $
-  Version:   $Revision: 1.94 $
+  Date:      $Date: 2005/01/07 21:09:42 $
+  Version:   $Revision: 1.95 $
   
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
 #include <sys/types.h>
 
 #ifdef _MSC_VER
-#define getcwd _getcwd
+#   define getcwd _getcwd
 #endif
 
-#if defined( _MSC_VER) || defined(__BORLANDC__)
-   #include <direct.h>
+#if defined(_MSC_VER) || defined(__BORLANDC__)
+#   include <direct.h>
 #else
-   #include <unistd.h>
+#   include <unistd.h>
 #endif
 
 namespace gdcm