Skip to content

Commit

Permalink
Make plplot detection automatic. Fix up a few omissions.
Browse files Browse the repository at this point in the history
  • Loading branch information
jtappin committed Aug 8, 2012
1 parent 7050750 commit 6f0462b
Show file tree
Hide file tree
Showing 27 changed files with 1,580 additions and 1,120 deletions.
34 changes: 27 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,25 @@
# this program; see the files COPYING3 and COPYING.RUNTIME respectively.
# If not, see <http://www.gnu.org/licenses/>.
#
# Contributed by Kyle Horne: 05.11.2011 (Gtk3 conversion James Tappin)
# Contributed by Kyle Horne: 05.11.2011
# Last modifications: James Tappin 8/7/2012.

# CMAKE build file for GtkFortran

cmake_minimum_required(VERSION 2.6)
project(gtk-fortran C Fortran)

# Uncomment this for a debug build
# SET(CMAKE_BUILD_TYPE debug)
# Uncomment this to debug or use "cmake -D CMAKE_BUILD_TYPE=debug .."
# set(CMAKE_BUILD_TYPE debug)
# set(CMAKE_BUILD_TYPE release)

set(CMAKE_Fortran_FLAGS_DEBUG
"-g -pthread -Wall -Wtabs -fcheck-array-temporaries -fbacktrace -fbounds-check -ffpe-trap=invalid,zero,overflow -Wno-unused-dummy-argument")
set(CMAKE_Fortran_FLAGS_DEBUG
"-g -pthread -Wall -Wtabs -fcheck-array-temporaries -fbacktrace -fbounds-check -ffpe-trap=invalid,zero,overflow -Wno-unused-dummy-argument")
set(CMAKE_Fortran_FLAGS_RELEASE
"-pthread -O3 -mtune=native -march=native")

set(CPACK_PACKAGE_VERSION "0.1.0")
set(CPACK_PACKAGE_INSTALL_DIRECTORY "gtk3-fortran")
set(CPACK_PACKAGE_INSTALL_DIRECTORY "gtk2-fortran")
set(CPACK_GENERATOR "STGZ;TGZ")
set(CPACK_SOURCE_GENERATOR "STGZ;TGZ")
include(CPack)
Expand Down Expand Up @@ -87,6 +89,24 @@ documentation..." WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
add_custom_target(doc)
add_dependencies(doc doxygen)

#
if (NOT EXCLUDE_PLPLOT)
find_package(PlplotF95 QUIET)
set(HAVE_LIBPLPLOTF95D ${PLPLOT_FOUND})
if(PLPLOT_FOUND)
set(LIBRARIES ${LIBRARIES} ${PLPLOT_LIBRARIES})
include_directories(${PLPLOT_INCLUDE_DIR})
include_directories(${PLPLOT_MODULE_DIR})
else(PLPLOT_FOUND)
message(STATUS "PLPLOT not found: PLPLOT integration and examples will not be built")
endif(PLPLOT_FOUND)
else(NOT EXCLUDE_PLPLOT)
message(STATUS "PLPLOT Excluded as command option")
endif(NOT EXCLUDE_PLPLOT)

add_subdirectory(src)
add_subdirectory(test)
add_subdirectory(examples)
add_subdirectory(sketcher)
if(PLPLOT_FOUND AND NOT EXCLUDE_PLPLOT)
add_subdirectory(plplot)
endif(PLPLOT_FOUND AND NOT EXCLUDE_PLPLOT)
4 changes: 2 additions & 2 deletions cmake/FindGTK3.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ list(APPEND GTK3_LIBRARIES ${FREETYPE_LIBRARIES})
foreach(_GTK3_component ${GTK3_FIND_COMPONENTS})
if(_GTK3_component STREQUAL "gtk")
_GTK3_FIND_INCLUDE_DIR(GTK3_GLIB_INCLUDE_DIR glib.h)
_GTK3_FIND_INCLUDE_DIR(GTK3_GLIBCONFIG_INCLUDE_DIR glibconfig.h)
# _GTK3_FIND_INCLUDE_DIR(GTK3_GLIBCONFIG_INCLUDE_DIR glibconfig.h)
_GTK3_FIND_LIBRARY (GTK3_GLIB_LIBRARY glib false true)

_GTK3_FIND_INCLUDE_DIR(GTK3_GOBJECT_INCLUDE_DIR gobject/gobject.h)
Expand All @@ -397,7 +397,7 @@ foreach(_GTK3_component ${GTK3_FIND_COMPONENTS})
_GTK3_FIND_LIBRARY (GTK3_GDK_PIXBUF_LIBRARY gdk_pixbuf false true)

_GTK3_FIND_INCLUDE_DIR(GTK3_GDK_INCLUDE_DIR gdk/gdk.h)
_GTK3_FIND_INCLUDE_DIR(GTK3_GDKCONFIG_INCLUDE_DIR gdkconfig.h)
_GTK3_FIND_INCLUDE_DIR(GTK3_GDKCONFIG_INCLUDE_DIR gdk/gdkconfig.h)
_GTK3_FIND_INCLUDE_DIR(GTK3_GTK_INCLUDE_DIR gtk/gtk.h)

