]> www.ginac.de Git - ginac.git/commitdiff
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 86d76face6cac515d5481f8f6e5a08ac0a6d2b7a..122d94cad70699ab332c59438abb4e52a18f2fd0 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 42fe50e1f4457eb4b8ab8bdbe037d91c9c9837ac..5bf53a19669c1e75f55eaa43f32fa29d5e305bd8 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 73fca28ae143a4e5ef771a85b62438f0dd296a67..b2589ee5a702688af33aa2571fc458a77b4f84d0 100644 (file)
@@ -3,3 +3,4 @@
 #cmakedefine HAVE_LIBREADLINE
 #cmakedefine HAVE_READLINE_READLINE_H
 #cmakedefine HAVE_READLINE_HISTORY_H
+#cmakedefine HAVE_LIBDL
index cc81229e84c2ac721613696552253337f85b0c31..c63b9ca022bd2f6bf5dfae75f1c5dc25ef58e376 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 1d344dd4d49b8cc857424625caf6305d73292326..fb0813cb6f0f33e4fbecfd88044c5363abecddd6 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 11a5a17070254b2251b12e5ae7f8c2aa61f0029d..993c3b9ff12aaa369e53376c293b0c228081dca3 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 360acb05a0e98b1a38f8923f7b43920aa266cabc..1021a32a22760cced31fd114e686d27e8a1c01cd 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 5281add0c637b08ab82a00f776f6cabcebbd9304..c350a21ab5a3e328b4b6cd3a298c4afa85c187ed 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 8ad8a072764ca744f6e48a744003ac62d941fb46..d92e5d930487ab5a352e972fc877d9a5959b0870 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 0bd0c9709e8416ece3c4b2a81420366e1a58a1d1..488e22e4919829dcda664252e9b8b626c4c8acba 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