[trunk] Fix compilation when TIFF lib is neither found nor compiled
[openjpeg.git] / tests / nonregression / checkmd5refs.cmake
index fd583e2abcd9335f328d055d5a6ad36dd93b4ca0..f94d7c092b45b66f1bc84df2a7a365bea0e63fab 100644 (file)
 #message("0: ${REFFILE}")
 #message("1: ${CMAKE_CURRENT_BINARY_DIR}")
 #message("2: ${FILENAME}")
-execute_process(
-  COMMAND ${CMAKE_COMMAND} -E md5sum ${FILENAME}.png
-  WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/Temporary
-  RESULT_VARIABLE res
-  OUTPUT_VARIABLE output
-  ERROR_VARIABLE  error_output
-  OUTPUT_STRIP_TRAILING_WHITESPACE # important
-)
-
-# Pass the output back to ctest
-if(res)
-  message(SEND_ERROR "md5 could not be computed, it failed with value ${res}. Output was: ${error_output}")
+#get_filename_component(pgxfile ${pgxfullpath} NAME)
+get_filename_component(OUTFILENAME_NAME ${OUTFILENAME} NAME)
+string(FIND ${OUTFILENAME_NAME} "." SHORTEST_EXT_POS REVERSE)
+string(SUBSTRING ${OUTFILENAME_NAME} 0 ${SHORTEST_EXT_POS} OUTFILENAME_NAME_WE)
+#message("3: ${OUTFILENAME_NAME}")
+#message("4: ${OUTFILENAME_NAME_WE}")
+#file(GLOB globfiles "Temporary/${FILENAME}*.pgx" "Temporary/${FILENAME}*.png")
+file(GLOB globfiles "Temporary/${OUTFILENAME_NAME_WE}*.pgx" "Temporary/${OUTFILENAME_NAME_WE}*.png")
+#message("6: ${globfiles}")
+if(NOT globfiles)
+  message(SEND_ERROR "Could not find output PGX files: ${OUTFILENAME_NAME_WE}")
 endif()
 
-#message("3: ${output}")
-
+# REFFILE follow what md5sum -c would expect as input:
 file(READ ${REFFILE} variable)
-#message("4: ${variable}")
-string(REGEX MATCH "^.*${FILENAME}.png" output_var ${variable})
+#string(REGEX REPLACE "\r?\n" ";" variable "${variable}")
 
-#message("5: ${output_var}")
-
-if("${output_var}" STREQUAL "${output}")
-  #message("6: eqal")
-else()
-  message(SEND_ERROR "not equal: [${output_var}] vs [${output}]")
-endif()
+foreach(pgxfullpath ${globfiles})
+  get_filename_component(pgxfile ${pgxfullpath} NAME)
+  #message("8: ${pgxfile}")
+  execute_process(
+    COMMAND ${CMAKE_COMMAND} -E md5sum ${pgxfile}
+    WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/Temporary
+    RESULT_VARIABLE res
+    OUTPUT_VARIABLE output
+    ERROR_VARIABLE  error_output
+    OUTPUT_STRIP_TRAILING_WHITESPACE # important
+  )
+  
+  # Pass the output back to ctest
+  if(res)
+    message(SEND_ERROR "md5 could not be computed, it failed with value ${res}. Output was: ${error_output}")
+  endif()
+  #message("3: ${output}")
+  
+  #message("4: ${variable}")
+  string(REGEX MATCH "[0-9a-f]+  ${pgxfile}" output_var "${variable}")
+  #message("5: ${output_var}")
+  
+  if("${output_var}" STREQUAL "${output}")
+    #message("6: eqal")
+  else()
+    message(SEND_ERROR "not equal: [${output_var}] vs [${output}]")
+  endif()
+endforeach()