# ********* At least on Debian the gdk & gtk libraries
Expand Down
34 changes: 34 additions & 0 deletions cmake/FindPlplotF95.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#
# copyright : (c) 2010 Maxime Lenoir, Alain Coulais,
# Sylwester Arabas and Orion Poplawski
#
# Modified to find Fortran rather than C++ libraries:
# July 2012: James Tappin
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#

find_package(PkgConfig)
pkg_check_modules(PLPLOTF95 QUIET plplotd-f95)

find_library(PLPLOT_LIBRARY NAMES plplotd)
find_library(PLPLOTF95_LIBRARY NAMES plplotf95d)
find_library(PLPLOTF95C_LIBRARY NAMES plplotf95cd)
set(PLPLOT_LIBRARIES ${PLPLOT_LIBRARY} ${PLPLOTF95_LIBRARY} ${PLPLOTF95C_LIBRARY})
find_path(PLPLOT_INCLUDE_DIR NAMES plplot/plplot.h)
find_path(PLPLOT_MODULE_DIR NAMES plplot.mod PATHS ${PLPLOTF95_INCLUDE_DIRS})
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(PLPLOT DEFAULT_MSG PLPLOT_LIBRARIES
PLPLOT_INCLUDE_DIR)

mark_as_advanced(
PLPLOT_LIBRARY
PLPLOTCF95_LIBRARY
PLPLOTCF95C_LIBRARY
PLPLOT_LIBRARIES
PLPLOT_INCLUDE_DIR
PLPLOT_MODULE_DIR
)
65 changes: 65 additions & 0 deletions plplot/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Free Software Foundation, Inc.
#
# This file is part of the gtk-fortran gtk+ Fortran Interface library.
#
# This is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
#
# This software is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# Under Section 7 of GPL version 3, you are granted additional
# permissions described in the GCC Runtime Library Exception, version
# 3.1, as published by the Free Software Foundation.
#
# You should have received a copy of the GNU General Public License along with
# this program; see the files COPYING3 and COPYING.RUNTIME respectively.
# If not, see <http://www.gnu.org/licenses/>.
#
# Contributed by James Tappin: 7/31/2012

# set(sources
# "plplot_extra.f90")

include_directories("/usr/include")
#include_directories(${PLPLOT_INCLUDES})
include_directories("${CMAKE_BINARY_DIR}/plplot")
include_directories("${CMAKE_BINARY_DIR}/src")
include_directories(${GTK_INCLUDES})
#include_directories(${PLPLOT_MODULE_DIR})

add_custom_command(
OUTPUT plplot_extra.mod
COMMAND ${CMAKE_Fortran_COMPILER} -c ${CMAKE_CURRENT_SOURCE_DIR}/plplot_extra.f90
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/plplot_extra.f90)
add_custom_target(plplot_extra_module ALL DEPENDS plplot_extra.mod)

install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/plplot_extra.mod"
DESTINATION include/gtk-2-fortran)

add_executable(hl_plplot1e "hl_plplot1e.f90")
add_dependencies(hl_plplot1e plplot_extra_module)
target_link_libraries(hl_plplot1e gtk-fortran_static ${GTK_LIBRARIES} ${PLPLOT_LIBRARIES})
add_test(hl_plplot1e ./hl_plplot1e)

add_executable(hl_plplot8e "hl_plplot8e.f90")
add_dependencies(hl_plplot8e plplot_extra_module)
target_link_libraries(hl_plplot8e gtk-fortran_static ${GTK_LIBRARIES} ${PLPLOT_LIBRARIES})
add_test(hl_plplot8e ./hl_plplot8e)

add_executable(hl_plplot17e "hl_plplot17e.f90")
add_dependencies(hl_plplot17e plplot_extra_module)
target_link_libraries(hl_plplot17e gtk-fortran_static ${GTK_LIBRARIES} ${PLPLOT_LIBRARIES})
add_test(hl_plplot17e ./hl_plplot17e)

# Excluded in this version as it needs at least 5.9.7 and Oneiric doesn't provide it.
# add_executable(hl_plplot30e "hl_plplot30e.f90")
# add_dependencies(hl_plplot30e plplot_extra_module)
# target_link_libraries(hl_plplot30e gtk-fortran_static ${GTK_LIBRARIES} ${PLPLOT_LIBRARIES})
# add_test(hl_plplot30e ./hl_plplot30e)

File renamed without changes.
80 changes: 52 additions & 28 deletions graphics/plplot/README → plplot/README
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,20 @@ Requirements
------------

gtk-fortran: (including for these examples the high-level modules gtk_hl
and gtk_draw_hl), gtk2 or gtk3 should work. It is easiest to build the
and gtk_draw_hl), gtk2 and gtk3 should both work. It is easiest to build the
examples if gtk-fortran and its pkg-config file are installed on your
system.

