Skip to content

Commit 8ac0209

Browse files
committed
bugfix: FindGLIB2 didn't clean up properly. added new pkg-config utility functions which can be reused
1 parent db19afc commit 8ac0209

File tree

3 files changed

+53
-16
lines changed

3 files changed

+53
-16
lines changed

tests/CMakeLists.txt

+20-6
Original file line numberDiff line numberDiff line change
@@ -455,15 +455,29 @@ inclusion(GLIB2_DIR GLIB2_INCLUDE_DIRS)
455455

456456
# find libraries using pkg-config
457457
find_package(PkgConfig REQUIRED)
458+
include(PkgConfigTools.cmake)
459+
save_pkg_config_env()
458460

459-
pkg_search_module(FONTCONFIG REQUIRED fontconfig>=2.11.0)
460-
message(STATUS "fontconfig found: ${FONTCONFIG_VERSION}")
461+
if (DEFINED ENV{OPENSCAD_LIBRARIES})
462+
set(ENV{PKG_CONFIG_PATH} "$ENV{OPENSCAD_LIBRARIES}/lib/pkgconfig")
463+
endif()
464+
465+
pkg_check_modules(FONTCONFIG REQUIRED fontconfig>=2.11.0)
466+
if (FONTCONFIG_VERSION)
467+
message(STATUS "fontconfig ${FONTCONFIG_VERSION} found: ${FONTCONFIG_INCLUDE_DIRS}")
468+
endif()
461469

462-
pkg_search_module(FREETYPE REQUIRED freetype2>=2.4.9)
463-
message(STATUS "freetype2 found: ${FREETYPE_VERSION}")
470+
pkg_check_modules(FREETYPE REQUIRED freetype2>=2.4.9)
471+
if (FREETYPE_VERSION)
472+
message(STATUS "freetype2 ${FREETYPE_VERSION} found: ${FREETYPE_INCLUDE_DIRS}")
473+
endif()
474+
475+
pkg_check_modules(HARFBUZZ REQUIRED harfbuzz>=0.9.19)
476+
if (HARFBUZZ_VERSION)
477+
message(STATUS "harfbuzz ${HARFBUZZ_VERSION} found: ${HARFBUZZ_INCLUDE_DIRS}")
478+
endif()
464479

465-
pkg_search_module(HARFBUZZ REQUIRED harfbuzz>=0.9.19)
466-
message(STATUS "harfbuzz found: ${HARFBUZZ_VERSION}")
480+
restore_pkg_config_env()
467481

468482
add_definitions(${FONTCONFIG_CFLAGS})
469483
add_definitions(${FREETYPE_CFLAGS})

tests/FindGLIB2.cmake

+4-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
message(STATUS "running openscad/tests/FindGLIB2.cmake ...")
22

3+
include(PkgConfigTools.cmake)
4+
save_pkg_config_env()
5+
36
# GLIB2 requires pkg-config to build.
47
# If we are did an OPENSCAD_LIBRARIES dependency build of glib2, we need to
58
# tell pkg-config to look under OPENSCAD_LIBRARIES dir.
@@ -8,8 +11,6 @@ if (NOT $ENV{OPENSCAD_LIBRARIES} STREQUAL "")
811
if (EXISTS "$ENV{OPENSCAD_LIBRARIES}/include/glib-2.0/glib.h")
912
message(STATUS "found glib.h under OPENSCAD_LIBRARIES.")
1013
message(STATUS "redirecting pkg-config to look under OPENSCAD_LIBRARIES")
11-
set(SAVED_PKG_CONFIG_PATH "$ENV{PKG_CONFIG_PATH}")
12-
set(SAVED_PKG_CONFIG_LIBDIR "$ENV{PKG_CONFIG_LIBDIR}")
1314
set(ENV{PKG_CONFIG_PATH} "$ENV{OPENSCAD_LIBRARIES}/lib/pkgconfig")
1415
set(ENV{PKG_CONFIG_LIBDIR} "$ENV{OPENSCAD_LIBRARIES}/lib/pkgconfig")
1516
else()
@@ -55,11 +56,4 @@ foreach(glib2libdir ${GLIB2_LIBRARIES})
5556
message(STATUS " " ${glib2libdir})
5657
endforeach()
5758

58-
if (NOT $ENV{OPENSCAD_LIBRARIES} STREQUAL "")
59-
if (EXISTS "$ENV{OPENSCAD_LIBRARIES}/include/glib-2.0/glib.h")
60-
message(STATUS "resetting pkgconfig as it was")
61-
else()
62-
set(ENV{PKG_CONFIG_PATH} "${SAVED_PKG_CONFIG_PATH}")
63-
set(ENV{PKG_CONFIG_LIBDIR} "${SAVED_PKG_CONFIG_LIBDIR}")
64-
endif()
65-
endif()
59+
restore_pkg_config_env()

tests/PkgConfigTools.cmake

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Use this to save the existing pkg-config settings
2+
function(save_pkg_config_env)
3+
message(STATUS "saving pkg-config env")
4+
5+
if (DEFINED ENV{PKG_CONFIG_PATH})
6+
set(SAVED_PKG_CONFIG_PATH "$ENV{PKG_CONFIG_PATH}")
7+
endif()
8+
if (DEFINED ENV{PKG_CONFIG_LIBDIR})
9+
set(SAVED_PKG_CONFIG_LIBDIR "$ENV{PKG_CONFIG_LIBDIR}")
10+
endif()
11+
endfunction()
12+
13+
# Use this to restore to the original pkg-config settings
14+
function(restore_pkg_config_env)
15+
message(STATUS "restoring pkg-config env")
16+
17+
if (SAVED_PKG_CONFIG_PATH)
18+
set(ENV{PKG_CONFIG_PATH} "${SAVED_PKG_CONFIG_PATH}")
19+
unset(SAVED_PKG_CONFIG_PATH)
20+
else()
21+
unset(ENV{PKG_CONFIG_PATH})
22+
endif()
23+
if (SAVED_PKG_CONFIG_LIBDIR)
24+
set(ENV{PKG_CONFIG_LIBDIR} "${SAVED_PKG_CONFIG_LIBDIR}")
25+
unset(SAVED_PKG_CONFIG_LIBDIR)
26+
else()
27+
unset(ENV{PKG_CONFIG_LIBDIR})
28+
endif()
29+
endfunction()

0 commit comments

Comments
 (0)