Skip to content

Commit

Permalink
Autotools|CMake: Link against libm for function "isnan"
Browse files Browse the repository at this point in the history
$ git --no-pager grep -lw isnan
lib/xmlparse.c
tests/runtests.c
xmlwf/xmlwf.c
  • Loading branch information
hartwork committed Sep 10, 2021
1 parent 634cc99 commit 6ae5333
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 3 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/autotools-cmake.yml
Expand Up @@ -74,6 +74,7 @@ jobs:
automake \
cmake \
docbook2x \
gnu-sed \
libtool \
lzip
Expand Down Expand Up @@ -128,6 +129,14 @@ jobs:
&& mv expat-noconfig{-patched,}.cmake )
fi
if [[ "${{ runner.os }}" == macOS ]]; then
# Autotools' LT_LIB_M has a hardcoded exclude for "*-*-darwin*" hosts,
# while macOS does have libm and is successfully found by CMake.
# We patch the CMake side in line here to get the differ below to empty.
export PATH="$(brew --prefix)/opt/gnu-sed/libexec/gnubin:${PATH}"
sed 's,-lm,,' -i build_cmake/ROOT/usr/local/lib*/pkgconfig/expat.pc
fi
diff \
--recursive \
--unified \
Expand Down
16 changes: 16 additions & 0 deletions expat/CMakeLists.txt
Expand Up @@ -380,6 +380,9 @@ else()
endif()

add_library(expat ${_SHARED} ${expat_SRCS})
if(_EXPAT_LIBM_FOUND)
target_link_libraries(expat m)
endif()
if(EXPAT_WITH_LIBBSD)
target_link_libraries(expat ${LIB_BSD})
endif()
Expand Down Expand Up @@ -446,6 +449,11 @@ if(EXPAT_BUILD_PKGCONFIG)
string(TOLOWER "${_build_type}" _build_type_lower)
string(TOUPPER "${_build_type}" _build_type_upper)
set_property(TARGET expat PROPERTY "pkgconfig_${_build_type_lower}_name" "expat${CMAKE_${_build_type_upper}_POSTFIX}")
if(_EXPAT_LIBM_FOUND)
set_property(TARGET expat PROPERTY "pkgconfig_libm" "-lm")
else()
set_property(TARGET expat PROPERTY "pkgconfig_libm" "")
endif()
endforeach()

