MantisBT - CMake
View Issue Details
0014567CMakeModulespublic2013-11-13 12:482014-06-02 08:37
Daniel Landau 
Rolf Eike Beer 
lowtweakalways
closedfixed 
CMake 2.8.12 
CMake 3.0CMake 3.0 
0014567: FindOpenMP is incorrect for compilers that accept OpenMP with no flags
The CMake FindOpenMP.cmake module tries several flags in order to find out which one is supported by the compiler. The way it does it is seems to be by testing whether a compilation returns a successful exit status. The overall effect is that since "-openmp" is tested for before " ", the former gets chosen as the flag for OpenMP when the compiler doesn't require any.

The practical problem here is that the compiler that accepts "-openmp" without intending for it to signify OpenMP interpretes that as "-o penmp". This is not as big a problem as it first sounds, because CMake usually includes another -o flag later in the command line. In fact, I couldn't produce a small test case where this would lead to problems. It does lead to problems in the real word case of molecular dynamics software Gromacs (http://www.gromacs.org/ [^]), where some linking steps get generated with the order of first the intended -o flag and later -openmp.

A simple fix is to simply swap the order of testing for no flag (" ") and "-openmp".
Any simple CMakeLists.txt with OpenMP and a compiler that accepts OpenMP without flags (I used the Cray compiler) will produce compilation commands with -openmp, but I couldn't generate a small test case where that leads to explicit problems.
No tags attached.
patch 0001-FindOpenMP-fix-detecting-compilers-that-do-not-need-.patch (1,632) 2013-11-13 14:32
https://public.kitware.com/Bug/file/4949/0001-FindOpenMP-fix-detecting-compilers-that-do-not-need-.patch
Issue History
2013-11-13 12:48Daniel LandauNew Issue
2013-11-13 14:32Rolf Eike BeerFile Added: 0001-FindOpenMP-fix-detecting-compilers-that-do-not-need-.patch
2013-11-13 14:32Rolf Eike BeerNote Added: 0034447
2013-11-13 14:59Daniel LandauNote Added: 0034449
2013-11-13 15:44Rolf Eike BeerNote Added: 0034450
2013-11-13 15:44Rolf Eike BeerAssigned To => Rolf Eike Beer
2013-11-13 15:44Rolf Eike BeerStatusnew => resolved
2013-11-13 15:44Rolf Eike BeerResolutionopen => fixed
2013-11-13 15:44Rolf Eike BeerFixed in Version => CMake 3.0
2013-11-13 15:44Rolf Eike BeerTarget Version => CMake 3.0
2014-06-02 08:37Robert MaynardNote Added: 0036012
2014-06-02 08:37Robert MaynardStatusresolved => closed

Notes
(0034447)
Rolf Eike Beer   
2013-11-13 14:32   
Could you please try the attached patch.
(0034449)
Daniel Landau   
2013-11-13 14:59   
The patch as it stands fails. If I add a space between the quotes in both places it works.

Outputs with both versions:

no space:

-- Try OpenMP C flag = []
-- Performing Test OpenMP_FLAG_DETECTED
-- Performing Test OpenMP_FLAG_DETECTED - Success
-- Try OpenMP CXX flag = [-fopenmp]
-- Performing Test OpenMP_FLAG_DETECTED
-- Performing Test OpenMP_FLAG_DETECTED - Failed
-- Try OpenMP CXX flag = [/openmp]
-- Performing Test OpenMP_FLAG_DETECTED
-- Performing Test OpenMP_FLAG_DETECTED - Failed
-- Try OpenMP CXX flag = [-Qopenmp]
-- Performing Test OpenMP_FLAG_DETECTED
-- Performing Test OpenMP_FLAG_DETECTED - Failed
-- Try OpenMP CXX flag = [-openmp]
-- Performing Test OpenMP_FLAG_DETECTED
-- Performing Test OpenMP_FLAG_DETECTED - Success
-- Could NOT find OpenMP (missing: OpenMP_C_FLAGS)


space:

-- Try OpenMP C flag = [ ]
-- Performing Test OpenMP_FLAG_DETECTED
-- Performing Test OpenMP_FLAG_DETECTED - Success
-- Try OpenMP CXX flag = [ ]
-- Performing Test OpenMP_FLAG_DETECTED
-- Performing Test OpenMP_FLAG_DETECTED - Success
-- Found OpenMP:

I'm not terribly experienced with CMake, but is an empty string considered a false value?
(0034450)
Rolf Eike Beer   
2013-11-13 15:44   
Yes it is. I'm wondering why it hadn't worked for the C++ compiler in the first test. But anyway, thanks for testing.

Can you run a CMake dashboard using the cray compiler? We don't have any regular submissions using that compiler, so there could be other things going wrong.

Fix pushed to next: http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=ebf70b037ddc45941c3ad2152622fd7326517c1e [^]
(0036012)
Robert Maynard   
2014-06-02 08:37   
Closing resolved issues that have not been updated in more than 4 months.