diff options
| author | Mike Taves <mwtoews@gmail.com> | 2020-03-21 14:16:00 +1300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-03-21 14:16:00 +1300 |
| commit | b76acd354ca376194fb1fb682e5347dbf2e20f8d (patch) | |
| tree | 2112c2a945ab8470373bbc1539b5d5e01c686885 /test/postinstall | |
| parent | 56b0d6c5066205be5a046b6a999681b9197246bf (diff) | |
| download | PROJ-b76acd354ca376194fb1fb682e5347dbf2e20f8d.tar.gz PROJ-b76acd354ca376194fb1fb682e5347dbf2e20f8d.zip | |
Add post-install checks for CMake and Autotools/pkg-config (#2077)
* Checks CMake's find_package(PROJ) and find_package(PROJ4)
* Checks pkg-config used with a Makefile (Linux and macOS only)
* Use proj.h / libproj with a simple 'testappprojinfo'
Diffstat (limited to 'test/postinstall')
| -rwxr-xr-x | test/postinstall/test_cmake.bat | 40 | ||||
| -rwxr-xr-x | test/postinstall/test_cmake.sh | 43 | ||||
| -rwxr-xr-x | test/postinstall/test_pkg-config.sh | 83 | ||||
| -rw-r--r-- | test/postinstall/testappprojinfo/CMakeLists.txt | 58 | ||||
| -rw-r--r-- | test/postinstall/testappprojinfo/Makefile | 15 | ||||
| -rw-r--r-- | test/postinstall/testappprojinfo/testappprojinfo.c | 19 |
6 files changed, 258 insertions, 0 deletions
diff --git a/test/postinstall/test_cmake.bat b/test/postinstall/test_cmake.bat new file mode 100755 index 00000000..d2e7baaf --- /dev/null +++ b/test/postinstall/test_cmake.bat @@ -0,0 +1,40 @@ +@echo off +:: Post-install tests with CMake +:: +:: First required argument is the installed prefix, which +:: is used to set CMAKE_PREFIX_PATH + +echo Running post-install tests with CMake + +set CMAKE_PREFIX_PATH=%1 +if not defined CMAKE_PREFIX_PATH ( + echo First positional argument CMAKE_PREFIX_PATH required + exit /B 1 +) + +echo CMAKE_PREFIX_PATH=%CMAKE_PREFIX_PATH% + +cd %~dp0 + +cd testappprojinfo +del /f /q build 2> nul + +:: Check CMake project name PROJ +md build +cd build +cmake -G "%VS_FULL%" -DCMAKE_PREFIX_PATH=%CMAKE_PREFIX_PATH% -DUSE_PROJ_NAME=PROJ .. || exit /B 2 +cmake --build . --config Release || exit /B 3 +ctest --build-config Release -VV || exit /B 4 +cd .. +del /f /q build + +:: Check legacy CMake project name PROJ4 +md build +cd build +cmake -G "%VS_FULL%" -DCMAKE_PREFIX_PATH=%CMAKE_PREFIX_PATH% -DUSE_PROJ_NAME=PROJ4 .. || exit /B 2 +cmake --build . --config Release || exit /B 3 +ctest --build-config Release -VV || exit /B 4 +cd .. +del /f /q build + +cd .. diff --git a/test/postinstall/test_cmake.sh b/test/postinstall/test_cmake.sh new file mode 100755 index 00000000..e72af7c7 --- /dev/null +++ b/test/postinstall/test_cmake.sh @@ -0,0 +1,43 @@ +#!/bin/sh + +# Post-install tests with CMake +# +# First required argument is the installed prefix, which +# is used to set CMAKE_PREFIX_PATH + +set -e + +echo "Running post-install tests with CMake" + +CMAKE_PREFIX_PATH=$1 +if [ -z "$CMAKE_PREFIX_PATH" ]; then + echo "First positional argument CMAKE_PREFIX_PATH required" + exit 1 +fi + +echo "CMAKE_PREFIX_PATH=$CMAKE_PREFIX_PATH" + +cd $(dirname $0) + +cd testappprojinfo +rm -rf build + +# Check CMake project name PROJ +mkdir build +cd build +cmake -DCMAKE_PREFIX_PATH=$CMAKE_PREFIX_PATH -DUSE_PROJ_NAME=PROJ -DCMAKE_VERBOSE_MAKEFILE=ON .. +cmake --build . +ctest -VV . +cd .. +rm -rf build + +# Check legacy CMake project name PROJ4 +mkdir build +cd build +cmake -DCMAKE_PREFIX_PATH=$CMAKE_PREFIX_PATH -DUSE_PROJ_NAME=PROJ4 -DCMAKE_VERBOSE_MAKEFILE=ON .. +cmake --build . +ctest -VV . +cd .. +rm -rf build + +cd .. diff --git a/test/postinstall/test_pkg-config.sh b/test/postinstall/test_pkg-config.sh new file mode 100755 index 00000000..fc7fb8b7 --- /dev/null +++ b/test/postinstall/test_pkg-config.sh @@ -0,0 +1,83 @@ +#!/bin/sh + +# Post-install tests with pkg-config +# +# First required argument is the installed prefix, which +# is used to set PKG_CONFIG_PATH and LD_LIBRARY_PATH + +set -e + +echo "Running post-install tests with pkg-config" + +prefix=$1 +if [ -z "$prefix" ]; then + echo "First positional argument to the the installed prefix is required" + exit 1 +fi + +export PKG_CONFIG_PATH=$prefix/lib/pkgconfig +export LD_LIBRARY_PATH=$prefix/lib + +echo "PKG_CONFIG_PATH=$PKG_CONFIG_PATH" + +PKG_CONFIG_MODVERSION=$(pkg-config proj --modversion) +echo "pkg-config proj --modversion: $PKG_CONFIG_MODVERSION" +PKG_CONFIG_DATADIR=$(pkg-config proj --variable=datadir) +echo "pkg-config proj --variable=datadir: $PKG_CONFIG_DATADIR" + +UNAME=$(uname) +case $UNAME in + Darwin*) + alias ldd="otool -L" ;; + Linux*) + ;; + *) + echo "no ldd equivalent found for UNAME=$UNAME" + exit 1 ;; +esac + +cd $(dirname $0) + +PROGRAM=testappprojinfo +cd $PROGRAM +make + +# Run tests from shell, count any errors +ERRORS=0 + +LDD_OUTPUT=$(ldd ./$PROGRAM | grep proj) +LDD_SUBSTR=$LD_LIBRARY_PATH/libproj. +printf "Testing expected ldd output ... " +case "$LDD_OUTPUT" in + *$LDD_SUBSTR*) + echo "passed" ;; + *) + ERRORS=$(($ERRORS + 1)) + echo "failed: ldd output '$LDD_OUTPUT' does not contain '$LDD_SUBSTR'" ;; +esac + +SEARCHPATH_OUTPUT=$(./$PROGRAM -s) +printf "Testing expected searchpath/datadir ... " +case "$SEARCHPATH_OUTPUT" in + *$PKG_CONFIG_DATADIR*) + echo "passed" ;; + *) + ERRORS=$(($ERRORS + 1)) + echo "failed: searchpath '$SEARCHPATH_OUTPUT' does not contain '$PKG_CONFIG_DATADIR'" ;; +esac + +VERSION_OUTPUT=$(./$PROGRAM -v) +printf "Testing expected version ... " +case "$VERSION_OUTPUT" in + $PKG_CONFIG_MODVERSION) + echo "passed" ;; + *) + ERRORS=$(($ERRORS + 1)) + echo "failed: '$VERSION_OUTPUT' != '$PKG_CONFIG_MODVERSION'" ;; +esac + +make clean + +cd .. + +exit $ERRORS diff --git a/test/postinstall/testappprojinfo/CMakeLists.txt b/test/postinstall/testappprojinfo/CMakeLists.txt new file mode 100644 index 00000000..2405bc8c --- /dev/null +++ b/test/postinstall/testappprojinfo/CMakeLists.txt @@ -0,0 +1,58 @@ +cmake_minimum_required(VERSION 3.5) +project(testappprojinfo LANGUAGES C) + +set(USE_PROJ_NAME "PROJ" + CACHE STRING "Either PROJ (default) or PROJ4") + +find_package(${USE_PROJ_NAME}) + +# Show some target properties +get_cmake_property(_variableNames VARIABLES) +list(SORT _variableNames) +foreach(_variableName ${_variableNames}) + string(REGEX MATCH "^${USE_PROJ_NAME}_" _matched ${_variableName}) + if(NOT ${_matched} STREQUAL "") + message(STATUS "${_variableName}=${${_variableName}}") + endif() +endforeach() + +add_executable(testappprojinfo testappprojinfo.c) +target_link_libraries(testappprojinfo ${${USE_PROJ_NAME}_LIBRARIES}) + +include(CTest) + +if(APPLE) + set(LDD_CL "otool -L") + set(EXPECTED_LDD_CL_OUT "@rpath/libproj") +elseif(UNIX) + set(LDD_CL "ldd") + set(EXPECTED_LDD_CL_OUT "${CMAKE_PREFIX_PATH}/lib/libproj") +endif() + +if(LDD_CL) + add_test(NAME test_ldd + COMMAND sh -c "${LDD_CL} ${CMAKE_BINARY_DIR}/testappprojinfo | grep proj") + set_tests_properties(test_ldd PROPERTIES + PASS_REGULAR_EXPRESSION ${EXPECTED_LDD_CL_OUT} + ) +else() + add_test(NAME test_ldd COMMAND testappprojinfo) + set_tests_properties(test_ldd PROPERTIES SKIP_RETURN_CODE 1) +endif() + +# data directory property not available, so recreate one +get_filename_component(EXPECTED_DATADIR + "${${USE_PROJ_NAME}_DIR}/../../../share/proj" ABSOLUTE) +if(WIN32) + # Match each '/' with either '\' or '/' + string(REPLACE "/" "[\\/]" EXPECTED_DATADIR ${EXPECTED_DATADIR}) +endif() +add_test(NAME test_searchpath COMMAND testappprojinfo -s) +set_tests_properties(test_searchpath PROPERTIES + PASS_REGULAR_EXPRESSION "${EXPECTED_DATADIR}" +) + +add_test(NAME test_version COMMAND testappprojinfo -v) +set_tests_properties(test_version PROPERTIES + PASS_REGULAR_EXPRESSION "${${USE_PROJ_NAME}_VERSION}" +) diff --git a/test/postinstall/testappprojinfo/Makefile b/test/postinstall/testappprojinfo/Makefile new file mode 100644 index 00000000..98c47f28 --- /dev/null +++ b/test/postinstall/testappprojinfo/Makefile @@ -0,0 +1,15 @@ +PROGRAM = testappprojinfo +OBJECTS = $(addsuffix .o,$(PROGRAM)) + +override CFLAGS += -g -Wall -Werror $(shell pkg-config proj --cflags) +override LDFLAGS += $(shell pkg-config proj --libs) + +all: $(PROGRAM) + +$(PROGRAM): $(OBJECTS) + $(CC) -o $@ $< $(LDFLAGS) + +clean: + $(RM) $(PROGRAM) $(OBJECTS) + +.PHONY: clean diff --git a/test/postinstall/testappprojinfo/testappprojinfo.c b/test/postinstall/testappprojinfo/testappprojinfo.c new file mode 100644 index 00000000..64b5d665 --- /dev/null +++ b/test/postinstall/testappprojinfo/testappprojinfo.c @@ -0,0 +1,19 @@ +#include <stdio.h> +#include <proj.h> + +int main(int argc, char *argv[]) { + PJ_INFO info; + info = proj_info(); + if(argc == 2 && argv[1][0] == '-') { + switch(argv[1][1]) { + case 's': + printf("%s\n", info.searchpath); + return(0); + case 'v': + printf("%d.%d.%d\n", info.major, info.minor, info.patch); + return(0); + } + } + printf("Use option -v or -s\n"); + return(1); +} |
