Skip to content

Commit

Permalink
Allow overridding OpenMP flags to empty (trilinos/Trilinos#1400)
Browse files Browse the repository at this point in the history
I don't have automated tests for this.  Adding automated tests would require
actually running with a compiler with OpenMPI support.  That would make these
tests not very portable.  Therefore, I manually tested this.  But the code is
very simple so it would be hard to break unless you were very sloppy.

Build/Test Cases Summary
Enabled Packages:
Enabled all Packages
0) MPI_DEBUG => passed: passed=265,notpassed=0 (0.80 min)
1) SERIAL_RELEASE => passed: passed=265,notpassed=0 (0.59 min)
2) MPI_DEBUG_CMAKE-3.6.2 => passed: passed=286,notpassed=0 (0.65 min)
3) SERIAL_RELEASE_CMAKE-3.6.2 => passed: passed=286,notpassed=0 (0.50 min)
Other local commits for this build/test group: 24d3975
  • Loading branch information
bartlettroscoe committed Dec 2, 2017
1 parent 24d3975 commit b9d3531
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
16 changes: 13 additions & 3 deletions tribits/core/package_arch/TribitsGlobalMacros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -1951,10 +1951,10 @@ MACRO(TRIBITS_SETUP_ENV)
IF(${PROJECT_NAME}_ENABLE_OpenMP)
FIND_PACKAGE(OpenMP)
IF(OPENMP_FOUND)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
TRIBITS_SET_OPENMP_FLAGS(CXX)
TRIBITS_SET_OPENMP_FLAGS(C)
IF(OpenMP_Fortran_FLAGS)
SET(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${OpenMP_Fortran_FLAGS}")
TRIBITS_SET_OPENMP_FLAGS(Fortran)
ELSE()
# Older versions of FindOpenMP.cmake don't find Fortran flags. Mike H said this is safe.
SET(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${OpenMP_C_FLAGS}")
Expand Down Expand Up @@ -2012,6 +2012,16 @@ MACRO(TRIBITS_SETUP_ENV)

ENDMACRO()


MACRO(TRIBITS_SET_OPENMP_FLAGS LANG)
IF (NOT "${OpenMP_${LANG}_FLAGS_OVERRIDE}" STREQUAL "")
SET(CMAKE_${LANG}_FLAGS "${CMAKE_${LANG}_FLAGS} ${OpenMP_${LANG}_FLAGS_OVERRIDE}")
ELSE()
SET(CMAKE_${LANG}_FLAGS "${CMAKE_${LANG}_FLAGS} ${OpenMP_${LANG}_FLAGS}")
ENDIF()
ENDMACRO()


#
# Set mapping of labels to subprojects (i.e. TriBITS packages) for local CTest
# only.
Expand Down
11 changes: 11 additions & 0 deletions tribits/doc/build_ref/TribitsBuildReferenceBody.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1105,6 +1105,17 @@ To enable OpenMP support, one must set::
Note that if you enable OpenMP directly through a compiler option (e.g.,
``-fopenmp``), you will NOT enable OpenMP inside <Project> source code.

To skip adding flags for OpenMP for ``<LANG>`` = ``C``, ``CXX``, or
``Fortran``, use::

-D OpenMP_<LANG>_FLAGS_OVERRIDE=" "

The single space " " will result in no flags getting added. This is needed
since one can't set the flags ``OpenMP_<LANG>_FLAGS`` to an empty string or
the ``FIND_PACKAGE(OpenMP)`` command will fail. Setting the variable
``-DOpenMP_<LANG>_FLAGS_OVERRIDE= " "`` is the only way to enable OpenMP but
skip adding the OpenMP flags provided by ``FIND_PACKAGE(OpenMP)``.

.. _BUILD_SHARED_LIBS:

Building shared libraries
Expand Down

0 comments on commit b9d3531

Please sign in to comment.