Regardless which of the two target_compile_options lines above I choose, the target is compiled with OpenMP code generated. What is the correct way to turn OpenMP on and off.
[build] /usr/bin/ld: CMakeFiles/ocv.dir/grid.cpp.o: undefined reference to symbol 'omp_get_thread_num@@OMP_1.0'
[build] //usr/lib/x86_64-linux-gnu/libgomp.so.1: error adding symbols: DSO missing from command line
when used with -fopenmp. Works fine with -fno-openmp, but I would rather have a less drastic solution for switching between serial and parallel versions of the project. Is there a single compiler switch, or CMake variable, which can do the job?
I think using/not using OpenMP::OpenMP_CXX should be enough. It comes with the -fopenmp flag attached to its use already, so you shouldn’t need to do anything with the flag (additionally, its spelling can change based on the compiler in use; the target already accounts for that).
Thank you. It does work. I wonder though, if this will hold for more complicated OpenMP flags like device offload, e.g. –fopenmp-targets=nvptx64-nvidia-cuda. I will test it when I get to that stage.
Hmm. I don’t think so. It’s something that could be added to FindOpenMP though (either as a target or a function to make the flags based on other information). Please open an issue to track such an enhancement as openmp-targets currently doesn’t appear anywhere in CMake’s codebase.