Skip to content

Commit 030e5c0

Browse files
authored
Fix broken PyImath.pc, and add pkg-config CI tests (AcademySoftwareFoundation#510)
PyImath.pc failed to get updated with recent changes to PyImath CMakeLists.txt. This also adds CI tests for Imath.pc and PyImath.pc, steps to build simple programs in `share/ci/src` using values extracted via pkg-config. Signed-off-by: Cary Phillips <cary@ilm.com>
1 parent 1985a11 commit 030e5c0

File tree

7 files changed

+103
-42
lines changed

7 files changed

+103
-42
lines changed

.github/workflows/ci_steps.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,4 +650,18 @@ jobs:
650650
$EXAMPLES_BUILD_DIR/bin/imath-examples.exe
651651
shell: msys2 {0}
652652

653+
- name: Test Imath.pc
654+
# Validate that Imath.pc works by compiling/linking the test program
655+
if: runner.os != 'Windows' && inputs.IMATH_INSTALL_PKG_CONFIG == 'ON' && inputs.IMATH_BUILD_APPLE_FRAMEWORKS != 'ON'
656+
run: |
657+
set -x
658+
share/ci/scripts/validate_pkgconfig.sh $INSTALL_DIR Imath share/ci/src/Imath.pc/Imath.pc.cpp
659+
653660
661+
- name: Test PyImath.pc
662+
# Validate that PyImath.pc works by compiling/linking the test program
663+
if: runner.os != 'Windows' && inputs.IMATH_INSTALL_PKG_CONFIG == 'ON' && inputs.PYTHON == 'ON' && inputs.IMATH_TEST_PYTHON == 'ON' && inputs.IMATH_BUILD_APPLE_FRAMEWORKS != 'ON'
664+
run: |
665+
set -x
666+
share/ci/scripts/validate_pkgconfig.sh $INSTALL_DIR PyImath share/ci/src/PyImath.pc/PyImath.pc.cpp
667+
shell: bash
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env bash
2+
3+
# SPDX-License-Identifier: BSD-3-Clause
4+
# Copyright Contributors to the OpenEXR Project.
5+
6+
#
7+
# Validate that the given source file compiles and links with the
8+
# given pkg-config file.
9+
#
10+
# First argument is the directory where Imath is installed
11+
# Second argument is the pkg name, i.e. Imath or PyImath
12+
# Third argument is the test program source
13+
#
14+
15+
set -x
16+
17+
if [ "$#" -ne 3 ]; then
18+
echo "Error: Expected 4 arguments, got $#." >&2
19+
echo "Usage: $0 <install dir> <pc file> <src file>" >&2
20+
exit 1
21+
fi
22+
23+
INSTALL=$1
24+
PKG=$2
25+
SRC=$3
26+
27+
export PKG_CONFIG_PATH=$INSTALL/lib/pkgconfig
28+
cflags=$(pkg-config --cflags $PKG)
29+
libs=$(pkg-config --libs $PKG)
30+
bin=$SRC.bin
31+
g++ -std=c++17 $cflags $SRC $libs -o $bin -Wl,-rpath,$INSTALL/lib
32+
./$bin
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44
//
55

66
//
7-
// A simple program for use in validating that Imath's configuration properly
8-
// exports the information require by downstream projects using Imath via
9-
// CMake's FetchContent
7+
// A simple program for use in validating that Imath.pc is configured
8+
// properly.
109
//
1110

1211
#include <ImathConfig.h>
@@ -20,7 +19,7 @@ main (int argc, char* argv[])
2019

2120
V2f v(0);
2221

23-
std::cout << "ImathFetchTest: v=" << v << std::endl;
22+
std::cout << argv[0] << ": ok" << std::endl;
2423

2524
return 0;
2625
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//
2+
// SPDX-License-Identifier: BSD-3-Clause
3+
// Copyright Contributors to the OpenEXR Project.
4+
//
5+
6+
//
7+
// A simple program for use in validating that PyImath.pc is
8+
// configured properly.
9+
//
10+
11+
#include <PyImathStringTable.h>
12+
#include <PyImath.h>
13+
14+
int
15+
main (int argc, char* argv[])
16+
{
17+
Py_Initialize();
18+
19+
PyImath::StringTable st;
20+
21+
std::cout << argv[0] << ": ok" << std::endl;
22+
23+
return 0;
24+
}

share/ci/src/fetch/CMakeLists.txt

Lines changed: 0 additions & 33 deletions
This file was deleted.

src/python/PyImath/CMakeLists.txt

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,10 +289,26 @@ if (IMATH_INSTALL)
289289
set(exec_prefix "\${prefix}")
290290
set(libdir "\${exec_prefix}/${CMAKE_INSTALL_LIBDIR}")
291291
set(includedir "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}")
292+
string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE)
293+
set(lib_suffix "${IMATH_LIB_SUFFIX}${CMAKE_${uppercase_CMAKE_BUILD_TYPE}_POSTFIX}")
294+
set(pylib_suffix "${PYIMATH_LIB_SUFFIX}${CMAKE_${uppercase_CMAKE_BUILD_TYPE}_POSTFIX}")
295+
296+
# boost lib/dir
297+
set(BOOST_PYTHON_LOCATION ${Boost_PYTHON_LIBRARY_RELEASE})
298+
get_filename_component(boost_libdir "${BOOST_PYTHON_LOCATION}" DIRECTORY)
299+
get_filename_component(boost_libname "${BOOST_PYTHON_LOCATION}" NAME_WE)
300+
string(REGEX REPLACE "^lib" "" boost_libname "${boost_libname}")
301+
302+
# python lib/dir
303+
get_filename_component(python_libdir "${Python3_LIBRARIES}" DIRECTORY)
304+
set(python_libname "python${Python3_VERSION_MAJOR}.${Python3_VERSION_MINOR}")
305+
292306
string(REPLACE ".in" "" pcout ${pcinfile})
293307
configure_file(${pcinfile} ${CMAKE_CURRENT_BINARY_DIR}/${pcout} @ONLY)
308+
294309
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${pcout} DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
295-
message(STATUS "generating ${pcout}")
310+
311+
message(STATUS "generating ${pcout}")
296312
else()
297313
message(STATUS "pkg-config generation disabled for PyImath")
298314
endif()