file(GENERATE
Expand All @@ -470,6 +478,9 @@ if(EXPAT_BUILD_TOOLS)
add_executable(xmlwf ${xmlwf_SRCS})
set_property(TARGET xmlwf PROPERTY RUNTIME_OUTPUT_DIRECTORY xmlwf)
target_link_libraries(xmlwf expat)
if(_EXPAT_LIBM_FOUND)
target_link_libraries(xmlwf m)
endif()
expat_install(TARGETS xmlwf DESTINATION ${CMAKE_INSTALL_BINDIR})

if(MINGW AND _EXPAT_UNICODE_WCHAR_T)
Expand Down Expand Up @@ -543,6 +554,11 @@ if(EXPAT_BUILD_TESTS)
set_property(TARGET runtestspp PROPERTY RUNTIME_OUTPUT_DIRECTORY tests)
expat_add_test(runtestspp $<TARGET_FILE:runtestspp>)

if(_EXPAT_LIBM_FOUND)
target_link_libraries(runtests m)
target_link_libraries(runtestspp m)
endif()

if(EXPAT_WITH_LIBBSD)
target_link_libraries(runtests ${LIB_BSD})
target_link_libraries(runtestspp ${LIB_BSD})
Expand Down
1 change: 1 addition & 0 deletions expat/Changes
Expand Up @@ -4,6 +4,7 @@ NOTE: We are looking for help with a few things:

Release 2.4.2 xxx xxx xx xxxx
Other changes:
#509 #510 Link againgst libm for function "isnan"
#497 Autotools: Include files with release archives:
- buildconf.sh
- fuzz/*.c
Expand Down
3 changes: 3 additions & 0 deletions expat/ConfigureChecks.cmake
Expand Up @@ -2,6 +2,7 @@ include(CheckCCompilerFlag)
include(CheckCSourceCompiles)
include(CheckIncludeFile)
include(CheckIncludeFiles)
include(CheckLibraryExists)
include(CheckSymbolExists)
include(TestBigEndian)

Expand Down Expand Up @@ -64,3 +65,5 @@ check_c_source_compiles("

check_c_compiler_flag("-fno-strict-aliasing" FLAG_NO_STRICT_ALIASING)
check_c_compiler_flag("-fvisibility=hidden" FLAG_VISIBILITY)

check_library_exists(m cos "" _EXPAT_LIBM_FOUND)
5 changes: 5 additions & 0 deletions expat/cmake/autotools/expat.cmake
Expand Up @@ -55,8 +55,13 @@ add_library(expat::expat SHARED IMPORTED)

set_target_properties(expat::expat PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include"
INTERFACE_LINK_LIBRARIES "m"
)

if(CMAKE_VERSION VERSION_LESS 2.8.12)
message(FATAL_ERROR "This file relies on consumers using CMake 2.8.12 or greater.")
endif()

# Load information for each installed configuration.
get_filename_component(_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
file(GLOB CONFIG_FILES "${_DIR}/expat-*.cmake")
Expand Down
1 change: 1 addition & 0 deletions expat/configure.ac
Expand Up @@ -186,6 +186,7 @@ AM_CONDITIONAL([_INTERNAL_UNICODE_WCHAR_T], [echo -- "${CPPFLAGS}${CFLAGS}" | ${
AM_CONDITIONAL([_INTERNAL_MIN_SIZE], [echo -- "${CPPFLAGS}${CFLAGS}" | ${FGREP} XML_MIN_SIZE >/dev/null])
AM_CONDITIONAL([_INTERNAL_LARGE_SIZE], [echo -- "${CPPFLAGS}${CFLAGS}" | ${FGREP} XML_LARGE_SIZE >/dev/null])

LT_LIB_M

AC_ARG_WITH([libbsd],
[AS_HELP_STRING([--with-libbsd], [utilize libbsd (for arc4random_buf)])],
Expand Down
2 changes: 1 addition & 1 deletion expat/expat.pc.cmake
Expand Up @@ -7,5 +7,5 @@ Name: $<TARGET_PROPERTY:pkgconfig_$<LOWER_CASE:$<CONFIG>>_name>
Version: $<TARGET_PROPERTY:pkgconfig_version>
Description: expat XML parser
URL: https://libexpat.github.io/
Libs: -L${libdir} -l$<TARGET_PROPERTY:pkgconfig_$<LOWER_CASE:$<CONFIG>>_name>
Libs: -L${libdir} -l$<TARGET_PROPERTY:pkgconfig_$<LOWER_CASE:$<CONFIG>>_name> $<TARGET_PROPERTY:pkgconfig_libm>
Cflags: -I${includedir}
2 changes: 1 addition & 1 deletion expat/expat.pc.in
Expand Up @@ -7,5 +7,5 @@ Name: @PACKAGE_NAME@
Version: @PACKAGE_VERSION@
Description: expat XML parser
URL: https://libexpat.github.io/
Libs: -L${libdir} -l@PACKAGE_NAME@
Libs: -L${libdir} -l@PACKAGE_NAME@ @LIBM@
Cflags: -I${includedir}
1 change: 1 addition & 0 deletions expat/lib/Makefile.am
Expand Up @@ -40,6 +40,7 @@ noinst_LTLIBRARIES = libexpatinternal.la

libexpat_la_LDFLAGS = \
@AM_LDFLAGS@ \
@LIBM@ \
-no-undefined \
-version-info @LIBCURRENT@:@LIBREVISION@:@LIBAGE@

Expand Down
3 changes: 3 additions & 0 deletions expat/tests/Makefile.am
Expand Up @@ -57,6 +57,9 @@ runtestspp_SOURCES = \
runtests_LDADD = libruntests.a ../lib/libexpatinternal.la
runtestspp_LDADD = libruntests.a ../lib/libexpatinternal.la

runtests_LDFLAGS = @AM_LDFLAGS@ @LIBM@
runtestspp_LDFLAGS = @AM_LDFLAGS@ @LIBM@

EXTRA_DIST = \
chardata.h \
structdata.h \
Expand Down
2 changes: 1 addition & 1 deletion expat/xmlwf/Makefile.am
Expand Up @@ -38,7 +38,7 @@ xmlwf_SOURCES = \
@FILEMAP@.c

xmlwf_CPPFLAGS = @AM_CPPFLAGS@ -I$(srcdir)/../lib
xmlwf_LDFLAGS = @AM_LDFLAGS@
xmlwf_LDFLAGS = @AM_LDFLAGS@ @LIBM@

if MINGW
if UNICODE
Expand Down

0 comments on commit 6ae5333

Please sign in to comment.