Hi,

This is a first attempt to compile the library with msvc.
The changes are:
* ssize_t -> size_t
* vasprintf -> vsnprintf, malloc, sprintf
* removed unavailable headers
* added cmake file

To compile it, use cmake <source dir>. This will generate a visual studio solution file which you can open and build the project. In the cmake file I've added the option to make all symbols in the library public (or whatever the right term is), so it behaves like gcc. This avoids polluting the source code with DLL_EXPORT defines (__declspec(dllexport/dllimport)).

It's possible I missed some things which configure generates. I'll add those to CMakeLists.txt in the future.

Currently it only builds the library and not the tools. I'm hoping to add those later.

There's also a message in the source code "type_info::raw_name() demangling has not been tested yet with Microsoft compiler! Feedback appreciated!"

I'm working on lmms porting the code to msvc and to be honest I'm not that familiar with libgig, but if you let me know what triggers that code, I'll gladly try it out.
Index: CMakeLists.txt
===================================================================
--- CMakeLists.txt      (nonexistent)
+++ CMakeLists.txt      (working copy)
@@ -0,0 +1,33 @@
+cmake_minimum_required(VERSION 3.0)
+project(libgig)
+
+if(NOT MSVC)
+    message(FATAL_ERROR "Please use configure and make, this cmake file is 
only to generate msvc solution files")
+endif()
+
+set(VERSION_MAJOR 0)
+set(VERSION_MINOR 0)
+set(VERSION_RELEASE 0)
+
+set(PACKAGE_NAME "libgig")
+
+
+set(SOURCES 
+    src/Akai.cpp
+    src/DLS.cpp
+    src/gig.cpp
+    src/helper.cpp
+    src/Korg.cpp
+    src/RIFF.cpp
+    src/Serialization.cpp
+    src/SF.cpp
+    src/typeinfo.cpp
+    win32/dllmain.cpp)
+
+add_library(libgig SHARED ${SOURCES})
+target_compile_definitions(libgig PRIVATE NOMINMAX)
+
+target_compile_definitions(libgig PRIVATE PACKAGE="${PACKAGE_NAME}" 
VERSION="${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_RELEASE}")
+
+target_link_libraries(libgig Rpcrt4.lib)
+set_target_properties(libgig PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
Index: src/Akai.cpp
===================================================================
--- src/Akai.cpp        (revision 3457)
+++ src/Akai.cpp        (working copy)
@@ -24,7 +24,9 @@
 
 #include <stdio.h>
 #include <string.h>
-#include <unistd.h>
+#ifndef _MSC_VER
+# include <unistd.h>
+#endif
 #include <fcntl.h>
 #if defined(_CARBON_) || defined(__APPLE__)
 # if defined (__GNUC__) && (__GNUC__ >= 4)
Index: src/Akai.h
===================================================================
--- src/Akai.h  (revision 3457)
+++ src/Akai.h  (working copy)
@@ -43,8 +43,9 @@
 #include <fstream>
 #include <sys/types.h>
 #include <sys/stat.h>
+#ifndef _MSC_VER
 #include <sys/fcntl.h>
-
+#endif
 #if defined(_CARBON_) || defined(__APPLE__) || LINUX
 # include <sys/ioctl.h>
 # include <unistd.h>
Index: src/gig.cpp
===================================================================
--- src/gig.cpp (revision 3457)
+++ src/gig.cpp (working copy)
@@ -5246,7 +5246,7 @@
      */
     void Instrument::RemoveScript(Script* pScript) {
         LoadScripts();
-        for (ssize_t i = pScriptRefs->size() - 1; i >= 0; --i) {
+        for (size_t i = pScriptRefs->size() - 1; i >= 0; --i) {
             if ((*pScriptRefs)[i].script == pScript) {
                 pScriptRefs->erase( pScriptRefs->begin() + i );
             }
Index: src/helper.h
===================================================================
--- src/helper.h        (revision 3457)
+++ src/helper.h        (working copy)
@@ -30,9 +30,13 @@
 #include <algorithm>
 
 #if defined(WIN32) && !HAVE_CONFIG_H
+#if _MSC_VER
+//PACKAGE and VERSION are defined using the cmake file
+#else
 # include "../win32/libgig_private.h" // like config.h, automatically 
generated by Dev-C++
 # define PACKAGE "libgig"
 # define VERSION VER_STRING // VER_STRING defined in libgig_private.h
+#endif // _MSC_VER
 #endif // WIN32
 
 #if HAVE_CONFIG_H /*&& !HAVE_VASPRINTF*/ && defined(WIN32)
Index: src/Korg.cpp
===================================================================
--- src/Korg.cpp        (revision 3457)
+++ src/Korg.cpp        (working copy)
@@ -24,6 +24,7 @@
 #include "Korg.h"
 
 #include <string.h> // for memset()
+#include "helper.h"
 
 #if WORDS_BIGENDIAN
 # define CHUNK_ID_MSP1  0x4d535031
Index: src/RIFF.cpp
===================================================================
--- src/RIFF.cpp        (revision 3457)
+++ src/RIFF.cpp        (working copy)
@@ -2273,7 +2273,9 @@
 
     String Exception::assemble(String format, va_list arg) {
         char* buf = NULL;
-        vasprintf(&buf, format.c_str(), arg);
+        size_t needed = vsnprintf(buf, 0, format.c_str(), arg);
+        buf = (char*)malloc(needed+1);
+        sprintf(buf, format.c_str(), arg);
         String s = buf;
         free(buf);
         return s;
Index: src/RIFF.h
===================================================================
--- src/RIFF.h  (revision 3457)
+++ src/RIFF.h  (working copy)
@@ -54,7 +54,7 @@
 # include <unistd.h>
 #endif // POSIX
 
-#ifdef _MSC_VER
+#if _MSC_VER < 1600
 // Visual C++ 2008 doesn't have stdint.h
 typedef __int8 int8_t;
 typedef __int16 int16_t;
Index: src/Serialization.cpp
===================================================================
--- src/Serialization.cpp       (revision 3457)
+++ src/Serialization.cpp       (working copy)
@@ -31,8 +31,9 @@
 #include <assert.h>
 #include <string.h> // for memcpy()
 #include <stdlib.h> // for atof()
+#ifndef _MSC_VER
 #include <cxxabi.h>
-
+#endif
 #include "helper.h"
 
 #define LIBGIG_EPOCH_TIME ((time_t)0)
@@ -404,8 +405,14 @@
     String DataType::customTypeName(bool demangle) const {
         if (!demangle) return m_customTypeName;
         int status;
+#ifdef _MSC_VER
+#pragma message("name demangling for msvc not currently supported")
+        const char* result = m_customTypeName.c_str();
+#else
+
         const char* result =
             abi::__cxa_demangle(m_customTypeName.c_str(), 0, 0, &status);
+#endif
         return (status == 0) ? result : m_customTypeName;
     }
 
@@ -2320,7 +2327,9 @@
 
     String Exception::assemble(String format, va_list arg) {
         char* buf = NULL;
-        vasprintf(&buf, format.c_str(), arg);
+        size_t needed = vsnprintf(buf, 0, format.c_str(), arg);
+        buf = (char*)malloc(needed+1);
+        sprintf(buf, format.c_str(), arg);
         String s = buf;
         free(buf);
         return s;
Index: src/Serialization.h
===================================================================
--- src/Serialization.h (revision 3457)
+++ src/Serialization.h (working copy)
@@ -441,7 +441,7 @@
         template<typename T>
         static String rawCppTypeNameOf(const T& data) {
             #if defined _MSC_VER // Microsoft compiler ...
-            # warning type_info::raw_name() demangling has not been tested yet 
with Microsoft compiler! Feedback appreciated!
+            #pragma message("type_info::raw_name() demangling has not been 
tested yet with Microsoft compiler! Feedback appreciated!")
             String name = typeid(data).raw_name(); //NOTE: I haven't checked 
yet what MSC actually outputs here exactly
             #else // i.e. especially GCC and clang ...
             String name = typeid(data).name();
Index: src/SF.cpp
===================================================================
--- src/SF.cpp  (revision 3457)
+++ src/SF.cpp  (working copy)
@@ -728,7 +728,7 @@
 
     InstrumentBase::~InstrumentBase() {
         if (pGlobalRegion) delete pGlobalRegion;
-        for (ssize_t i = regions.size() - 1; i >= 0; i--) {
+        for (size_t i = regions.size() - 1; i >= 0; i--) {
             if (regions[i]) delete (regions[i]);
         }
     }
@@ -1152,13 +1152,13 @@
 
     File::~File() {
         delete pInfo;
-        for (ssize_t i = Presets.size() - 1; i >= 0; i--) {
+        for (size_t i = Presets.size() - 1; i >= 0; i--) {
             if (Presets[i]) delete (Presets[i]);
         }
-        for (ssize_t i = Instruments.size() - 1; i >= 0; i--) {
+        for (size_t i = Instruments.size() - 1; i >= 0; i--) {
             if (Instruments[i]) delete (Instruments[i]);
         }
-        for (ssize_t i = Samples.size() - 1; i >= 0; i--) {
+        for (size_t i = Samples.size() - 1; i >= 0; i--) {
             if (Samples[i]) delete (Samples[i]);
         }
     }
_______________________________________________
Linuxsampler-devel mailing list
Linuxsampler-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxsampler-devel

Reply via email to