From: malaterre Date: Tue, 5 Jul 2005 23:27:46 +0000 (+0000) Subject: ENH: Adding a cmake script to find which compiler return NULL on malloc(0) X-Git-Tag: Version1.2.bp~366 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=491464726aaa589a3d82eedd0479f754748b47ee;p=gdcm.git ENH: Adding a cmake script to find which compiler return NULL on malloc(0) --- diff --git a/src/gdcmjasper/CMakeLists.txt b/src/gdcmjasper/CMakeLists.txt index 5298f6dc..5d81feb2 100644 --- a/src/gdcmjasper/CMakeLists.txt +++ b/src/gdcmjasper/CMakeLists.txt @@ -1,5 +1,35 @@ PROJECT(GDCMJASPER C) +#----------------------------------------------------------------------------- +# Test how compiler handle the case of a malloc(0). If it returns 0 +# then we are doomed (jasper does not support this case) +IF("NULL_ON_MALLOC_0" MATCHES "^NULL_ON_MALLOC_0$") + STRING(ASCII 35 POUND) + FILE(WRITE ${GDCMJASPER_BINARY_DIR}/jasperNULLmalloc.c + "${POUND}include \n" + "int main() { return (int)malloc(0); }") + MESSAGE(STATUS "Checking if compiler return NULL on malloc(0)") + TRY_RUN(RESULT_NULL_ON_MALLOC_0 COMPILE_NULL_ON_MALLOC_0 + "${GDCMJASPER_BINARY_DIR}" + "${GDCMJASPER_BINARY_DIR}/jasperNULLmalloc.c" + OUTPUT_VARIABLE OUTPUT) + IF(NULL_ON_MALLOC_0) + MESSAGE(STATUS "Checking if compiler return NULL on malloc(0) -- yes") + SET(NULL_ON_MALLOC_0 1 CACHE INTERNAL "Check if compiler returns NULL on malloc(0)") + WRITE_FILE(${CMAKE_BINARY_DIR}/CMakeOutput.log + "Determining how compiler implement malloc(0)" + "passed with the following output:\n" + "${OUTPUT}\n" APPEND) + ELSE(NULL_ON_MALLOC_0) + MESSAGE(STATUS "Checking if ifreq has a sa_len -- no") + SET(NULL_ON_MALLOC_0 0 CACHE INTERNAL "Check if compiler returns NULL on malloc(0)") + WRITE_FILE(${CMAKE_BINARY_DIR}/CMakeError.log + "Determining how compiler implement malloc(0)" + "failed with the following output:\n" + "${OUTPUT}\n" APPEND) + ENDIF(NULL_ON_MALLOC_0) +ENDIF("NULL_ON_MALLOC_0" MATCHES "^NULL_ON_MALLOC_0$") + #OPTION(HAVE_LIBJPEG "Do you have ijg" OFF) IF(GDCM_SOURCE_DIR) SET(HAVE_LIBJPEG ON CACHE BOOL "Do you have ijg" FORCE)