diff options
author | Brad King <brad.king@kitware.com> | 2014-08-19 13:48:41 (GMT) |
---|---|---|
committer | CMake Topic Stage <kwrobot@kitware.com> | 2014-08-19 13:48:41 (GMT) |
commit | c91a65f812ae65ebff45e09ecb9948d2bf695b8b (patch) | |
tree | 1ebf7382dacf999d44125dd3c70d1e247172f72c /Modules | |
parent | eea6103c10a697f727cb4638e36b5cd72eff749c (diff) | |
parent | d0678408543d362f127b9ee45453283e38c25415 (diff) | |
download | CMake-c91a65f812ae65ebff45e09ecb9948d2bf695b8b.zip CMake-c91a65f812ae65ebff45e09ecb9948d2bf695b8b.tar.gz CMake-c91a65f812ae65ebff45e09ecb9948d2bf695b8b.tar.bz2 |
Merge topic 'FindOpenMP-add-Fortran-support'
d0678408 FindOpenMP: Add support for Fortran (#14656)
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/FindOpenMP.cmake | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/Modules/FindOpenMP.cmake b/Modules/FindOpenMP.cmake index 935a0ca..801b4f8 100644 --- a/Modules/FindOpenMP.cmake +++ b/Modules/FindOpenMP.cmake @@ -16,6 +16,7 @@ # # OpenMP_C_FLAGS - flags to add to the C compiler for OpenMP support # OpenMP_CXX_FLAGS - flags to add to the CXX compiler for OpenMP support +# OpenMP_Fortran_FLAGS - flags to add to the Fortran compiler for OpenMP support # OPENMP_FOUND - true if openmp is detected # # @@ -27,6 +28,7 @@ # Copyright 2009 Kitware, Inc. # Copyright 2008-2009 André Rigland Brodtkorb <Andre.Brodtkorb@ifi.uio.no> # Copyright 2012 Rolf Eike Beer <eike@sf-mail.de> +# Copyright 2014 Nicolas Bock <nicolasbock@gmail.com> # # Distributed under the OSI-approved BSD License (the "License"); # see accompanying file Copyright.txt for details. @@ -106,6 +108,17 @@ int main() { } ") +# same in Fortran +set(OpenMP_Fortran_TEST_SOURCE + " +program test +use omp_lib +integer :: n +n = omp_get_num_threads() +end program test + " + ) + # check c compiler if(CMAKE_C_COMPILER_LOADED) # if these are set then do not try to find them again, @@ -176,6 +189,40 @@ if(CMAKE_CXX_COMPILER_LOADED) unset(OpenMP_CXX_TEST_SOURCE) endif() +# check Fortran compiler +if(CMAKE_Fortran_COMPILER_LOADED) + # if these are set then do not try to find them again, + # by avoiding any try_compiles for the flags + if(OpenMP_Fortran_FLAGS) + unset(OpenMP_Fortran_FLAG_CANDIDATES) + else() + _OPENMP_FLAG_CANDIDATES("Fortran") + include(${CMAKE_CURRENT_LIST_DIR}/CheckFortranSourceCompiles.cmake) + endif() + + foreach(FLAG IN LISTS OpenMP_Fortran_FLAG_CANDIDATES) + set(SAFE_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}") + set(CMAKE_REQUIRED_FLAGS "${FLAG}") + unset(OpenMP_FLAG_DETECTED CACHE) + if(NOT CMAKE_REQUIRED_QUIET) + message(STATUS "Try OpenMP Fortran flag = [${FLAG}]") + endif() + check_fortran_source_compiles("${OpenMP_Fortran_TEST_SOURCE}" OpenMP_FLAG_DETECTED) + set(CMAKE_REQUIRED_FLAGS "${SAFE_CMAKE_REQUIRED_FLAGS}") + if(OpenMP_FLAG_DETECTED) + set(OpenMP_Fortran_FLAGS_INTERNAL "${FLAG}") + break() + endif() + endforeach() + + set(OpenMP_Fortran_FLAGS "${OpenMP_Fortran_FLAGS_INTERNAL}" + CACHE STRING "Fortran compiler flags for OpenMP parallization") + + list(APPEND _OPENMP_REQUIRED_VARS OpenMP_Fortran_FLAGS) + unset(OpenMP_Fortran_FLAG_CANDIDATES) + unset(OpenMP_Fortran_TEST_SOURCE) +endif() + set(CMAKE_REQUIRED_QUIET ${CMAKE_REQUIRED_QUIET_SAVE}) if(_OPENMP_REQUIRED_VARS) |