gnucash master: Link with libm.so on those platforms that require it.
John Ralls
jralls at code.gnucash.org
Mon Jul 6 15:30:51 EDT 2020
Updated via https://github.com/Gnucash/gnucash/commit/4ee573e2 (commit)
from https://github.com/Gnucash/gnucash/commit/43749a94 (commit)
commit 4ee573e23a15691247b509c981258a12bdd49194
Author: John Ralls <jralls at ceridwen.us>
Date: Mon Jul 6 12:24:49 2020 -0700
Link with libm.so on those platforms that require it.
diff --git a/common/cmake_modules/CMakeLists.txt b/common/cmake_modules/CMakeLists.txt
index 115c90fd5..e25f806b2 100644
--- a/common/cmake_modules/CMakeLists.txt
+++ b/common/cmake_modules/CMakeLists.txt
@@ -1,7 +1,7 @@
set(cmake_FILES
GncAddGSchemaTargets.cmake GncAddSchemeTargets.cmake
- GncAddSwigCommand.cmake GncAddTest.cmake
+ GncAddSwigCommand.cmake GncAddTest.cmake GncFindLibm.cmake
MacroAddSourceFileCompileFlags.cmake MacroAppendForeach.cmake
MakeDist.cmake MakeDistFiles.cmake MakeDistCheck.cmake
)
diff --git a/common/cmake_modules/GncFindLibm.cmake b/common/cmake_modules/GncFindLibm.cmake
new file mode 100644
index 000000000..ab29df95c
--- /dev/null
+++ b/common/cmake_modules/GncFindLibm.cmake
@@ -0,0 +1,46 @@
+# Copied & modified from https://android.googlesource.com/platform/external/eigen/+/master/cmake/FindStandardMathLibrary.cmake
+# Copyright (c) 2010 Benoit Jacob <jacob.benoit.1 at gmail.com>
+# Redistribution and use is allowed according to the terms of the 2-clause BSD license.
+# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
+
+#Detect whether this platform requires libm for pow().
+
+include(CheckCXXSourceCompiles)
+macro (gnc_check_standard_math_library)
+ set(find_standard_math_library_test_program
+"
+#include <math.h>
+int main(int argc, char** argv)
+{
+ double foo = pow(2.0, 2.0);
+ return foo == 4.0;
+}"
+ )
+
+ set(CMAKE_REQUIRED_FLAGS "")
+ set(CMAKE_REQUIRED_LIBRARIES "")
+ check_c_source_compiles(
+ "${find_standard_math_library_test_program}"
+ standard_math_library_linked_to_automatically
+ )
+ if(standard_math_library_linked_to_automatically)
+ # the test program linked successfully without any linker flag.
+ set(STANDARD_MATH_LIBRARY "")
+ set(STANDARD_MATH_LIBRARY_FOUND TRUE)
+ else()
+ # the test program did not link successfully without any linker flag.
+ # Try again with standard name 'm' for the standard math library.
+ set(CMAKE_REQUIRED_LIBRARIES "m")
+ check_c_source_compiles(
+ "${find_standard_math_library_test_program}"
+ standard_math_library_linked_to_as_m)
+ if(standard_math_library_linked_to_as_m)
+ # the test program linked successfully when linking to the 'm' library
+ set(STANDARD_MATH_LIBRARY "m")
+ set(STANDARD_MATH_LIBRARY_FOUND TRUE)
+ else()
+ # the test program still doesn't link successfully
+ set(STANDARD_MATH_LIBRARY_FOUND FALSE)
+ endif()
+ endif()
+endmacro()
diff --git a/libgnucash/app-utils/CMakeLists.txt b/libgnucash/app-utils/CMakeLists.txt
index 4cfa65a35..2cc9c82f1 100644
--- a/libgnucash/app-utils/CMakeLists.txt
+++ b/libgnucash/app-utils/CMakeLists.txt
@@ -1,6 +1,9 @@
# NB: Unit tests which require GSchemas should be made conditional on COMPILE_GSCHEMAS.
add_subdirectory(test)
add_subdirectory(mocks)
+
+include (GncFindLibm)
+
# Build the library
set (app_utils_noinst_HEADERS
@@ -67,10 +70,15 @@ set (app_utils_SOURCES
gnc-ui-util.c
gnc-ui-balances.c
option-util.c
-)
+ )
set_source_files_properties (${app_utils_SOURCES} PROPERTIES OBJECT_DEPENDS ${CONFIG_H})
+gnc_check_standard_math_library()
+if (NOT STANDARD_MATH_LIBRARY_FOUND)
+ message(FATAL_ERROR "An implementation of the standard C function pow() is required and is supported neither by the C runtime nor libm.so.")
+endif()
+
set(app_utils_ALL_SOURCES ${app_utils_SOURCES} ${app_utils_HEADERS} ${app_utils_noinst_HEADERS})
set(app_utils_ALL_LIBRARIES
gnc-engine
@@ -78,7 +86,10 @@ set(app_utils_ALL_LIBRARIES
gnucash-guile
${GIO_LDFLAGS}
${LIBXML2_LDFLAGS}
- ${LIBXSLT_LDFLAGS})
+ ${LIBXSLT_LDFLAGS}
+ ${STANDARD_MATH_LIBRARY}
+)
+
set(app_utils_ALL_INCLUDES
${CMAKE_CURRENT_SOURCE_DIR}/calculation
${GIO_INCLUDE_DIRS}
Summary of changes:
common/cmake_modules/CMakeLists.txt | 2 +-
common/cmake_modules/GncFindLibm.cmake | 46 ++++++++++++++++++++++++++++++++++
libgnucash/app-utils/CMakeLists.txt | 15 +++++++++--
3 files changed, 60 insertions(+), 3 deletions(-)
create mode 100644 common/cmake_modules/GncFindLibm.cmake
More information about the gnucash-changes
mailing list