[CMake] Statically link OpenMP on Mac gcc

Rob McDonald rob.a.mcdonald at gmail.com
Thu Apr 30 17:19:31 EDT 2015


I'm using MacPorts GCC 4.8 and CMake 3.2.

I use 'FIND_PACKAGE( OpenMP )', and then use OpenMP_C_FLAGS and
OpenMP_CXX_FLAGS appropriately.

My application works on the machine that I build on.  However, users
without MacPorts GCC installed can't find libgomp.1.dylib on their
machine.

I'd like to tell GCC to statically link libgomp.  I think the global
-static flag may do this, but it seems like a fairly brutish way of
getting the job done.

Is there a way to get CMake to tell GCC to statically link libgomp?
Or to have more fine grained control over which libraries are static
vs. dynamic?

Is there any reason to not want to use the global -static?

FindOpenMP.cmake isn't like most other Find*.cmake scripts -- instead
of searching for a *.h, *.a, *.so, or *.dylib file, it checks various
flags to the compiler -fopenmp, /openmp, etc.  From that, it
determines the appropriate flags, but there isn't any
${OPENMP_LIBRARIES} to use in a later TARGET_LINK_LIBRARIES later on.

Thanks,

Rob


More information about the CMake mailing list