CMAKE / msvc openmp, delay loading of openmp dll so we can set environment
authorMartijn Berger <martijn.berger@gmail.com>
Thu, 31 Mar 2016 11:45:33 +0000 (13:45 +0200)
committerMartijn Berger <martijn.berger@gmail.com>
Thu, 31 Mar 2016 11:46:14 +0000 (13:46 +0200)
variable before it is loaded

CMakeLists.txt
source/creator/creator.c

index 4a03e8fa86e3791aa626239cfb526a9320b573d2..99c0799659867cbc64ebefc7fed3c8b88a492188 100644 (file)
@@ -1308,6 +1308,17 @@ elseif(WIN32)
 
                set(PLATFORM_LINKFLAGS_DEBUG "/IGNORE:4099 /NODEFAULTLIB:libcmt.lib /NODEFAULTLIB:libc.lib")
 
+               # Use dynamic loading for OpenMP
+               if(WITH_OPENMP)
+                       if(MSVC_VERSION EQUAL 1800)
+                               set(OPENMP_DLL_NAME "vcomp120")
+                       else()
+                               set(OPENMP_DLL_NAME "vcomp140")
+                       endif()
+                       set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} /DELAYLOAD:${OPENMP_DLL_NAME}.dll delayimp.lib")
+                       set(PLATFORM_LINKFLAGS_DEBUG "${PLATFORM_LINKFLAGS_DEBUG} /DELAYLOAD::${OPENMP_DLL_NAME}d.dll delayimp.lib")
+               endif()
+
                if(NOT DEFINED LIBDIR)
 
                        # Setup 64bit and 64bit windows systems
index 2c2af7c199a64c1aea5dba0a0002326e67be7224..1010c9f06c812b441bb0b096df8cebbc931a85c7 100644 (file)
@@ -205,6 +205,11 @@ int main(
 
 
 #ifdef WIN32
+       /* We delay loading of openmp so we can set the policy here. */
+# if defined(_MSC_VER)
+       _putenv_s("OMP_WAIT_POLICY", "PASSIVE");
+# endif
+
        /* FMA3 support in the 2013 CRT is broken on Vista and Windows 7 RTM (fixed in SP1). Just disable it. */
 #  if defined(_MSC_VER) && defined(_M_X64)
        _set_FMA3_enable(0);