title: Compile an OpenMP program with CMake on OS X
body: <p>I have a very simple openmp hello world program as this:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;omp.h&gt;
  
  int main()
  {
  #pragma omp parallel
      {
          int id = omp_get_thread_num();
          printf("hello, from %d.\n", id);
      }
      return 0;
  }
  </code></pre>
  
  <p>I can compile it in my terminal with <code>gcc-5 -fopenmp hello.c -o hello.o</code></p>
  
  <p>But I want to code in CLion, it uses CMake to organize project, when I just click the run button, I will got an error</p>
  
  <pre><code>fatal error: 'omp.h' file not found
  #include &lt;omp.h&gt;
  </code></pre>
  
  <p>I did search in google, and add something into my CMakeLists.txt file</p>
  
  <p>This is my CMakeLists.txt file:</p>
  
  <pre><code>cmake_minimum_required(VERSION 3.3)
  project(openmp)
  
  OPTION (USE_OpenMP "Use OpenMP" ON)
  IF(USE_OpenMP)
      FIND_PACKAGE(OpenMP)
  IF(OPENMP_FOUND)
      SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
      SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
  ENDIF()
  ENDIF()
  
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fopenmp")
  
  set(SOURCE_FILES hello.c omp.c)
  add_executable(openmp ${SOURCE_FILES})
  </code></pre>