Menu

#22 Add CMake script to ease native compilation on Windows

open
nobody
None
5
2014-05-18
2014-03-09
No

I needed to compile libmodplug natively with MSVC 2010 (both x86 and x64). Instead of reusing some hard-coded MSVC project I've found with google (from XBMC project) I've created a CMakeLists.txt script for CMake, so that a build configuration could be generated for any version of MSVC (or other compiler).

I hope you will find this useful

1 Attachments

Discussion

  • Konstanty

    Konstanty - 2014-03-10

    Thanks Pavel,

    As there were some other patches for windows support, I made some modifications - however I cannot guarantee that it all still works.

    Please pull the latest version and let me know what remaining patches may be required to have it working out of the box.

    Konstanty

     
    • Pavel Koshevoy

      Pavel Koshevoy - 2014-03-10

      Hi,

      I will have to alter the CMakeLists.txt to add preprocessor definitions for DLL_EXPORT, MODPLUG_STATIC, and MODPLUG_BUILD to match modplug.h changes.

      It appears stdafx.h now includes stdint.h, which is usually absent on windows systems. It would be more portable not to use POSIX types int32_t and int16_t, but stick to the more widely supported int and short int instead. As is, this code will not compile with MSVC versions prior to 2013 (and I don't have 2013 to test with). Usually, if a project insists on using stdint.h and inttypes.h they would bundle their own copy of those files for building on windows, or indicate where they can be acquired (http://code.google.com/p/msinttypes/)

      Also, I see that libmodplug.pc.in-for-cmake is absent. Is this unintentional?

      Thank you,
      Pavel.

       

      Last edit: Pavel Koshevoy 2014-03-10
    • Pavel Koshevoy

      Pavel Koshevoy - 2014-03-11

      Updated patch posted.

      Modified CMakeLists.txt to look for inttypes.h and stdint.h (available from http://msinttypes.googlecode.com/files/msinttypes-r26.zip). I tried using the latest version of msinttypes from svn trunk but it doesn't work with MSVC 2010 -- "stdint.h" tries to include <stdint.h> but the compiler includes the same file again and causes 1200+ errors.

      Modified load_abc.cpp to use std::vector<char> in two places where variable length arrays were used -- VLAs are not supported.

      Fixed compilation errors in sndfile.h -- multiple static class members were declared on one line, and the compiler did not like that.

      Fixed a linker error caused by undefined IMixPlugin destructor.

      Hope this helps,
      Pavel

       

      Last edit: Pavel Koshevoy 2014-03-11
  • Pavel Koshevoy

    Pavel Koshevoy - 2014-03-15

    Hi, could you please apply the second patch? CMakeLists.txt in master does not work because of the other changes you've merged, and MSVC 2010 compilation is also broken. The second patch fixes that, I don't see what could be holding it up.

     
  • Konstanty

    Konstanty - 2014-05-18

    Thank you for your patches - and sorry for the delay in getting to them. You and quiet a few others are wanting to make sure that this works in MS VC2010 (as do I).

    Your patches seem to combine many issues into one 'large patch'.

    I don't like the use of <vector> to replace the dynamic arrays. I've had another patch which I've now applied which should solve it for MSVC 2010 (use of 'new' and 'delete').</vector>

    Seems there is one remaining issue - the multiple static class members defined on one line. I find this a bit weird, as modplug originated as a Windows only piece of code, and was only ported to Linux later on...

     
    • Pavel Koshevoy

      Pavel Koshevoy - 2014-05-18

      new/delete are best used together with RAII pattern, to avoid memory leaks. I used std::vector precisely because it hides new/delete (std::vector implements the RAII pattern). Anyway, that's just my advice...

      Regarding multiple static class members -- I don't remember exactly what the problem was, it's been a while. However, I wouldn't have changed it unnecessarily.

      Let me know if/when you want me to try another msvc build.

       
    • Pavel Koshevoy

      Pavel Koshevoy - 2014-05-20

      With current master MSVC build fails with 379 errors, like the ones listed below. I have split static class data-member declarations into 1-per-line and the errors vanished. New patch attached.

      2>ClCompile:
      2>  fastmix.cpp
      2>S:/Developer/modplug-git-src/libmodplug/src/libmodplug\sndfile.h(542): error C2487: 'm_nXBassRange' : member of dll interface class may not be declared with dll interface
      2>S:/Developer/modplug-git-src/libmodplug/src/libmodplug\sndfile.h(543): error C2487: 'm_nReverbDelay' : member of dll interface class may not be declared with dll interface
      2>S:/Developer/modplug-git-src/libmodplug/src/libmodplug\sndfile.h(543): error C2487: 'gnReverbType' : member of dll interface class may not be declared with dll interface
      2>S:/Developer/modplug-git-src/libmodplug/src/libmodplug\sndfile.h(544): error C2487: 'm_nProLogicDelay' : member of dll interface class may not be declared with dll interface
      
       

Log in to post a comment.

MongoDB Logo MongoDB