On 15/02/2019 16:00, justnope wrote:
On 15/02/2019 15:15, Christian Schoenebeck wrote:
I suggest that I commit your msvc patch first, and then sure, if you like to adapt the cmakes for other architectures, very much appreciated of course!

So your previous patch sent to the list is the latest one, or should I wait
for an updated patch from your side?
um... wait for a bit?
I tried to integrate it in vcpkg and noticed some problems. I know, I should've done this earlier!

This is the final version. I did several tests and they all seem to work.

If you remove the MSVC check in CMakeLists.txt it will also compile the library and some tools in linux.
diff --git CMakeLists.txt CMakeLists.txt
new file mode 100644
index 0000000..9d5b036
--- /dev/null
+++ CMakeLists.txt
@@ -0,0 +1,139 @@
+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()
+
+
+#configuration options
+set(LIBGIG_BUILD_TOOLS ON CACHE BOOL "Build the extra tools")
+set(LIBGIG_ENABLE_TESTING ON CACHE BOOL "Build the test cases")
+set(LIBGIG_BUILD_SHARED ${BUILD_SHARED_LIBS} CACHE BOOL "build dynamic 
libraries")
+
+set(BUILD_SHARED_LIBS ${LIBGIG_BUILD_SHARED})
+
+if(LIBGIG_ENABLE_TESTING)
+       enable_testing()
+endif()
+
+set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
+set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
+set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
+
+#TODO: this is written for vcpkg cppunit install
+#if you're adding other platform and package managers it's probably better to 
put everything in FindCppUnit.cmake
+#and replace everything here with a simple find_package(CppUnit)
+if(WIN32)
+       find_path(CPPUNIT_INCLUDE_DIRS cppunit/TestFixture.h)
+       find_library(CPPUNIT_LIBRARIES_DEBUG cppunitd_dll)
+       find_library(CPPUNIT_LIBRARIES_RELEASE cppunit_dll)
+       mark_as_advanced(CPPUNIT_INCLUDE_DIRS CPPUNIT_LIBRARIES_DEBUG 
CPPUNIT_LIBRARIES_RELEASE)
+
+       if(CPPUNIT_LIBRARIES_DEBUG AND CPPUNIT_LIBRARIES_RELEASE AND 
CPPUNIT_INCLUDE_DIRS)
+               set(CPPUNIT_FOUND TRUE)
+               set(CPPUNIT_LIBRARIES
+               $<$<CONFIG:Debug>:${CPPUNIT_LIBRARIES_DEBUG}>
+               $<$<CONFIG:RelWithDebInfo>:${CPPUNIT_LIBRARIES_RELEASE}>
+               $<$<CONFIG:Release>:${CPPUNIT_LIBRARIES_RELEASE}>
+               $<$<CONFIG:MinSizeRel>:${CPPUNIT_LIBRARIES_RELEASE}>)
+       else()
+               message("cppunit not found. Testcases will not be built.")
+       endif()
+endif(WIN32)
+
+if(LIBGIG_BUILD_TOOLS)
+       find_package(LibSndFile)
+endif()
+
+#get version from configure.ac
+#have to make a slight detour since I cannot get the cmake regex subgroup to 
work with file
+file(STRINGS configure.ac VERSION_STRINGS REGEX 
"^m4_define\\(libgig_release.*\\)$")
+
+string(REGEX MATCH "libgig_release_major, ([^)]*)\\)" TEMP ${VERSION_STRINGS})
+set(VERSION_MAJOR ${CMAKE_MATCH_1})
+string(REGEX MATCH "libgig_release_minor, ([^)]*)\\)" TEMP ${VERSION_STRINGS})
+set(VERSION_MINOR ${CMAKE_MATCH_1})
+string(REGEX MATCH "libgig_release_build, ([^)]*)\\)" TEMP ${VERSION_STRINGS})
+set(VERSION_BUILD ${CMAKE_MATCH_1})
+
+set(PACKAGE_NAME "libgig")
+
+set(LIBGIG_HEADERS
+       src/DLS.h
+       src/gig.h
+       src/RIFF.h
+       src/SF.h
+       src/Korg.h
+       src/Serialization.h)
+
+#libgig core library
+add_library(libgig
+       src/DLS.cpp
+       src/gig.cpp
+       src/helper.cpp
+       src/Korg.cpp
+       src/RIFF.cpp
+       src/Serialization.cpp
+       src/SF.cpp
+       src/typeinfo.cpp)
+if(WIN32)
+       target_sources(libgig PRIVATE win32/dllmain.cpp)
+endif()
+
+set_target_properties(libgig PROPERTIES PUBLIC_HEADER "${LIBGIG_HEADERS}")
+target_compile_definitions(libgig PRIVATE PACKAGE="${PACKAGE_NAME}" 
VERSION="${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_BUILD}")
+target_include_directories(libgig PUBLIC $<INSTALL_INTERFACE:include>)
+if(MSVC)
+       target_compile_definitions(libgig PRIVATE NOMINMAX)
+endif()
+if(WIN32)
+       target_link_libraries(libgig Rpcrt4.lib dbghelp.lib)
+endif()
+if(BUILD_SHARED_LIBS AND MSVC)
+       set_target_properties(libgig PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
+endif()
+
+#libakai library
+add_library(libakai src/Akai.cpp)
+if(WIN32)
+       target_sources(libakai PRIVATE win32/dllmain.cpp)
+endif()
+set_target_properties(libakai PROPERTIES PUBLIC_HEADER src/Akai.h)
+target_include_directories(libakai PUBLIC $<INSTALL_INTERFACE:include>)
+target_compile_definitions(libakai PRIVATE PACKAGE="${PACKAGE_NAME}" 
VERSION="${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_BUILD}")
+
+if(MSVC)
+       target_compile_definitions(libakai PRIVATE NOMINMAX)
+endif()
+if(BUILD_SHARED_LIBS AND MSVC)
+       set_target_properties(libakai PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS 
TRUE)
+endif()
+if(WIN32)
+       target_link_libraries(libakai Rpcrt4.lib )
+endif()
+
+if(CPPUNIT_FOUND AND LIBGIG_ENABLE_TESTING)
+       add_subdirectory(src/testcases)
+endif()
+
+if(LIBGIG_BUILD_TOOLS)
+       add_subdirectory(src/tools)
+endif(LIBGIG_BUILD_TOOLS)
+
+#installation
+#It also creates a *-config.cmake files so other cmake users can include it 
more easily into their projects
+install(TARGETS libgig EXPORT libgig-config
+       LIBRARY DESTINATION lib
+       ARCHIVE DESTINATION lib
+       RUNTIME DESTINATION bin
+       PUBLIC_HEADER DESTINATION include/libgig)
+install(EXPORT libgig-config NAMESPACE libgig:: DESTINATION share/libgig)
+
+install(TARGETS libakai EXPORT libakai-config
+       LIBRARY DESTINATION lib
+       ARCHIVE DESTINATION lib
+       RUNTIME DESTINATION bin
+       PUBLIC_HEADER DESTINATION include/libgig)
+install(EXPORT libakai-config NAMESPACE libgig:: DESTINATION share/libgig)
+
diff --git README README
index 433c35e..fb37e25 100644
--- README
+++ README
@@ -149,8 +149,30 @@ Compiling for Linux
   On success, the resulting rpm(s) can usually be found under the proper
   "/usr/src/<rpmdir>/RPMS/<arch>" directory.
 
-Compiling for Windows
-=====================
+Compiling for Windows using CMake
+=================================
+The easiest way is to compile is to use vcpkg 
(https://github.com/Microsoft/vcpkg)
+to install libsndfile (required) and cppunit (optional). In the vcpkg install 
dir
+type:
+.\vcpkg.exe install libsndfile cppunit [--triplet x64-windows]
+
+This should install the libraries in vcpkg, add the triplet option if you wish 
to
+get the 64bit libraries.
+
+In an empty directory type:
+cmake <libgig source dir> -DCMAKE_TOOLCHAIN_FILE=<vcpkg 
dir>\scripts\buildsystems\vcpkg.cmake
+[-G"Visual Studio 15 2017 Win64"]
+
+Use the -G option to select the visual studio version and whether to compile 
for
+64bits.
+
+This will create libgig.sln file which you can open in visual studio or you 
can use
+the following command line to compile:
+
+cmake --build . --config <Release|Debug|MinRelSize|RelWithDebInfo>
+
+Compiling for Windows using Dev-C++
+===================================
 
   libgig and its tools can be compiled for Windows using Bloodshed Dev-C++,
   which is a free (GPL) C++ integrated development environment for Windows.
diff --git src/Akai.cpp src/Akai.cpp
index fc4558d..3f4ae7d 100755
--- src/Akai.cpp
+++ src/Akai.cpp
@@ -24,8 +24,10 @@
 
 #include <stdio.h>
 #include <string.h>
+#ifndef _MSC_VER
 #include <unistd.h>
 #include <fcntl.h>
+#endif
 #if defined(_CARBON_) || defined(__APPLE__)
 # if defined (__GNUC__) && (__GNUC__ >= 4)
 #  include <sys/disk.h>
diff --git src/Akai.h src/Akai.h
index 759648f..6815029 100755
--- src/Akai.h
+++ src/Akai.h
@@ -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>
diff --git src/RIFF.h src/RIFF.h
index a740921..b68004d 100644
--- src/RIFF.h
+++ src/RIFF.h
@@ -54,7 +54,7 @@
 # include <unistd.h>
 #endif // POSIX
 
-#ifdef _MSC_VER
+#if defined _MSC_VER && _MSC_VER < 1600
 // Visual C++ 2008 doesn't have stdint.h
 typedef __int8 int8_t;
 typedef __int16 int16_t;
diff --git src/Serialization.cpp src/Serialization.cpp
index a46b184..e2f3f8f 100644
--- src/Serialization.cpp
+++ src/Serialization.cpp
@@ -31,8 +31,12 @@
 #include <assert.h>
 #include <string.h> // for memcpy()
 #include <stdlib.h> // for atof()
+#ifdef _MSC_VER
+#include <windows.h>
+#include <dbghelp.h>
+#else
 #include <cxxabi.h>
-
+#endif
 #include "helper.h"
 
 #define LIBGIG_EPOCH_TIME ((time_t)0)
@@ -403,12 +407,25 @@ namespace Serialization {
      */
     String DataType::customTypeName(bool demangle) const {
         if (!demangle) return m_customTypeName;
+#ifdef _MSC_VER
+        const size_t MAXLENGTH = 1024;
+        char result[MAXLENGTH];
+
+        //Skip the first char
+        size_t size = UnDecorateSymbolName(m_customTypeName.c_str() +1, 
result, MAXLENGTH, UNDNAME_32_BIT_DECODE | UNDNAME_NO_ARGUMENTS);
+        if (size)
+        {
+            return result;
+        }
+        return m_customTypeName;
+#else
         int status;
         char* result =
             abi::__cxa_demangle(m_customTypeName.c_str(), 0, 0, &status);
         String sResult = result;
         free(result);
         return (status == 0) ? sResult : m_customTypeName;
+#endif
     }
 
     // *************** Member ***************
diff --git src/Serialization.h src/Serialization.h
index f96df0e..98af4ac 100644
--- src/Serialization.h
+++ src/Serialization.h
@@ -441,8 +441,7 @@ namespace Serialization {
         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!
-            String name = typeid(data).raw_name(); //NOTE: I haven't checked 
yet what MSC actually outputs here exactly
+            String name = typeid(data).raw_name();
             #else // i.e. especially GCC and clang ...
             String name = typeid(data).name();
             #endif
diff --git src/helper.h src/helper.h
index 65a481e..8777ac1 100644
--- src/helper.h
+++ src/helper.h
@@ -29,17 +29,26 @@
 #include <sstream>
 #include <algorithm>
 
-#if defined(WIN32) && !HAVE_CONFIG_H
+#if defined(WIN32) && !HAVE_CONFIG_H && !defined(_MSC_VER)
 # 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 // WIN32
 
-#if HAVE_CONFIG_H /*&& !HAVE_VASPRINTF*/ && defined(WIN32)
+#if (HAVE_CONFIG_H /*&& !HAVE_VASPRINTF*/ && defined(WIN32)) || 
defined(_MSC_VER)
 # include <stdarg.h>
 int vasprintf(char** ret, const char* format, va_list arg);
 #endif
 
+#if defined(_MSC_VER)
+#if _MSC_VER < 1900
+#error versions prior to msvc 2015 have not been tested
+#else
+#include <BaseTsd.h>
+typedef SSIZE_T ssize_t;
+#endif
+#endif
+
 #include "RIFF.h"
 
 // *************** Helper Functions **************
diff --git src/testcases/CMakeLists.txt src/testcases/CMakeLists.txt
new file mode 100644
index 0000000..b08fdb1
--- /dev/null
+++ src/testcases/CMakeLists.txt
@@ -0,0 +1,5 @@
+
+add_executable(gigwritetest main.cpp GigWriteTest.cpp)
+target_link_libraries(gigwritetest PRIVATE libgig ${CPPUNIT_LIBRARIES})
+target_include_directories(gigwritetest PRIVATE ${CPPUNIT_INCLUDE_DIRS})
+add_test(NAME gigwritetest COMMAND gigwritetest)
diff --git src/testcases/GigWriteTest.cpp src/testcases/GigWriteTest.cpp
index 2ca5c87..97f5da0 100644
--- src/testcases/GigWriteTest.cpp
+++ src/testcases/GigWriteTest.cpp
@@ -207,7 +207,9 @@ void GigWriteTest::testArticulationsOfCreatedGigFile() {
             CPPUNIT_ASSERT(pRegion->VelocityRange.low  == iInstrument - 1);
             CPPUNIT_ASSERT(pRegion->VelocityRange.high == iInstrument);
             CPPUNIT_ASSERT(pRegion->KeyGroup  == iInstrument - 1);
-            gig::DimensionRegion* pDimensionRegion = 
pRegion->GetDimensionRegionByValue((uint[8]){0,0,0,0,0,0,0,0});
+            //gig::DimensionRegion* pDimensionRegion = 
pRegion->GetDimensionRegionByValue((uint[8]){0,0,0,0,0,0,0,0});
+            const uint dimensionRegion[] = { 0, 0, 0, 0, 0, 0, 0, 0 };
+            gig::DimensionRegion* pDimensionRegion = 
pRegion->GetDimensionRegionByValue(dimensionRegion);
             CPPUNIT_ASSERT(pDimensionRegion);
             CPPUNIT_ASSERT(pDimensionRegion->pSample->pInfo->Name == 
sOughtToBe);
             iInstrument++;
diff --git src/tools/CMakeLists.txt src/tools/CMakeLists.txt
new file mode 100644
index 0000000..30bdd31
--- /dev/null
+++ src/tools/CMakeLists.txt
@@ -0,0 +1,38 @@
+
+macro(add_tool NAME)
+    add_executable(${NAME} ${NAME}.cpp)
+    target_link_libraries(${NAME} PRIVATE libgig)
+endmacro(add_tool)
+
+add_executable(akaidump akaidump.cpp)
+target_link_libraries(akaidump PRIVATE libakai)
+
+if(NOT LibSndFile_FOUND)
+       message(WARNING "sndfile library not found: akaiextract, gigextract and 
sf2extract will not be built")
+endif()
+#These tools are not yet ported to msvc
+if(NOT MSVC)
+       if(LibSndFile_FOUND)
+               add_executable(akaiextract akaiextract.cpp)
+               target_link_libraries(akaiextract PRIVATE libakai)
+       endif()
+       add_tool(gig2mono)
+       add_tool(gig2stereo)
+else()
+       message(WARNING "akaiextract, gig2mono and gig2stereo aren't yet ported 
to msvc")
+endif()
+
+if(LibSndFile_FOUND)
+       add_tool(gigextract)
+       target_link_libraries(gigextract PRIVATE sndfile-shared)
+       add_tool(sf2extract)
+       target_link_libraries(sf2extract PRIVATE sndfile-shared)
+endif()
+
+add_tool(dlsdump)
+add_tool(gigdump)
+add_tool(gigmerge)
+add_tool(korg2gig)
+add_tool(korgdump)
+add_tool(rifftree)
+add_tool(sf2dump)
_______________________________________________
Linuxsampler-devel mailing list
Linuxsampler-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxsampler-devel

Reply via email to