# Proper way to use OpenMP: target\_link\_libraries() enough?

**URL:** https://discourse.cmake.org/t/proper-way-to-use-openmp-target-link-libraries-enough/9158
**Category:** Code
**Created:** [October 9, 2023, 4:24pm UTC](https://discourse.cmake.org/t/proper-way-to-use-openmp-target-link-libraries-enough/9158 "2023-10-09T16:24:20Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![retif](https://discourse.cmake.org/user_avatar/discourse.cmake.org/retif/32/1776_2.png) [@retif](https://discourse.cmake.org/u/retif)
#### Post date: [October 9, 2023, 7:21pm UTC](https://discourse.cmake.org/t/proper-way-to-use-openmp-target-link-libraries-enough/9158/2 "2023-10-09T19:21:51Z")

</div>

> How do the compiler flags get added

That happens in [FindOpenMP](https://gitlab.kitware.com/cmake/cmake/-/blob/master/Modules/FindOpenMP.cmake#L104) module, which is called when you execute `find_package(OpenMP)`.

> how could I figure out from the CMake docs that `target_link_libraries` is sufficient

Well, that’s a fair amount of docs that you would need to read to get to that understanding. In short, I’d say that this part of the documentation wouldn’t be specific to OpenMP, as this topic is rather common and applies to any library/package in general.

The `target_link_libraries()` is sufficient when the library files are already discovered, so you can provide them to this function as arguments, but obviously you first need to discover those files, and that is what `find_package()` does (_among other things, as you can see in that `FindOpenMP` module_). You can write your own discovery procedure which wouldn’t set `-fopenmp` flags, if that is what you are after. Alternatively, perhaps you could also overwrite those flags right after `find_package(OpenMP)` line.

---

_[View the full topic](https://discourse.cmake.org/t/proper-way-to-use-openmp-target-link-libraries-enough/9158)._
