Commit 1ed0d717 authored by Christophe Palmann's avatar Christophe Palmann

ENH: added GDAL config tests

parent 6459f09c
#ifdef WIN32
#define CPL_DISABLE_DLL
#endif
#include "ogr_api.h"
int main(int argc,char * argv[])
{
OGRDataSourceH hDS;
OGRSFDriverH *pahDriver;
OGRRegisterAll();
hDS = OGROpen(argv[1], FALSE, pahDriver );
if( hDS == NULL )
{
return -1;
}
OGRReleaseDataSource( hDS );
return 0;
}
#include <iostream>
#include <stdexcept>
#include <gdal.h>
int main(int argc, char * argv[])
{
if (argc != 2)
{
std::cerr << "Usage : " << argv[0] << "filename" << std::endl;
return 0;//FAIL
}
GDALAllRegister();
GDALOpen(argv[1], GA_ReadOnly );
return 1;//SUCCESS
}
#!/bin/sh
tempFolder=@TEMP@
gdalLibLocation=@GDAL_LIBRARY@
sourceDir=@CMAKE_SOURCE_DIR@
apple=@APPLE@
#TEST 1 : GDAL version
gdalConfig="$(which gdal-config)"
${gdalConfig} --version > ${tempFolder}/testgdal1.txt
#TEST 2 : dyn. symbols
if [ -z "${apple}"]
then
nm -D --defined-only ${gdalLibLocation} | grep TIFFClose > ${tempFolder}/testgdal2.txt
else
nm -U ${gdalLibLocation} | grep TIFFClose > ${tempFolder}/testgdal2.txt # -U : don't display undefined syms (same as --defined-only)
fi
#TEST 3 : Big tiff
gdal_translate -co "BIGTIFF=YES" ${sourceDir}/Modules/ThirdParty/GDAL/logoVectoriel.png ${tempFolder}/logoVectoriel.tif > ${tempFolder}/testgdal3.txt
#TEST 4 : GDAL formats
${gdalConfig} --formats > ${tempFolder}/testgdal4.txt
#include <fstream>
#include <iostream>
#include <sstream>
#include <cstdlib>
#include <vector>
using namespace std;
//----------------- gdal >= 1.10 -------------------------
int main(int argc, char * argv[])
{
const char * inputFilename = argv[1];
ifstream file(inputFilename, ios::in);
if(file)
{
string line;
vector<unsigned int> UIntVect;
getline(file, line);
//Parsing
istringstream iss(line);
unsigned int pos=0;
string sub;
unsigned int someUIntVal;
while ( std::getline( iss, sub, '.' ) )
{
istringstream convert(sub);
convert >> someUIntVal;
//cout << someUIntVal << '\n';
if (pos==0) //Major
UIntVect.push_back(someUIntVal);
if (pos==1) //Minor
UIntVect.push_back(someUIntVal);
pos++;
}
file.close();
if ( (UIntVect[0]<1) || (UIntVect[1]<10) )
{
cout << "WARNING : Version of GDAL must be >= 1.10 (" << UIntVect[0] << "." << UIntVect[1] << " detected)." << endl;
return 1;
}
}
/*else
{
cout << "WARNING : Can't open file " << inputFilename << endl;
return 2;
}*/
return EXIT_SUCCESS;
}
#include <fstream>
#include <iostream>
#include <sstream>
#include <cstdlib>
using namespace std;
//----------------- if internal libtiff/libgeotiff are detected, symbol renaming is mandatory -------------------------
int main(int argc, char * argv[])
{
const char * inputFilename = argv[1];
string pattern1("TIFFClose");
string pattern2("gdal_");
ifstream file(inputFilename, ios::in);
if(file)
{
string line;
while(getline(file, line))
{
if (line.find(pattern1) != string::npos)
if (line.find(pattern2) == string::npos)
{
cout << "WARNING : Internal versions of libtiff/libgeotiff detected without symbol renaming." << endl;
return 1;
}
}
}
/*else
{
cout << "WARNING : Can't open file " << inputFilename << endl;
return 2;
}*/
return EXIT_SUCCESS;
}
#include <fstream>
#include <iostream>
#include <sstream>
#include <cstdlib>
using namespace std;
//----------------- BIGTIFF -------------------------
int main(int argc, char * argv[])
{
const char * inputFilename = argv[1];
string patternDone("done");
ifstream file(inputFilename, ios::in);
if(file)
{
string line;
bool bigtiff=false;
while(getline(file, line))
if (line.find(patternDone) != string::npos)
bigtiff=true;
if (!bigtiff)
{
cout << "WARNING : No BIGTIFF capatilities" << endl;
return 1;
}
}
/*else
{
cout << "WARNING : Can't open file " << inputFilename << endl;
return 2;
}*/
return EXIT_SUCCESS;
}
#include <fstream>
#include <iostream>
#include <sstream>
#include <cstdlib>
using namespace std;
//----------------- FORMAT -------------------------
int main(int argc, char * argv[])
{
const char * inputFilename = argv[1];
string format(argv[2]);
ifstream file(inputFilename, ios::in);
if(file)
{
string line;
while(getline(file, line))
if (line.find(format) != string::npos)
return 1; //SUCCESS
}
/*else
{
cout << "WARNING : Can't open file " << inputFilename << endl;
return 2;
}*/
return 0; //FAIL
}
......@@ -4,4 +4,102 @@ mark_as_advanced(GDAL_INCLUDE_DIR)
mark_as_advanced(GDAL_LIBRARY)
mark_as_advanced(GDAL_CONFIG)
# TODO : backport work from ImportGDAL about tiff, geotiff, driver tests, etc...
\ No newline at end of file
if(NOT GDAL_FOUND)
message(FATAL_ERROR "Cannot find GDAL. Set GDAL_INCLUDE_DIR and GDAL_LIBRARY")
endif()
message(STATUS "Check if Gdal qualifies for Orfeo ToolBox")
# Prepare bash script
configure_file(${CMAKE_SOURCE_DIR}/Modules/ThirdParty/GDAL/gdalTest.sh.in ${CMAKE_CURRENT_BINARY_DIR}/gdalTest.sh @ONLY)
execute_process(COMMAND chmod u+x ${CMAKE_CURRENT_BINARY_DIR}/gdalTest.sh)
execute_process(COMMAND ${CMAKE_CURRENT_BINARY_DIR}/gdalTest.sh)
#------------------- TESTS ---------------------
# Version of GDAL
try_run(RUN_RESULT_VAR1 COMPILE_RESULT_VAR1 ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_SOURCE_DIR}/Modules/ThirdParty/GDAL/gdalTest1.cxx ARGS ${TEMP}/testgdal1.txt)
# test libtiff/libgeotiff and test if symbols are renamed (only for internal libtiff/libgeotiff)
try_run(RUN_RESULT_VAR2 COMPILE_RESULT_VAR2 ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_SOURCE_DIR}/Modules/ThirdParty/GDAL/gdalTest2.cxx ARGS ${TEMP}/testgdal2.txt)
# bigtiff
try_run(RUN_RESULT_VAR3 COMPILE_RESULT_VAR3 ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_SOURCE_DIR}/Modules/ThirdParty/GDAL/gdalTest3.cxx ARGS ${TEMP}/testgdal3.txt)
# formats
try_run(GDAL_HAS_HDF COMPILE_RESULT_VAR4 ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_SOURCE_DIR}/Modules/ThirdParty/GDAL/gdalTest4.cxx ARGS ${TEMP}/testgdal4.txt hdf)
try_run(GDAL_HAS_J2K_JG2000 COMPILE_RESULT_VAR4 ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_SOURCE_DIR}/Modules/ThirdParty/GDAL/gdalTest4.cxx ARGS ${TEMP}/testgdal4.txt jpeg2000)
try_run(GDAL_HAS_J2K_OPJG COMPILE_RESULT_VAR4 ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_SOURCE_DIR}/Modules/ThirdParty/GDAL/gdalTest4.cxx ARGS ${TEMP}/testgdal4.txt openjpeg)
try_run(GDAL_HAS_J2K_KAK COMPILE_RESULT_VAR4 ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_SOURCE_DIR}/Modules/ThirdParty/GDAL/gdalTest4.cxx ARGS ${TEMP}/testgdal4.txt jp2kak)
try_run(GDAL_HAS_J2K_ECW COMPILE_RESULT_VAR4 ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_SOURCE_DIR}/Modules/ThirdParty/GDAL/gdalTest4.cxx ARGS ${TEMP}/testgdal4.txt ecw)
# Has OGR
try_compile(GDAL_HAS_OGR ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_SOURCE_DIR}/Modules/ThirdParty/GDAL/gdalOGRTest.cxx CMAKE_FLAGS "-DINCLUDE_DIRECTORIES:PATH=${GDAL_INCLUDE_DIR}" "-DLINK_LIBRARIES:STRING=${GDAL_LIBRARY}")
# Can open tiff file
try_run(GDAL_CAN_OPEN_TIFF COMPILE_RESULT_OPEN ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_SOURCE_DIR}/Modules/ThirdParty/GDAL/gdalOpenTest.cxx CMAKE_FLAGS "-DINCLUDE_DIRECTORIES:PATH=${GDAL_INCLUDE_DIR}" "-DLINK_LIBRARIES:STRING=${GDAL_LIBRARY}" ARGS ${CMAKE_SOURCE_DIR}/Modules/ThirdParty/GDAL/otb_logo.tif)
# Can open jpeg file
try_run(GDAL_CAN_OPEN_JPEG COMPILE_RESULT_OPEN ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_SOURCE_DIR}/Modules/ThirdParty/GDAL/gdalOpenTest.cxx CMAKE_FLAGS "-DINCLUDE_DIRECTORIES:PATH=${GDAL_INCLUDE_DIR}" "-DLINK_LIBRARIES:STRING=${GDAL_LIBRARY}" ARGS ${CMAKE_SOURCE_DIR}/Modules/ThirdParty/GDAL/otb_logo.jpeg)
# Can open jpeg2000 file
try_run(GDAL_CAN_OPEN_JPEG2000 COMPILE_RESULT_OPEN ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_SOURCE_DIR}/Modules/ThirdParty/GDAL/gdalOpenTest.cxx CMAKE_FLAGS "-DINCLUDE_DIRECTORIES:PATH=${GDAL_INCLUDE_DIR}" "-DLINK_LIBRARIES:STRING=${GDAL_LIBRARY}" ARGS ${CMAKE_SOURCE_DIR}/Modules/ThirdParty/GDAL/QB_multicomp_small.jpx)
# Can open geotiff file
#try_run(GDAL_CAN_OPEN_GEOTIFF COMPILE_RESULT_OPEN ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_SOURCE_DIR}/Modules/ThirdParty/GDAL/gdalOpenTest.cxx CMAKE_FLAGS "-DINCLUDE_DIRECTORIES:PATH=${GDAL_INCLUDE_DIR}" "-DLINK_LIBRARIES:STRING=${GDAL_LIBRARY}" ARGS ${CMAKE_SOURCE_DIR}/Modules/ThirdParty/GDAL/GEOTIFF)
#------------------- TESTS (END)---------------------
# Compilations checking
if (NOT COMPILE_RESULT_VAR1)
message(WARNING "Modules/ThirdParty/GDAL/gdalTest1.cxx did not compile.")
endif()
if (NOT COMPILE_RESULT_VAR2)
message(WARNING "Modules/ThirdParty/GDAL/gdalTest2.cxx did not compile.")
endif()
if (NOT COMPILE_RESULT_VAR3)
message(WARNING "Modules/ThirdParty/GDAL/gdalTest3.cxx did not compile.")
endif()
if (NOT COMPILE_RESULT_VAR4)
message(WARNING "Modules/ThirdParty/GDAL/gdalTest4.cxx did not compile.")
endif()
if (NOT COMPILE_RESULT_OPEN)
message(WARNING "Modules/ThirdParty/GDAL/gdalOpenTest.cxx did not compile.")
endif()
# Warning messages
if (${RUN_RESULT_VAR1} EQUAL 1)
message(WARNING "Version of GDAL must be >= 1.10")
endif()
if (${RUN_RESULT_VAR2} EQUAL 1)
message(WARNING "Internal versions of libtiff/libgeotiff detected without symbol renaming (when configuring GDAL, if options --with-libtiff or --with-geotiff are set to 'internal', then options --with-rename-internal-libtiff-symbols and --with-rename-internal-libgeotiff-symbols should be set to 'yes').")
endif()
if (${RUN_RESULT_VAR3} EQUAL 1)
message(WARNING "No BIGTIFF capatilities.")
endif()
if (NOT GDAL_HAS_HDF)
message(WARNING "No HDF capatilities.")
endif()
if (NOT GDAL_HAS_J2K_JG2000 AND NOT GDAL_HAS_J2K_OPJG AND NOT GDAL_HAS_J2K_KAK AND NOT GDAL_HAS_J2K_ECW)
message(WARNING "No Jpeg2000 driver found (compatible drivers are : OpenJpeg, Kakadu, ECW).")
endif()
if (NOT GDAL_HAS_OGR)
message(WARNING "GDAL doesn't expose OGR library symbols.")
endif()
if (NOT GDAL_CAN_OPEN_TIFF)
message(WARNING "GDAL can't open tiff files.")
endif()
if (NOT GDAL_CAN_OPEN_JPEG)
message(WARNING "GDAL can't open jpeg files.")
endif()
if (NOT GDAL_CAN_OPEN_JPEG2000)
message(WARNING "GDAL can't open jpeg files.")
endif()
#if (NOT GDAL_CAN_OPEN_GEOTIFF)
# message(WARNING "GDAL can't open geotiff files.")
#endif()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment