Skip to content

GitLab

  • Menu
Projects Groups Snippets
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • VTK VTK
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 738
    • Issues 738
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 202
    • Merge requests 202
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Monitor
    • Monitor
    • Incidents
  • Packages & Registries
    • Packages & Registries
    • Package Registry
    • Infrastructure Registry
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • VTK
  • VTKVTK
  • Issues
  • #17155

Closed
Open
Created Oct 24, 2017 by Johannes Asal@jasal

find_package(OpenMP) fails in C try_compile check when -Werror=return-type is set

In CMake v3.9 the FindOpenMP.cmake module saw some massive changes, including the test program used for detection of OpenMP support. Previous versions used

#include <omp.h>
int main() {
#ifdef _OPENMP
  return 0;
#else
  breaks_on_purpose
#endif
}

whereas CMake v3.9 and newer uses

#include <omp.h>
int main() {
#ifndef _OPENMP
  breaks_on_purpose
#endif
}

This should not make much of a difference unless you enable -Werror=return-type which is done in the OpenCV build for example. The C compiler will complain about the missing return statement whereas the CXX compiler does not care. This results in CMake reporting OpenMP_C to be missing.

The problem can be reproduced easily with this minimal CMakeLists.txt:

cmake_minimum_required(VERSION 3.9)
cmake_policy(SET CMP0012 NEW)
project(example)
#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror=return-type")
find_package(OpenMP)

Without the line setting the CMAKE_C_FLAGS you will get the following output:

-- Found OpenMP_C: -fopenmp (found version "3.1")
-- Found OpenMP_CXX: -fopenmp (found version "3.1")

With the line you get this:

-- Could NOT find OpenMP_C (missing: OpenMP_C_FLAGS OpenMP_C_LIB_NAMES) (found version "1.0")
-- Found OpenMP_CXX: -fopenmp (found version "3.1")
Assignee
Assign to
Time tracking