MantisBT - CMake
View Issue Details
0013895CMakeDocumentationpublic2013-02-07 05:582013-07-01 09:37
Sylwester Arabas 
Rolf Eike Beer 
normalminorN/A
closedfixed 
CMake 2.8.10.2 
CMake 2.8.11CMake 2.8.11 
0013895: CMake docs: suggestion for impovement in OpenMP section
The CMake FindOpenMP docs say that "If the compiler supports OpenMP, the flags required to compile with openmp support are set." This might be misleading as these flags are not set for any targets, but instead some variables with these flags inside are made available to the user.

Furthermore, it might be worth to mention how to use these variables, e.g.:

if (OPENMP_FOUND)
  set_target_properties(... PROPERTIES LINK_FLAGS ${OpenMP_CXX_FLAGS})
  set_target_properties(... PROPERTIES COMPILE_FLAGS ${OpenMP_CXX_FLAGS})
endif()

HTH,
Sylwester
No tags attached.
Issue History
2013-02-07 05:58Sylwester ArabasNew Issue
2013-02-07 08:18Brad KingAssigned To => Rolf Eike Beer
2013-02-07 08:18Brad KingStatusnew => assigned
2013-02-07 09:11Sylwester ArabasNote Added: 0032209
2013-02-07 09:19Sylwester ArabasNote Added: 0032210
2013-02-07 14:56Rolf Eike BeerNote Added: 0032213
2013-02-07 16:06Sylwester ArabasNote Added: 0032215
2013-02-07 16:19Rolf Eike BeerNote Added: 0032216
2013-02-13 13:39Rolf Eike BeerNote Added: 0032265
2013-02-13 13:39Rolf Eike BeerStatusassigned => resolved
2013-02-13 13:39Rolf Eike BeerResolutionopen => fixed
2013-02-13 13:39Rolf Eike BeerFixed in Version => CMake 2.8.11
2013-02-13 13:39Rolf Eike BeerTarget Version => CMake 2.8.11
2013-02-14 09:13Julien FinetRelationship addedchild of 0013873
2013-02-14 10:48Julien FinetRelationship deletedchild of 0013873
2013-07-01 09:37Robert MaynardNote Added: 0033422
2013-07-01 09:37Robert MaynardStatusresolved => closed

Notes
(0032209)
Sylwester Arabas   
2013-02-07 09:11   
Apparently, this would be more correct?:

if(OPENMP_FOUND)
  get_target_property(flags ... LINK_FLAGS)
  set_target_properties(... PROPERTIES LINK_FLAGS "${flags} ${OpenMP_CXX_FLAGS}")
  get_target_property(flags ... COMPILE_FLAGS)
  set_target_properties(... PROPERTIES COMPILE_FLAGS "${flags} ${OpenMP_CXX_FLAGS}")
endif()
(0032210)
Sylwester Arabas   
2013-02-07 09:19   
And this would be even more correct probably (please confirm):

if(OPENMP_FOUND)
  get_target_property(flags ... LINK_FLAGS)
  if (${flags} STREQUAL "flags-NOTFOUND")
    set(flags "")
  endif()
  set_target_properties(... PROPERTIES LINK_FLAGS "${flags} ${OpenMP_CXX_FLAGS}")
  
  get_target_property(flags ... COMPILE_FLAGS)
  if (${flags} STREQUAL "flags-NOTFOUND")
    set(flags "")
  endif()
  set_target_properties(... PROPERTIES COMPILE_FLAGS "${flags} ${OpenMP_CXX_FLAGS}")
endif()

BTW, get_target_property() docs say that "If the property is not found, VAR will be set to "NOTFOUND".". Apparently the value is then "varname-NOTFOUND"?
(0032213)
Rolf Eike Beer   
2013-02-07 14:56   
I would change that sentence to:

"If the compiler supports OpenMP, the flags required to compile with OpenMP support are returned in variables for the different languages. The variables may be empty if the compiler does not need a special flag to support OpenMP."

I would not document there how to set these flags, this does belong in the common documentation and is nothing special to this module.
(0032215)
Sylwester Arabas   
2013-02-07 16:06   
Perhaps it's then worth mentioning at least that it's not only the compiler but also the linker that might need these flags. In case of GCC -fopenmp is needed at both stages as otherwise either _OPENMP is not defined or the libgomp library is not linked.

BTW, what about OpenMP_Fortran_FLAGS?

HTH,
Sylwester
(0032216)
Rolf Eike Beer   
2013-02-07 16:19   
If you add it to CMAKE_*_FLAGS* it will added to the linker flags automatically.

And once you come up with a test compile file for Fortran it will get added.
(0032265)
Rolf Eike Beer   
2013-02-13 13:39   
Fix merged to next:

http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=77fd5e51ab40865df240d52862baa7212443bdd9 [^]
(0033422)
Robert Maynard   
2013-07-01 09:37   
Closing resolved issues that have not been updated in more than 4 months.