[babl/wip/msvc: 1/4] meson.build: Fix lcms2 detection for MSVC builds



commit 61bdb241d27743979ecfd3439672c9db10537612
Author: Chun-wei Fan <fanchunwei src gnome org>
Date:   Fri Jan 17 15:19:54 2020 +0800

    meson.build: Fix lcms2 detection for MSVC builds
    
    The build files for lcms2 do not normally generate pkg-config files for us, so
    we need to look for it manually if they cannot be found.  Also, at least for
    32-bit builds, we need to check whether the found lcms2 .lib is really a DLL
    build or a static .lib build, otherwise linking will fail for DLL lcms2 builds
    if we do not define CMS_DLL for our builds, at least for 32-bit builds.

 meson.build | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)
---
diff --git a/meson.build b/meson.build
index be9779c8b..9a9f72006 100644
--- a/meson.build
+++ b/meson.build
@@ -305,7 +305,29 @@ endif
 
 # LCMS
 if get_option('with-lcms')
-  lcms = dependency('lcms2', required: true, native: false)
+  lcms = dependency('lcms2', required: cc.get_id() != 'msvc', native: false)
+  if cc.get_id() == 'msvc'
+    if not lcms.found()
+      lcms = cc.find_library('lcms2', has_headers: 'lcms2.h', required: true)
+    endif
+
+    # MSVC builds: We must check whether the lcms2 library is a static or DLL build,
+    # at least for 32-bit builds, otherwise the code will fail to link.
+    lcms_dll_test = '''
+      #define CMS_DLL
+      #include <lcms2.h>
+
+      int main(int argc, char* argv[])
+        {
+          cmsGetEncodedCMMversion();
+          return 0;
+        }
+    '''
+
+    if cc.links(lcms_dll_test, dependencies: lcms, name: 'lcms_dll_check')
+      add_project_arguments('-DCMS_DLL', language: 'c')
+    endif
+  endif
   if lcms.found()
     conf.set('HAVE_LCMS', 1, description:
       'Define to 1 if liblcms2 is available')


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]