Permalink
Browse files

Fixes to accommodate plplot changes

  • Loading branch information...
1 parent 0d27842 commit 1f68c204517295d4e65923050282407f652fb570 @jtappin jtappin committed Dec 29, 2013
Showing with 174 additions and 17 deletions.
  1. +22 −11 CMakeLists.txt
  2. +93 −0 cmake/CheckFortranSourceCompiles.cmake
  3. +14 −6 plplot/CMakeLists.txt
  4. +45 −0 plplot/plplot_extra_ndef.f90
View
@@ -27,7 +27,7 @@
# CMAKE build file for GtkFortran
cmake_minimum_required(VERSION 2.8.5)
-project(gtk-fortran C Fortran)
+project(gtk-fortran Fortran)
# CMAKE versions up to and including 2.8.10 fail to add the GIO libs for GTK2
if (CMAKE_VERSION VERSION_LESS 2.8.11)
@@ -63,6 +63,7 @@ set(CPACK_SOURCE_GENERATOR "STGZ;TGZ")
include(CPack)
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
+include(CheckFortranSourceCompiles)
# uninstall target
configure_file(
@@ -114,19 +115,29 @@ if (NOT EXCLUDE_PLPLOT)
set(HAVE_LIBPLPLOTF95D ${PLPLOT_FOUND})
if(PLPLOT_FOUND)
set(LIBRARIES ${LIBRARIES} ${PLPLOT_LIBRARIES})
+
include_directories(${PLPLOT_INCLUDE_DIR})
include_directories(${PLPLOT_MODULE_DIR})
set(CMAKE_REQUIRED_LIBRARIES "${PLPLOT_LIBRARIES}")
- set(CMAKE_REQUIRED_INCLUDES "${PLPLOT_INCLUDE_DIR}")
- check_c_source_compiles("
-#include <plplot/plplot.h>
-int main(int argc, void *argv[])
-{
- PLFLT w = 0.5;
- plinit();
- plwidth(w);
-}" NEW_PLPLOT)
- else(PLPLOT_FOUND)
+ set(CMAKE_REQUIRED_INCLUDES "${PLPLOT_INCLUDE_DIR}; ${PLPLOT_MODULE_DIR}")
+ check_fortran_source_compiles("
+ program tw
+ use plplot
+ implicit none
+
+ real(kind=plflt) :: w = 0.5_plflt
+ call plinit()
+ call plwidth(w)
+ end program tw" NEW_PLPLOT)
+ check_fortran_source_compiles("
+ program tdef
+ use plplot
+ implicit none
+
+ integer :: i = PLESC_DEVINIT
+ end program tdef" NEW_PLPLOT_DEFS)
+
+else(PLPLOT_FOUND)
message(STATUS "PLPLOT not found: PLPLOT integration and examples will not be built")
endif(PLPLOT_FOUND)
else(NOT EXCLUDE_PLPLOT)
@@ -0,0 +1,93 @@
+# - Check if given Fortran source compiles and links into an executable
+# CHECK_FORTRAN_SOURCE_COMPILES(<code> <var> [FAIL_REGEX <fail-regex>])
+# <code> - source code to try to compile, must define 'main'
+# <var> - variable to store whether the source code compiled
+# <fail-regex> - fail if test output matches this regex
+# The following variables may be set before calling this macro to
+# modify the way the check is run:
+#
+# CMAKE_REQUIRED_FLAGS = string of compile command line flags
+# CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar)
+# CMAKE_REQUIRED_INCLUDES = list of include directories
+# CMAKE_REQUIRED_LIBRARIES = list of libraries to link
+
+#=============================================================================
+# Copyright 2005-2009 Kitware, Inc.
+# Fortran version, 2013, James Tappin
+#
+# Distributed under the OSI-approved BSD License (the "License");
+# see accompanying file Copyright.txt for details.
+#
+# This software is distributed WITHOUT ANY WARRANTY; without even the
+# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+# See the License for more information.
+#=============================================================================
+# (To distribute this file outside of CMake, substitute the full
+# License text for the above reference.)
+
+
+
+macro(CHECK_FORTRAN_SOURCE_COMPILES SOURCE VAR)
+ if("${VAR}" MATCHES "^${VAR}$")
+ set(_FAIL_REGEX)
+ set(_key)
+ foreach(arg ${ARGN})
+ if("${arg}" MATCHES "^(FAIL_REGEX)$")
+ set(_key "${arg}")
+ elseif(_key)
+ list(APPEND _${_key} "${arg}")
+ else()
+ message(FATAL_ERROR "Unknown argument:\n ${arg}\n")
+ endif()
+ endforeach()
+ set(MACRO_CHECK_FUNCTION_DEFINITIONS
+ "-D${VAR} ${CMAKE_REQUIRED_FLAGS}")
+ if(CMAKE_REQUIRED_LIBRARIES)
+ set(CHECK_FORTRAN_SOURCE_COMPILES_ADD_LIBRARIES
+ LINK_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
+ else()
+ set(CHECK_FORTRAN_SOURCE_COMPILES_ADD_LIBRARIES)
+ endif()
+ if(CMAKE_REQUIRED_INCLUDES)
+ set(CHECK_FORTRAN_SOURCE_COMPILES_ADD_INCLUDES
+ "-DINCLUDE_DIRECTORIES:STRING=${CMAKE_REQUIRED_INCLUDES}")
+ else()
+ set(CHECK_FORTRAN_SOURCE_COMPILES_ADD_INCLUDES)
+ endif()
+ file(WRITE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src.f90"
+ "${SOURCE}\n")
+
+ message(STATUS "Performing Test ${VAR}")
+ try_compile(${VAR}
+ ${CMAKE_BINARY_DIR}
+ ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src.f90
+ COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
+ ${CHECK_FORTRAN_SOURCE_COMPILES_ADD_LIBRARIES}
+ CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_FUNCTION_DEFINITIONS}
+ "${CHECK_FORTRAN_SOURCE_COMPILES_ADD_INCLUDES}"
+ OUTPUT_VARIABLE OUTPUT)
+
+ foreach(_regex ${_FAIL_REGEX})
+ if("${OUTPUT}" MATCHES "${_regex}")
+ set(${VAR} 0)
+ endif()
+ endforeach()
+
+ if(${VAR})
+ set(${VAR} 1 CACHE INTERNAL "Test ${VAR}")
+ message(STATUS "Performing Test ${VAR} - Success")
+ file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
+ "Performing Fortran SOURCE FILE Test ${VAR} succeded with the following output:\n"
+ "${OUTPUT}\n"
+ "Source file was:\n${SOURCE}\n")
+ else()
+ message(STATUS "Performing Test ${VAR} - Failed")
+ set(${VAR} "" CACHE INTERNAL "Test ${VAR}")
+ file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
+ "Performing Fortran SOURCE FILE Test ${VAR} failed with the following output:\n"
+ "${OUTPUT}\n"
+ "Source file was:\n${SOURCE}\n")
+ endif()
+ endif()
+endmacro()
+
View
@@ -20,7 +20,7 @@
# this program; see the files COPYING3 and COPYING.RUNTIME respectively.
# If not, see <http://www.gnu.org/licenses/>.
#
-# Contributed by James Tappin, last updated: 1/21/2013
+# Contributed by James Tappin, last updated: 12/29/2013
# set(sources
# "plplot_extra.f90")
@@ -32,11 +32,19 @@ 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)
+if(NEW_PLPLOT_DEFS)
+ add_custom_command(
+ OUTPUT plplot_extra.mod
+ COMMAND ${CMAKE_Fortran_COMPILER} -c ${CMAKE_CURRENT_SOURCE_DIR}/plplot_extra_ndef.f90
+ DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/plplot_extra_ndef.f90)
+ add_custom_target(plplot_extra_module ALL DEPENDS plplot_extra.mod)
+else()
+ 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)
+endif()
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/plplot_extra.mod"
@@ -0,0 +1,45 @@
+! Copyright (C) 2011
+! 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
+! Last modification: 8/2/2012
+
+module plplot_extra
+ ! Plplot extras for accessing the pl_cmd routine.
+
+ use iso_c_binding
+
+ implicit none
+
+ ! The operation codes for pl_cmd
+ ! In plplot 5.9.11 (and later?) these definitions are in the F95 binding
+
+ ! Interface for the pl_cmd routine
+ interface
+ subroutine pl_cmd(cmd, arg) bind(c)
+ use iso_c_binding, only: c_int, c_ptr
+ integer(kind=c_int), value :: cmd
+ type(c_ptr), value :: arg
+ end subroutine pl_cmd
+ end interface
+end module plplot_extra

0 comments on commit 1f68c20

Please sign in to comment.