plplot: including the fortran95 bindings and the cairo drivers. They
are tested with the current release -- 5.9.7.
are tested with the current release -- 5.9.9.
It is known that example 30 will not build with version 5.9.5, but is
buildable with 5.9.7.

N.B. As of version 5.9.9 (8?) the drawing codes are defined in the
plplot Fortran interface. I have therefore commented them out in the
plplot_extra module (but left them for those with older plplot
versions).
A wrapper module plplot_extra.mod is created by the gtk-fortran system
to allow access to the pl_cmd routine in plplot which is not in the
Fortran95 binding. It provides low-level access to the system and is
needed to correctly configure the "extcairo" driver. The module also
provides the mnemonic command codes for pl_cmd.

Concept
-------
Expand All @@ -44,17 +47,25 @@ Handlers:
PLplot drawing:
Connect plplot's output to the backing surface (see below).
Make the plot(s)
call gtk_widget_queue_draw on the drawing area to force a
Call gtk_widget_queue_draw on the drawing area to force a
redraw.

Globals:
For convenience in both examples I've put all the gtk use
For convenience in all examples I've put all the gtk (etc.) use
statements and any global variables into a separate module that
can be used by all of the other units.

Connecting PLplot's output to the pixbuf.
In the example codes these are:

For the extcairo driver, output is to an externally greated cairo
* The main program (called cairo_plplot_ex<n>)
* The common module (common_ex<n>)
* The drawing module (plplot_code_ex<n>)
* The handlers (handlers_ex<n>)

Connecting PLplot's output to the drawing area.
-----------------------------------------------

For the "extcairo" driver, output is to an externally-created cairo
context. So here you need to create a cairo context connected to the
backing surface (this is most easily done with
hl_gtk_drawing_area_cairo_new). And then use pl_cmd to connect plplot's
Expand All @@ -75,9 +86,9 @@ the call to plinit (or plstar):
write(geometry, "(I0,'x',I0)") width, height
call plsetopt("geometry", geometry)

And then after plinit or plstar you need:
And then after plinit you need:

call pl_cmd(PLESC_DEVINIT, cc)
call pl_cmd(PLESC_DEVINIT, cc)

A fortran interface to pl_cmd is provided by the plplot_extras module
in this directory.
Expand All @@ -86,36 +97,49 @@ in this directory.
Building the examples
---------------------

If plplot is found when building gtk-fortran, then the interface module
for pl_cmd will be built and installed and the examples will be
built. The instructions that follow are therefore only needed if you
want to build them manually for some reason.

The plplot example(s) are most easily built if gtk-fortran has been
installed. Then it is simply a matter of:

gfortran -o hl_plplot<x> hl_plplot<x>.f90 `pkg-config --cflags --libs \
gtk-2-fortran plplotd-f95`
gfortran -o hl_plplot<x>e hl_plplot<x>e.f90 `pkg-config --cflags --libs \
gtk-<n>-fortran plplotd-f95`

where <x> is the number of the example. A basic Makefile to do this is
provided.
where <x> is the number of the example, and <n> is 2 or 3 according to
which gtk version you are using.

The examples are derived from the Fortran95 versions of Examples 1, 8,
30 and 17 on the PLplot web site.

hl_plplot1e: Basic x-y plots on multiple pages
hl_plplot8e: 3-D data display
hl_plplot17e: Strip charts, shows continuous updating
hl_plplot30e: Transparency.
hl_plplot30e: Transparency (needs at least plplot 5.9.7).


If you wish to explicitly exclude building and installing plplot
support, then when running cmake, include the option "-D
EXCLUDE_PLPLOT=Y" (e.g.:
cmake -D EXCLUDE_PLPLOT=Y ..
)

Known issues
------------

Different releases of gfortran (let alone different fortran compilers)
cannot read each other's module files, therefore plplot must be built
with the same compiler as gtk-fortran. Since not many Linux distros use
gcc/gfortran 4.6 yet, this means you will probably need to build plplot
from source. In addition the x86_64 gfortran binary snapshots for 4.6 &
4.7 fail to build the C++ parts of plplot, unless you remove the c++
compiler binaries/links from the snapshot directory (I tried forcing
the c++ compiler to be /usr/bin/c++ with ccmake but I couldn't get it
to stick).

Since the modifications to the high-level drawing routines, it is no
longer possible to use the "memcairo" device to capture cairo output
into a pixbuf (but that was somewhat of a kludge anyway).
with the same compiler as gtk-fortran. For most Linux distributions,
this is no longer an issue as most use gcc 4.6 or 4.7. However for
those that are still based on 4.5 or lower [*], this means you will
probably need to build plplot from source. In addition when I last used
this method, the x86_64 gfortran binary snapshots for 4.6 & 4.7 failed
to build the C++ parts of plplot, unless you remove the c++ compiler
binaries/links from the snapshot directory (I tried forcing the c++
compiler to be /usr/bin/c++ with ccmake but I couldn't get it to
stick).

[*] To my knowledge RHEL, SUSE, Slackware and Debian Stable (and their
derivatives), but not Fedora or OpenSUSE.
Loading

0 comments on commit 6f0462b

Please sign in to comment.