dev-cafe / autocmake

CMake plugin composer.
http://autocmake.org
BSD 3-Clause "New" or "Revised" License
41 stars 18 forks source link

openmp detection needs tweaking #177

Closed loriab closed 8 years ago

loriab commented 8 years ago

In a case where both Fortran and C or CXX languages are defined, the path through the omp module at present would add OpenMP flags to CMAKE_Fortran_FLAGS, then set(OPENMP_FOUND TRUE), then find_package(OpenMP) never gets run, so C/CXX never get OpenMP flags appended.

I think the logic you want is more like the below, where the pedestrian Fortran checking is only a fallback when the FindOpenMP is too old to support Fortran.

To get the newer Intel OpenMP flag -qopenmp, I also grabbed some lines from the FindOpenMP module: https://github.com/Kitware/CMake/blob/master/Modules/FindOpenMP.cmake#L84-L91

FYI, @robertodr

if(ENABLE_OPENMP)

    if(NOT OPENMP_FOUND)
        find_package(OpenMP)
    endif()

    if(OPENMP_FOUND)
        add_definitions(-DHAVE_OPENMP)
        if(DEFINED CMAKE_C_COMPILER_ID)
            set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
        endif()
        if(DEFINED CMAKE_CXX_COMPILER_ID)
            set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
        endif()
        if(DEFINED CMAKE_Fortran_COMPILER_ID)
            set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${OpenMP_Fortran_FLAGS}")
        endif()
    endif()

    if(DEFINED CMAKE_Fortran_COMPILER_ID AND NOT DEFINED OpenMP_Fortran_FLAGS)
        # we do this in a pedestrian way because the Fortran support is relatively recent
        if(CMAKE_Fortran_COMPILER_ID MATCHES GNU)
            set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fopenmp")
        endif()
        if(CMAKE_Fortran_COMPILER_ID MATCHES Intel)
            if(WIN32)
                set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -Qopenmp")
            elseif(CMAKE_Fortran_COMPILER_ID STREQUAL "Intel" AND
                   "${CMAKE_Fortran_COMPILER_VERSION}" VERSION_LESS "15.0.0.20140528")
                set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -openmp")
            else()
                set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -qopenmp")
            endif()
        endif()
        if(CMAKE_Fortran_COMPILER_ID MATCHES PGI)
            set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -mp")
        endif()
        if(CMAKE_Fortran_COMPILER_ID MATCHES XL)
            set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -qsmp")
        endif()
        if(CMAKE_Fortran_COMPILER_ID MATCHES Cray)
            # do nothing in this case
        endif()
        set(OPENMP_FOUND TRUE)
    endif()
endif()
bast commented 8 years ago

Thanks Lori! I will integrate it today.

bast commented 8 years ago

Done - thanks again!

loriab commented 8 years ago

Hi Radovan, thanks for the merge and for maintaining these CMake modules.