Make compile_ex() work with CMake.
authorMartin Vala <mvala@saske.sk>
Tue, 14 Apr 2015 20:50:31 +0000 (22:50 +0200)
committerRichard Kreckel <kreckel@ginac.de>
Tue, 14 Apr 2015 20:50:31 +0000 (22:50 +0200)
Infrastructure fixes to make CMake find libdl and make ginac-excompiler
listen to the $CXXFLAGS environment variable.

CMakeLists.txt
check/CMakeLists.txt
cmake/modules/FindLibDL.cmake [new file with mode: 0644]
config.cmake.in
doc/examples/compile1.cpp
doc/examples/compile2.cpp
doc/examples/compile3.cpp
doc/tutorial/ginac.texi
ginsh/CMakeLists.txt
tools/CMakeLists.txt
tools/ginac-excompiler.in

index 86d76fa..122d94c 100644 (file)
@@ -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)
 
index 42fe50e..5bf53a1 100644 (file)
@@ -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 (file)
index 0000000..403a5c8
--- /dev/null
@@ -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 )
index 73fca28..b2589ee 100644 (file)
@@ -3,3 +3,4 @@
 #cmakedefine HAVE_LIBREADLINE
 #cmakedefine HAVE_READLINE_READLINE_H
 #cmakedefine HAVE_READLINE_HISTORY_H
+#cmakedefine HAVE_LIBDL
index cc81229..c63b9ca 100644 (file)
@@ -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 ...
index 1d344dd..fb0813c 100644 (file)
@@ -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
index 11a5a17..993c3b9 100644 (file)
@@ -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");
        }
 
index 360acb0..1021a32 100644 (file)
@@ -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)
index 5281add..c350a21 100644 (file)
@@ -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}")
index 8ad8a07..d92e5d9 100644 (file)
@@ -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)
index 0bd0c97..488e22e 100644 (file)
@@ -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