aboutsummaryrefslogtreecommitdiff
path: root/test/postinstall/cpp_app
diff options
context:
space:
mode:
Diffstat (limited to 'test/postinstall/cpp_app')
-rw-r--r--test/postinstall/cpp_app/CMakeLists.txt34
-rw-r--r--test/postinstall/cpp_app/Makefile.am9
-rw-r--r--test/postinstall/cpp_app/configure.ac20
-rw-r--r--test/postinstall/cpp_app/cpp_app.cpp45
-rw-r--r--test/postinstall/cpp_app/makefile.mak34
-rwxr-xr-xtest/postinstall/cpp_app/test_ldd.sh4
-rwxr-xr-xtest/postinstall/cpp_app/test_searchpath.sh7
-rwxr-xr-xtest/postinstall/cpp_app/test_transform.sh6
-rwxr-xr-xtest/postinstall/cpp_app/test_version.sh7
9 files changed, 166 insertions, 0 deletions
diff --git a/test/postinstall/cpp_app/CMakeLists.txt b/test/postinstall/cpp_app/CMakeLists.txt
new file mode 100644
index 00000000..1f011082
--- /dev/null
+++ b/test/postinstall/cpp_app/CMakeLists.txt
@@ -0,0 +1,34 @@
+cmake_minimum_required(VERSION 3.5)
+project(CPP_APP LANGUAGES CXX)
+
+# Required for (e.g.) g++-4.8
+# can be refactored for CMake 3.22
+# https://github.com/OSGeo/PROJ/issues/1924
+set(CMAKE_CXX_STANDARD 11)
+set(CMAKE_CXX_STANDARD_REQUIRED ON)
+set(CMAKE_CXX_EXTENSIONS OFF)
+
+set(USE_PROJ_NAME "PROJ"
+ CACHE STRING "Either PROJ (default) or PROJ4")
+
+find_package(${USE_PROJ_NAME} REQUIRED CONFIG)
+
+include(CMakePrintHelpers)
+cmake_print_properties(
+ TARGETS ${USE_PROJ_NAME}::proj
+ PROPERTIES
+ LOCATION
+ INTERFACE_INCLUDE_DIRECTORIES
+ INTERFACE_LINK_LIBRARIES
+ INTERFACE_COMPILE_FEATURES
+)
+
+add_executable(cpp_app cpp_app.cpp)
+target_link_libraries(cpp_app PRIVATE ${USE_PROJ_NAME}::proj)
+
+set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/..)
+include(common)
+add_test_ldd(cpp_app)
+add_test_transform(cpp_app)
+add_test_searchpath(cpp_app)
+add_test_version(cpp_app)
diff --git a/test/postinstall/cpp_app/Makefile.am b/test/postinstall/cpp_app/Makefile.am
new file mode 100644
index 00000000..5451403a
--- /dev/null
+++ b/test/postinstall/cpp_app/Makefile.am
@@ -0,0 +1,9 @@
+bin_PROGRAMS = cpp_app
+cpp_app_SOURCES = cpp_app.cpp
+cpp_app_CXXFLAGS = $(PROJ_CFLAGS)
+cpp_app_LDADD = $(PROJ_LIBS)
+TESTS = \
+ test_ldd.sh \
+ test_transform.sh \
+ test_searchpath.sh \
+ test_version.sh
diff --git a/test/postinstall/cpp_app/configure.ac b/test/postinstall/cpp_app/configure.ac
new file mode 100644
index 00000000..7da902a8
--- /dev/null
+++ b/test/postinstall/cpp_app/configure.ac
@@ -0,0 +1,20 @@
+AC_INIT([cpp_app], [0.1])
+AM_INIT_AUTOMAKE
+AC_PROG_CXX
+dnl Required for (e.g.) g++-4.8
+AC_CONFIG_MACRO_DIR([../../../m4])
+AX_CXX_COMPILE_STDCXX_11([noext],[mandatory])
+
+PKG_CHECK_MODULES([PROJ], [proj])
+
+AC_ARG_ENABLE([static-proj],
+ AS_HELP_STRING([--enable-static-proj],
+ [Enable linking to static PROJ library]))
+
+# If enabled, force static linking for Linux
+if test "x$enable_static_proj" = "xyes" -a "x$(uname)" = "xLinux"; then
+ PROJ_LIBS=$(echo "$PROJ_LIBS" | sed 's/-lproj/-Wl,-Bstatic -lproj -Wl,-Bdynamic/')
+fi
+
+AC_CONFIG_FILES([Makefile])
+AC_OUTPUT
diff --git a/test/postinstall/cpp_app/cpp_app.cpp b/test/postinstall/cpp_app/cpp_app.cpp
new file mode 100644
index 00000000..9bcab2fb
--- /dev/null
+++ b/test/postinstall/cpp_app/cpp_app.cpp
@@ -0,0 +1,45 @@
+#include <iostream>
+#include <proj.h>
+
+int test_transform() {
+ PJ *P;
+ PJ_COORD a, b;
+ P = proj_create_crs_to_crs(
+ PJ_DEFAULT_CTX,
+ "EPSG:4326",
+ "+proj=utm +zone=32 +datum=WGS84", // or EPSG:32632
+ NULL);
+ if (0 == P) {
+ std::cerr << "Oops" << std::endl;
+ return 1;
+ }
+ // Copenhagen: 55d N, 12d E
+ a = proj_coord(55, 12, 0, 0);
+ b = proj_trans(P, PJ_FWD, a);
+ std::cout.precision(2);
+ std::cout.setf( std::ios::fixed, std::ios::floatfield );
+ std::cout << "easting: " << b.enu.e << ", northing: " << b.enu.n;
+ b = proj_trans(P, PJ_INV, b);
+ std::cout << ", latitude: " << b.lp.lam << ", longitude: " << b.lp.phi << std::endl;
+ proj_destroy(P);
+ return 0;
+}
+
+int main(int argc, char *argv[]) {
+ PJ_INFO info;
+ info = proj_info();
+ if(argc == 2 && argv[1][0] == '-') {
+ switch(argv[1][1]) {
+ case 't':
+ return(test_transform());
+ case 's':
+ std::cout << info.searchpath << std::endl;
+ return(0);
+ case 'v':
+ std::cout << info.major << '.' << info.minor << '.' << info.patch << std::endl;
+ return(0);
+ }
+ }
+ std::cerr << "Use option -t, -s or -v" << std::endl;
+ return(1);
+}
diff --git a/test/postinstall/cpp_app/makefile.mak b/test/postinstall/cpp_app/makefile.mak
new file mode 100644
index 00000000..8d84785f
--- /dev/null
+++ b/test/postinstall/cpp_app/makefile.mak
@@ -0,0 +1,34 @@
+PROGRAM = cpp_app
+OBJECTS = $(addsuffix .o,$(PROGRAM))
+TESTS = \
+ test_ldd.sh \
+ test_transform.sh \
+ test_searchpath.sh \
+ test_version.sh
+
+override CXXFLAGS += -std=c++11 -fvisibility=hidden -g -Wall -Werror $(shell pkg-config proj --cflags)
+
+ifeq ($(BUILD_MODE),static)
+ UNAME_S := $(shell uname -s)
+ _ldflags := $(shell pkg-config proj --libs --static)
+ ifeq ($(UNAME_S),Linux)
+ # force static linking to libproj
+ _ldflags := $(shell echo $(_ldflags) | sed 's/-lproj/-Wl,-Bstatic -lproj -Wl,-Bdynamic/')
+ endif
+ override LDFLAGS += $(_ldflags)
+else # default is shared
+ override LDFLAGS += $(shell pkg-config proj --libs)
+endif
+
+all: $(PROGRAM)
+
+$(PROGRAM): $(OBJECTS)
+ $(CXX) -o $@ $< $(LDFLAGS)
+
+test: $(PROGRAM)
+ set -e; for t in $(TESTS); do ./$$t; done
+
+clean:
+ $(RM) $(PROGRAM) $(OBJECTS)
+
+.PHONY: test clean
diff --git a/test/postinstall/cpp_app/test_ldd.sh b/test/postinstall/cpp_app/test_ldd.sh
new file mode 100755
index 00000000..2e8cd5ea
--- /dev/null
+++ b/test/postinstall/cpp_app/test_ldd.sh
@@ -0,0 +1,4 @@
+#!/bin/sh
+. ../common.sh
+
+test_ldd cpp_app libproj
diff --git a/test/postinstall/cpp_app/test_searchpath.sh b/test/postinstall/cpp_app/test_searchpath.sh
new file mode 100755
index 00000000..71ac1756
--- /dev/null
+++ b/test/postinstall/cpp_app/test_searchpath.sh
@@ -0,0 +1,7 @@
+#!/bin/sh
+. ../common.sh
+
+PROGRAM_SEARCHPATH="$(./cpp_app -s)"
+EXPECTED_SEARCHPATH="$(pkg-config proj --variable=datadir)"
+
+test_searchpath "${PROGRAM_SEARCHPATH}" "${EXPECTED_SEARCHPATH}"
diff --git a/test/postinstall/cpp_app/test_transform.sh b/test/postinstall/cpp_app/test_transform.sh
new file mode 100755
index 00000000..3f4e69ec
--- /dev/null
+++ b/test/postinstall/cpp_app/test_transform.sh
@@ -0,0 +1,6 @@
+#!/bin/sh
+. ../common.sh
+
+PROGRAM_TRANSFORM="$(./cpp_app -t)"
+
+test_transform "${PROGRAM_TRANSFORM}"
diff --git a/test/postinstall/cpp_app/test_version.sh b/test/postinstall/cpp_app/test_version.sh
new file mode 100755
index 00000000..d095aad8
--- /dev/null
+++ b/test/postinstall/cpp_app/test_version.sh
@@ -0,0 +1,7 @@
+#!/bin/sh
+. ../common.sh
+
+PROGRAM_VERSION=$(./cpp_app -v)
+EXPECTED_VERSION=$(pkg-config proj --modversion)
+
+test_version ${PROGRAM_VERSION} ${EXPECTED_VERSION}