src/python/PyImath/PyImath.pc.in

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,19 @@ prefix=@prefix@
77
exec_prefix=@exec_prefix@
88
libdir=@libdir@
99
includedir=@includedir@
10-
libsuffix=@LIB_SUFFIX_DASH@
10+
libsuffix=@lib_suffix@
11+
pylibsuffix=@pylib_suffix@
12+
13+
boost_includedir=@Boost_INCLUDE_DIRS@
14+
boost_libdir=@boost_libdir@
15+
boost_libname=@boost_libname@
16+
17+
python_includedir=@Python3_INCLUDE_DIRS@
18+
python_libdir=@python_libdir@
19+
python_libname=@python_libname@
1120

1221
Name: PyImath
13-
Description: Python bindings for the Imath libraries
22+
Description: Python wrappings of Imath classes/functions
1423
Version: @IMATH_VERSION@
15-
Libs: -L${libdir} -lImath${libsuffix} -lPyImath@PYIMATH_LIB_PYTHONVER_ROOT@@Python3_VERSION_MAJOR@_@Python3_VERSION_MINOR@${libsuffix}
16-
Cflags: -I${includedir} -I${includedir}/Imath
24+
Libs: -L${libdir} -lImath${libsuffix} -lPyImath${pylibsuffix} -L${boost_libdir} -l${boost_libname} -L${python_libdir} -l${python_libname}
25+
Cflags: -I${includedir} -I${includedir}/@IMATH_OUTPUT_SUBDIR@ -I${includedir}/@PYIMATH_OUTPUT_SUBDIR@ -I${boost_includedir} -I${python_includedir}

0 commit comments

Comments
 (0)