Commit c684ff6c authored by Michael Hirsch, Ph.D's avatar Michael Hirsch, Ph.D

add Fortran 2008 coarray support

cleanupfcn
parent 02464dd5
Pipeline #125034 passed with stage
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
#[=======================================================================[.rst:
FindCoarray
----------
Finds compiler flags or library necessary to support Fortran 2008/2018 coarrays.
This packages primary purposes are:
* for compilers natively supporting Fortran coarrays without needing compiler options, simply indicating Coarray_FOUND (example: Cray)
* for compilers with built-in Fortran coarray support, enable compiler option (example: Intel Fortran)
* for compilers needing a library such as OpenCoarrays, presenting library (example: GNU)
Result Variables
^^^^^^^^^^^^^^^^
``Coarray_FOUND``
indicates coarray support found (whether built-in or library)
``Coarray_LIBRARIES``
coarray library path
``Coarray_COMPILE_OPTIONS``
coarray compiler options
``Coarray_EXECUTABLE``
coarray executable e.g. ``cafrun``
``Coarray_MAX_NUMPROCS``
maximum number of parallel processes
``Coarray_NUMPROC_FLAG``
use for executing in parallel: ${Coarray_EXECUTABLE} ${Coarray_NUMPROC_FLAG} ${Coarray_MAX_NUMPROCS} ${CMAKE_CURRENT_BINARY_DIR}/myprogram
Cache Variables
^^^^^^^^^^^^^^^^
The following cache variables may also be set:
``Coarray_LIBRARY``
The coarray libraries, if needed and found
#]=======================================================================]
cmake_policy(VERSION 3.3)
set(options_coarray Intel) # flags needed
set(opencoarray_supported GNU) # future: Flang, etc.
unset(Coarray_COMPILE_OPTIONS)
unset(Coarray_LIBRARY)
unset(Coarray_REQUIRED_VARS)
if(CMAKE_Fortran_COMPILER_ID IN_LIST options_coarray)
if(CMAKE_Fortran_COMPILER_ID STREQUAL Intel)
set(Coarray_COMPILE_OPTIONS -coarray=shared)
set(Coarray_LIBRARY -coarray=shared) # ifort requires it at build AND link
endif()
list(APPEND Coarray_REQUIRED_VARS ${Coarray_LIBRARY})
elseif(CMAKE_Fortran_COMPILER_ID IN_LIST opencoarray_supported)
find_package(OpenCoarrays)
if(OpenCoarrays_FOUND)
set(Coarray_LIBRARY OpenCoarrays::caf_mpi)
set(Coarray_EXECUTABLE cafrun)
include(ProcessorCount)
ProcessorCount(Nproc)
set(Coarray_MAX_NUMPROCS ${Nproc})
set(Coarray_NUMPROC_FLAG -np)
list(APPEND Coarray_REQUIRED_VARS ${Coarray_LIBRARY})
elseif(CMAKE_Fortran_COMPILER_ID STREQUAL GNU)
set(Coarray_COMPILE_OPTIONS -fcoarray=single)
list(APPEND Coarray_REQUIRED_VARS ${Coarray_COMPILE_OPTIONS})
endif()
endif()
set(CMAKE_REQUIRED_FLAGS ${Coarray_COMPILE_OPTIONS})
set(CMAKE_REQUIRED_LIBRARIES ${Coarray_LIBRARY})
include(CheckFortranSourceCompiles)
check_fortran_source_compiles("program a; real :: x[*]; end" f08coarray SRC_EXT f90)
unset(CMAKE_REQUIRED_FLAGS)
unset(CMAKE_REQUIRED_LIBRARIES)
list(APPEND Coarray_REQUIRED_VARS ${f08coarray})
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Coarray
REQUIRED_VARS Coarray_REQUIRED_VARS)
set(Coarray_LIBRARIES ${Coarray_LIBRARY})
mark_as_advanced(
Coarray_LIBRARY
Coarray_REQUIRED_VARS)
# Distributed under the OSI-approved BSD 3-Clause License.
# Copyright 2013, Julien Schueller
# Copyright 2018, Michael Hirsch, Ph.D.
#[=======================================================================[.rst:
FindOctave
----------
Finds GNU Octave and provides Octave tools, libraries and compilers to CMake.
This packages primary purposes are
* find the Octave exectuable to be able to run unit tests on ``.m`` code
* to run specific commands in Octave
Two components are supported:
* ``Interpreter``: search for Octave interpreter
* ``Development``: search for development artifacts (include directories and libraries). Implies ``Interpreter``
If no ``COMPONENTS`` are specified, ``Interpreter`` is assumed.
Module Input Variables
^^^^^^^^^^^^^^^^^^^^^^
Users or projects may set the following variables to configure the module
behaviour:
:variable:`Octave_ROOT`
the root of the Octave installation.
Variables defined by the module
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Result variables
""""""""""""""""
``Octave_FOUND``
``TRUE`` if the Octave installation is found, ``FALSE`` otherwise.
``Octave_Interpreter_FOUND``
``TRUE`` if the Octave interpreter is found, ``FALSE`` otherwise.
``Octave_Development_FOUND``
``TRUE`` if the Octave libraries are found, ``FALSE`` otherwise.
``Octave_MAIN_PROGRAM``
Octave interpreter
``Octave_INCLUDE_DIRS``
include path for mex.h
``Octave_LIBRARIES``
octinterp, octave
``Octave_OCTINTERP_LIBRARY``
path to the library octinterp
``Octave_OCTAVE_LIBRARY``
path to the liboctave
``Octave_VERSION``
Octave version string
``Octave_VERSION_MAJOR``
major version
``Octave_VERSION_MINOR``
minor version
``Octave_VERSION_PATCH``
patch version
``Octave_OCT_FILE_DIR``
object files that will be dynamically loaded
``Octave_OCT_LIB_DIR``
oct libraries
#]=======================================================================]
cmake_policy(VERSION 3.3)
if(Development IN_LIST Octave_FIND_COMPONENTS)
find_program(Octave_CONFIG_EXECUTABLE
NAMES octave-config
HINTS ${Octave_ROOT})
if(Octave_CONFIG_EXECUTABLE)
execute_process(COMMAND ${Octave_CONFIG_EXECUTABLE} -p BINDIR
OUTPUT_VARIABLE Octave_BIN_PATHS
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ${Octave_CONFIG_EXECUTABLE} -p OCTINCLUDEDIR
OUTPUT_VARIABLE Octave_INCLUDE_PATHS
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ${Octave_CONFIG_EXECUTABLE} -p OCTLIBDIR
OUTPUT_VARIABLE Octave_LIBRARIES_PATHS
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ${Octave_CONFIG_EXECUTABLE} -p OCTFILEDIR
OUTPUT_VARIABLE Octave_OCT_FILE_DIR
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ${Octave_CONFIG_EXECUTABLE} -p OCTLIBDIR
OUTPUT_VARIABLE Octave_OCT_LIB_DIR
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
find_program(Octave_MAIN_PROGRAM
NAMES octave
HINTS ${Octave_BIN_PATHS}
)
find_library(Octave_OCTINTERP_LIBRARY
NAMES octinterp
HINTS ${Octave_LIBRARIES_PATHS}
)
find_library(Octave_OCTAVE_LIBRARY
NAMES octave
HINTS ${Octave_LIBRARIES_PATHS}
)
set(Octave_LIBRARIES ${Octave_OCTINTERP_LIBRARY} ${Octave_OCTAVE_LIBRARY})
find_path(Octave_INCLUDE_DIR
NAMES mex.h
HINTS ${Octave_INCLUDE_PATHS}
)
set(Octave_INCLUDE_DIRS ${Octave_INCLUDE_DIR})
if(Octave_OCTAVE_LIBRARY)
set(Octave_Development_FOUND true)
endif()
endif()
else()
find_program(Octave_MAIN_PROGRAM
NAMES octave
HINTS ${Octave_ROOT})
endif()
if(Octave_MAIN_PROGRAM)
execute_process(COMMAND ${Octave_MAIN_PROGRAM} -v
OUTPUT_VARIABLE Octave_VERSION
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
string(REGEX REPLACE "GNU Octave, version ([0-9]+)\\.[0-9]+\\.[0-9]+.*" "\\1" Octave_VERSION_MAJOR ${Octave_VERSION})
string(REGEX REPLACE "GNU Octave, version [0-9]+\\.([0-9]+)\\.[0-9]+.*" "\\1" Octave_VERSION_MINOR ${Octave_VERSION})
string(REGEX REPLACE "GNU Octave, version [0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" Octave_VERSION_PATCH ${Octave_VERSION})
set(Octave_VERSION ${Octave_VERSION_MAJOR}.${Octave_VERSION_MINOR}.${Octave_VERSION_PATCH})
set(Octave_Interpreter_FOUND true)
endif()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Octave
REQUIRED_VARS Octave_MAIN_PROGRAM
VERSION_VAR Octave_VERSION
HANDLE_COMPONENTS)
mark_as_advanced(
Octave_OCT_FILE_DIR
Octave_OCT_LIB_DIR
Octave_OCTINTERP_LIBRARY
Octave_OCTAVE_LIBRARY
Octave_LIBRARIES
Octave_INCLUDE_DIR
Octave_INCLUDE_DIRS
Octave_VERSION
Octave_VERSION_MAJOR
Octave_VERSION_MINOR
Octave_VERSION_PATCH
)
add_test(NAME FindCoarray.Test COMMAND
${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION>
--build-and-test
"${CMake_SOURCE_DIR}/Tests/FindCoarray/Test"
"${CMake_BINARY_DIR}/Tests/FindCoarray/Test"
${build_generator_args}
--build-project TestFindCoarray
--build-options ${build_options}
--test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION>
)
cmake_minimum_required(VERSION 3.3)
project(TestFindCoarray Fortran)
enable_testing()
find_package(Coarray REQUIRED)
add_executable(test_var main.f90)
target_compile_options(test_var PRIVATE ${Coarray_COMPILE_OPTIONS})
target_link_libraries(test_var PRIVATE ${Coarray_LIBRARIES})
add_test(NAME test_var COMMAND test_var)
program a
real :: x[*]
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment