From 5745deb8dbcee040d1012b8260ed317eb2a32f4b Mon Sep 17 00:00:00 2001 From: Martin Vala Date: Tue, 14 Apr 2015 22:50:31 +0200 Subject: [PATCH] Make compile_ex() work with CMake. Infrastructure fixes to make CMake find libdl and make ginac-excompiler listen to the $CXXFLAGS environment variable. --- CMakeLists.txt | 5 +++++ check/CMakeLists.txt | 2 +- cmake/modules/FindLibDL.cmake | 30 ++++++++++++++++++++++++++++++ config.cmake.in | 1 + doc/examples/compile1.cpp | 3 +++ doc/examples/compile2.cpp | 3 +++ doc/examples/compile3.cpp | 3 +++ doc/tutorial/ginac.texi | 8 +++++++- ginsh/CMakeLists.txt | 2 +- tools/CMakeLists.txt | 11 ++++++++++- tools/ginac-excompiler.in | 2 +- 11 files changed, 65 insertions(+), 5 deletions(-) create mode 100644 cmake/modules/FindLibDL.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 86d76fac..122d94ca 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -159,6 +159,11 @@ if (READLINE_FOUND) set(HAVE_READLINE_HISTORY_H 1) endif() +find_package(LibDL) +if (LIBDL_FOUND) + set(HAVE_LIBDL 1) +endif() + find_program(MAKEINFO makeinfo) find_program(FIG2DEV fig2dev) diff --git a/check/CMakeLists.txt b/check/CMakeLists.txt index 42fe50e1..5bf53a19 100644 --- a/check/CMakeLists.txt +++ b/check/CMakeLists.txt @@ -71,7 +71,7 @@ macro(add_ginac_test thename) set(${thename}_sources ${thename}.cpp ${${thename}_extra_src}) endif() add_executable(${thename} EXCLUDE_FROM_ALL ${${thename}_sources}) - target_link_libraries(${thename} ginac) + target_link_libraries(${thename} ginac ${LIBDL_LIBRARIES}) add_dependencies(check ${thename}) add_test(NAME ${thename} COMMAND ${thename}${CMAKE_EXECUTABLE_SUFFIX}) endmacro() diff --git a/cmake/modules/FindLibDL.cmake b/cmake/modules/FindLibDL.cmake new file mode 100644 index 00000000..403a5c86 --- /dev/null +++ b/cmake/modules/FindLibDL.cmake @@ -0,0 +1,30 @@ +# - Find libdl +# Find the native LIBDL includes and library +# +# LIBDL_INCLUDE_DIR - where to find dlfcn.h, etc. +# LIBDL_LIBRARIES - List of libraries when using libdl. +# LIBDL_FOUND - True if libdl found. + + +IF (LIBDL_INCLUDE_DIR) + # Already in cache, be silent + SET(LIBDL_FIND_QUIETLY TRUE) +ENDIF (LIBDL_INCLUDE_DIR) + +FIND_PATH(LIBDL_INCLUDE_DIR dlfcn.h) + +SET(LIBDL_NAMES dl libdl ltdl libltdl) +FIND_LIBRARY(LIBDL_LIBRARY NAMES ${LIBDL_NAMES} ) + +# handle the QUIETLY and REQUIRED arguments and set LIBDL_FOUND to TRUE if +# all listed variables are TRUE +INCLUDE(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibDL DEFAULT_MSG LIBDL_LIBRARY LIBDL_INCLUDE_DIR) + +IF(LIBDL_FOUND) + SET( LIBDL_LIBRARIES ${LIBDL_LIBRARY} ) +ELSE(LIBDL_FOUND) + SET( LIBDL_LIBRARIES ) +ENDIF(LIBDL_FOUND) + +MARK_AS_ADVANCED( LIBDL_LIBRARY LIBDL_INCLUDE_DIR ) diff --git a/config.cmake.in b/config.cmake.in index 73fca28a..b2589ee5 100644 --- a/config.cmake.in +++ b/config.cmake.in @@ -3,3 +3,4 @@ #cmakedefine HAVE_LIBREADLINE #cmakedefine HAVE_READLINE_READLINE_H #cmakedefine HAVE_READLINE_HISTORY_H +#cmakedefine HAVE_LIBDL diff --git a/doc/examples/compile1.cpp b/doc/examples/compile1.cpp index cc81229e..c63b9ca0 100644 --- a/doc/examples/compile1.cpp +++ b/doc/examples/compile1.cpp @@ -25,6 +25,9 @@ int main() // Our function pointer that points to the compiled ex FUNCP_1P fp; + + // Optionally, compile with custom compiler flags: + // setenv("CXXFLAGS", "-O3 -fomit-frame-pointer -ffast-math", 1); compile_ex(expr, x, fp); // Do some (not necessarily meaningful ;-)) numerical stuff ... diff --git a/doc/examples/compile2.cpp b/doc/examples/compile2.cpp index 1d344dd4..fb0813cb 100644 --- a/doc/examples/compile2.cpp +++ b/doc/examples/compile2.cpp @@ -43,6 +43,9 @@ int main() // Our function pointer that points to the compiled ex FUNCP_CUBA fp; + + // Optionally, compile with custom compiler flags: + // setenv("CXXFLAGS", "-O3 -fomit-frame-pointer -ffast-math", 1); compile_ex(lst(expr), lst(x,y), fp); // Starting VEGAS diff --git a/doc/examples/compile3.cpp b/doc/examples/compile3.cpp index 11a5a170..993c3b9f 100644 --- a/doc/examples/compile3.cpp +++ b/doc/examples/compile3.cpp @@ -27,6 +27,9 @@ int main() cout << "Building new 'compile3_testprg.so'." << endl; symbol a, b; ex expr = a*b; + + // Optionally, compile with custom compiler flags: + // setenv("CXXFLAGS", "-O3 -fomit-frame-pointer -ffast-math", 1); compile_ex(expr, a, b, fp, "compile3_testprg"); } diff --git a/doc/tutorial/ginac.texi b/doc/tutorial/ginac.texi index 360acb05..1021a32a 100644 --- a/doc/tutorial/ginac.texi +++ b/doc/tutorial/ginac.texi @@ -6692,7 +6692,13 @@ ones supplied to @code{compile_ex} should appear in the expression. @code{compile_ex} uses the shell script @code{ginac-excompiler} to start the C compiler and produce the object files. This shell script comes with GiNaC and will be installed together with GiNaC in the configured @code{$PREFIX/bin} -directory. +directory. You can also export additional compiler flags via the $CXXFLAGS +variable: + +@example +setenv("CXXFLAGS", "-O3 -fomit-frame-pointer -ffast-math", 1); +compile_ex(...); +@end example @subsection Archiving @cindex @code{archive} (class) diff --git a/ginsh/CMakeLists.txt b/ginsh/CMakeLists.txt index 5281add0..c350a21a 100644 --- a/ginsh/CMakeLists.txt +++ b/ginsh/CMakeLists.txt @@ -61,5 +61,5 @@ if (READLINE_FOUND) endif() add_executable(ginsh ${ginsh_SOURCES} ${ginsh_HEADERS}) -target_link_libraries(ginsh ginac ${ginsh_extra_libs}) +target_link_libraries(ginsh ginac ${ginsh_extra_libs} ${LIBDL_LIBRARIES}) install(TARGETS ginsh RUNTIME DESTINATION "${BIN_INSTALL_DIR}") diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 8ad8a072..d92e5d93 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -2,6 +2,15 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../ginac) add_definitions(-DIN_GINAC) add_executable(viewgar viewgar.cpp) -target_link_libraries(viewgar ginac) +target_link_libraries(viewgar ginac ${LIBDL_LIBRARIES}) install(TARGETS viewgar RUNTIME DESTINATION "${BIN_INSTALL_DIR}") +if (CMAKE_COMPILER_IS_GNUCC) + set (CC gcc) + configure_file ( + "${CMAKE_CURRENT_SOURCE_DIR}/ginac-excompiler.in" + "${CMAKE_CURRENT_BINARY_DIR}/ginac-excompiler" + ) + + install(PROGRAMS ginac-excompiler DESTINATION "${BIN_INSTALL_DIR}") +endif (CMAKE_COMPILER_IS_GNUCC) diff --git a/tools/ginac-excompiler.in b/tools/ginac-excompiler.in index 0bd0c970..488e22e4 100644 --- a/tools/ginac-excompiler.in +++ b/tools/ginac-excompiler.in @@ -1,2 +1,2 @@ #!/bin/sh -@CC@ -x c -fPIC -shared -o $1.so $1 +@CC@ -x c -fPIC -shared $CXXFLAGS -o $1.so $1 -- 2.44.0