From 9d913797d3bf5a18625f4d8d8b42c8f5c8c10d99 Mon Sep 17 00:00:00 2001 From: malaterre Date: Fri, 7 Jan 2005 21:09:42 +0000 Subject: [PATCH] ENH: properly handle compiler that does not have __FUNCTION__ --- CMakeLists.txt | 24 ++++++++++++++++++++++++ gdcmConfigure.h.in | 3 +++ src/gdcmDebug.h | 26 +++++++++++++++++--------- src/gdcmDicomDir.cxx | 12 ++++++------ 4 files changed, 50 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 23ba5c08..5ff95b1b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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( diff --git a/gdcmConfigure.h.in b/gdcmConfigure.h.in index 473e5bd1..3a6f66c4 100644 --- a/gdcmConfigure.h.in +++ b/gdcmConfigure.h.in @@ -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 */ diff --git a/src/gdcmDebug.h b/src/gdcmDebug.h index a46a60bb..44660c09 100644 --- a/src/gdcmDebug.h +++ b/src/gdcmDebug.h @@ -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__ "" -#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 "" +#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 ); \ diff --git a/src/gdcmDicomDir.cxx b/src/gdcmDicomDir.cxx index c12a9a6f..a68960f0 100644 --- a/src/gdcmDicomDir.cxx +++ b/src/gdcmDicomDir.cxx @@ -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 @@ -38,13 +38,13 @@ #include #ifdef _MSC_VER -#define getcwd _getcwd +# define getcwd _getcwd #endif -#if defined( _MSC_VER) || defined(__BORLANDC__) - #include +#if defined(_MSC_VER) || defined(__BORLANDC__) +# include #else - #include +# include #endif namespace gdcm -- 2.45.1