aboutsummaryrefslogtreecommitdiff
path: root/test/postinstall/c_app
diff options
context:
space:
mode:
authorMike Taves <mwtoews@gmail.com>2021-12-09 00:45:03 +1300
committerGitHub <noreply@github.com>2021-12-09 00:45:03 +1300
commit7a9b6566ac02d8c408f4f3758bfa5fcc3e90b552 (patch)
treed71d0771cc9f95d5a8ea96bd975bbd4164188813 /test/postinstall/c_app
parent1b18defb63c7d2420d18e4375348663874247838 (diff)
downloadPROJ-7a9b6566ac02d8c408f4f3758bfa5fcc3e90b552.tar.gz
PROJ-7a9b6566ac02d8c408f4f3758bfa5fcc3e90b552.zip
Refactor post-install suite to test shared and static projlib (#2972)
Diffstat (limited to 'test/postinstall/c_app')
-rw-r--r--test/postinstall/c_app/CMakeLists.txt34
-rw-r--r--test/postinstall/c_app/Makefile.am9
-rw-r--r--test/postinstall/c_app/c_app.c43
-rw-r--r--test/postinstall/c_app/configure.ac18
-rw-r--r--test/postinstall/c_app/makefile.mak34
-rwxr-xr-xtest/postinstall/c_app/test_ldd.sh4
-rwxr-xr-xtest/postinstall/c_app/test_searchpath.sh7
-rwxr-xr-xtest/postinstall/c_app/test_transform.sh6
-rwxr-xr-xtest/postinstall/c_app/test_version.sh7
9 files changed, 162 insertions, 0 deletions
diff --git a/test/postinstall/c_app/CMakeLists.txt b/test/postinstall/c_app/CMakeLists.txt
new file mode 100644
index 00000000..a493849b
--- /dev/null
+++ b/test/postinstall/c_app/CMakeLists.txt
@@ -0,0 +1,34 @@
+cmake_minimum_required(VERSION 3.5)
+project(C_APP LANGUAGES C)
+
+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(c_app c_app.c)
+target_link_libraries(c_app PRIVATE ${USE_PROJ_NAME}::proj)
+
+get_target_property(PROJLIB_LOCATION ${USE_PROJ_NAME}::proj LOCATION)
+if(PROJLIB_LOCATION MATCHES ".*\.(lib|a)$")
+ # Used for static linking (is there a better way?)
+ enable_language(CXX)
+ set_target_properties(c_app PROPERTIES LINKER_LANGUAGE CXX)
+endif()
+
+set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/..)
+include(common)
+add_test_ldd(c_app proj)
+add_test_transform(c_app)
+add_test_searchpath(c_app)
+add_test_version(c_app)
diff --git a/test/postinstall/c_app/Makefile.am b/test/postinstall/c_app/Makefile.am
new file mode 100644
index 00000000..356034ba
--- /dev/null
+++ b/test/postinstall/c_app/Makefile.am
@@ -0,0 +1,9 @@
+bin_PROGRAMS = c_app
+c_app_SOURCES = c_app.c
+c_app_CFLAGS = $(PROJ_CFLAGS)
+c_app_LDADD = $(PROJ_LIBS)
+TESTS = \
+ test_ldd.sh \
+ test_transform.sh \
+ test_searchpath.sh \
+ test_version.sh
diff --git a/test/postinstall/c_app/c_app.c b/test/postinstall/c_app/c_app.c
new file mode 100644
index 00000000..58d7e135
--- /dev/null
+++ b/test/postinstall/c_app/c_app.c
@@ -0,0 +1,43 @@
+#include <stdio.h>
+#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) {
+ fprintf(stderr, "Oops\n");
+ return 1;
+ }
+ /* Copenhagen: 55d N, 12d E */
+ a = proj_coord(55, 12, 0, 0);
+ b = proj_trans(P, PJ_FWD, a);
+ printf("easting: %.2f, northing: %.2f, ", b.enu.e, b.enu.n);
+ b = proj_trans(P, PJ_INV, b);
+ printf("latitude: %.2f, longitude: %.2f\n", b.lp.lam, b.lp.phi);
+ 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':
+ printf("%s\n", info.searchpath);
+ return(0);
+ case 'v':
+ printf("%d.%d.%d\n", info.major, info.minor, info.patch);
+ return(0);
+ }
+ }
+ fprintf(stderr, "Use option -t, -s or -v\n");
+ return(1);
+}
diff --git a/test/postinstall/c_app/configure.ac b/test/postinstall/c_app/configure.ac
new file mode 100644
index 00000000..43ae4835
--- /dev/null
+++ b/test/postinstall/c_app/configure.ac
@@ -0,0 +1,18 @@
+AC_INIT([c_app], [0.1])
+AM_INIT_AUTOMAKE
+AC_PROG_CC
+AC_CONFIG_MACRO_DIR([../../../m4])
+
+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/c_app/makefile.mak b/test/postinstall/c_app/makefile.mak
new file mode 100644
index 00000000..d6c1c8de
--- /dev/null
+++ b/test/postinstall/c_app/makefile.mak
@@ -0,0 +1,34 @@
+PROGRAM = c_app
+OBJECTS = $(addsuffix .o,$(PROGRAM))
+TESTS = \
+ test_ldd.sh \
+ test_transform.sh \
+ test_searchpath.sh \
+ test_version.sh
+
+override CFLAGS += -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)
+ $(CC) -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/c_app/test_ldd.sh b/test/postinstall/c_app/test_ldd.sh
new file mode 100755
index 00000000..9750db16
--- /dev/null
+++ b/test/postinstall/c_app/test_ldd.sh
@@ -0,0 +1,4 @@
+#!/bin/sh
+. ../common.sh
+
+test_ldd c_app libproj
diff --git a/test/postinstall/c_app/test_searchpath.sh b/test/postinstall/c_app/test_searchpath.sh
new file mode 100755
index 00000000..0bd4feab
--- /dev/null
+++ b/test/postinstall/c_app/test_searchpath.sh
@@ -0,0 +1,7 @@
+#!/bin/sh
+. ../common.sh
+
+PROGRAM_SEARCHPATH="$(./c_app -s)"
+EXPECTED_SEARCHPATH="$(pkg-config proj --variable=datadir)"
+
+test_searchpath "${PROGRAM_SEARCHPATH}" "${EXPECTED_SEARCHPATH}"
diff --git a/test/postinstall/c_app/test_transform.sh b/test/postinstall/c_app/test_transform.sh
new file mode 100755
index 00000000..cfcaa9c3
--- /dev/null
+++ b/test/postinstall/c_app/test_transform.sh
@@ -0,0 +1,6 @@
+#!/bin/sh
+. ../common.sh
+
+PROGRAM_TRANSFORM="$(./c_app -t)"
+
+test_transform "${PROGRAM_TRANSFORM}"
diff --git a/test/postinstall/c_app/test_version.sh b/test/postinstall/c_app/test_version.sh
new file mode 100755
index 00000000..a1faacf5
--- /dev/null
+++ b/test/postinstall/c_app/test_version.sh
@@ -0,0 +1,7 @@
+#!/bin/sh
+. ../common.sh
+
+PROGRAM_VERSION=$(./c_app -v)
+EXPECTED_VERSION=$(pkg-config proj --modversion)
+
+test_version ${PROGRAM_VERSION} ${EXPECTED_VERSION}