From 183b5f0e61ef576da0673ebfca46cea2876071e6 Mon Sep 17 00:00:00 2001 From: Hlodver Sigurdsson Date: Tue, 25 Jun 2019 13:55:50 -0700 Subject: [PATCH] Windows MSVC - fix winsock2 in MSVC build - seperate msvc flags from mingw in waf --- common/JackActivationCount.cpp | 2 +- common/JackAtomicArrayState.h | 3 +++ common/JackAtomicState.h | 3 +++ common/jack/jack.h | 4 ++++ common/jack/systemdeps.h | 6 +---- common/shm.c | 3 ++- common/wscript | 3 ++- windows/JackAtomic_os.h | 38 ++++--------------------------- windows/JackNetWinSocket.h | 2 +- windows/JackRouter/JackRouter.cpp | 3 +-- wscript | 13 +++++------ 11 files changed, 29 insertions(+), 51 deletions(-) diff --git a/common/JackActivationCount.cpp b/common/JackActivationCount.cpp index b7bde1f0..397d3278 100644 --- a/common/JackActivationCount.cpp +++ b/common/JackActivationCount.cpp @@ -16,7 +16,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - +#include "systemdeps.h" #include "JackAtomic.h" #include "JackActivationCount.h" #include "JackConstants.h" diff --git a/common/JackAtomicArrayState.h b/common/JackAtomicArrayState.h index a7fbc698..760bdf0c 100644 --- a/common/JackAtomicArrayState.h +++ b/common/JackAtomicArrayState.h @@ -21,6 +21,9 @@ #define __JackAtomicArrayState__ #include "JackAtomic.h" +#ifdef _MSC_VER +#include "JackAtomic_os.h" +#endif #include "JackCompilerDeps.h" #include // for memcpy diff --git a/common/JackAtomicState.h b/common/JackAtomicState.h index cfd3d5f4..8a2cee0c 100644 --- a/common/JackAtomicState.h +++ b/common/JackAtomicState.h @@ -21,6 +21,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define __JackAtomicState__ #include "JackAtomic.h" +#ifdef _MSC_VER +#include "JackAtomic_os.h" +#endif #include "JackCompilerDeps.h" #include // for memcpy diff --git a/common/jack/jack.h b/common/jack/jack.h index 7c8891da..5ad2d67f 100644 --- a/common/jack/jack.h +++ b/common/jack/jack.h @@ -1420,7 +1420,9 @@ jack_time_t jack_get_time(void) JACK_OPTIONAL_WEAK_EXPORT; * * @param msg error message text (no newline at end). */ + #ifndef _MSC_VER extern void (*jack_error_callback)(const char *msg) JACK_OPTIONAL_WEAK_EXPORT; +#endif /** * Set the @ref jack_error_callback for error message display. * Set it to NULL to restore default_jack_error_callback function. @@ -1438,7 +1440,9 @@ void jack_set_error_function (void (*func)(const char *)) JACK_OPTIONAL_WEAK_EXP * * @param msg info message text (no newline at end). */ + #ifndef _MSC_VER extern void (*jack_info_callback)(const char *msg) JACK_OPTIONAL_WEAK_EXPORT; +#endif /** * Set the @ref jack_info_callback for info message display. diff --git a/common/jack/systemdeps.h b/common/jack/systemdeps.h index 22fd5aab..7462e21c 100644 --- a/common/jack/systemdeps.h +++ b/common/jack/systemdeps.h @@ -61,11 +61,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. #if defined(_WIN32) && !defined(__CYGWIN__) && !defined(GNU_WIN32) #include - - #ifdef __MINGW32__ - # include // mingw gives warning if we include windows.h before winsock2.h - #endif - + #include #include #ifdef _MSC_VER /* Microsoft compiler */ diff --git a/common/shm.c b/common/shm.c index d5815311..c08e6d17 100644 --- a/common/shm.c +++ b/common/shm.c @@ -33,9 +33,10 @@ #include "JackConstants.h" #ifdef _WIN32 +#define _WINSOCKAPI_ +#include #include #include -#include #include #include #else diff --git a/common/wscript b/common/wscript index a6cb66af..22fb3fe5 100644 --- a/common/wscript +++ b/common/wscript @@ -29,7 +29,8 @@ def create_jack_process_obj(bld, target, sources, uselib = None, framework = Non if bld.env['IS_SUN']: env_includes = ['../solaris', '../posix', '../solaris/oss'] if bld.env['IS_WINDOWS']: - driver.env.append_unique('LDFLAGS', ['/DLL', "common\\build"]) + if conf.env['CC_NAME'] == 'msvc': + driver.env.append_unique('LDFLAGS', ['/DLL', "common\\build", '/MT']) env_includes = ['../windows', '../windows/portaudio'] process.includes = ['.'] + env_includes + ['jack', '..'] process.name = target diff --git a/windows/JackAtomic_os.h b/windows/JackAtomic_os.h index dc3ca0d1..9b5eac7a 100644 --- a/windows/JackAtomic_os.h +++ b/windows/JackAtomic_os.h @@ -22,8 +22,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "JackTypes.h" -#ifndef __MINGW32__ +#ifdef _MSC_VER #define COMPARE_EXCHANGE(ADDRESS, NEW, EXPECTED) atomic::msvc::interlocked::compare_exchange(ADDRESS, NEW, EXPECTED) +#endif + +#ifdef __MINGW32__ #ifdef __SMP__ # define LOCK lock #else @@ -37,37 +40,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. //---------------------------------------------------------------- // CAS functions //---------------------------------------------------------------- -#if defined(_M_X64) - -#include - -bool CAS(volatile UInt32 value, UInt32 newvalue, volatile void * addr) -{ - return std::atomic_compare_exchange_weak((std::_Atomic_address *) addr, value, newvalue); -} - -#else - -inline char CAS(volatile UInt32 value, UInt32 newvalue, volatile void * addr) -{ - register char c; - __asm { - push ebx - push esi - mov esi, addr - mov eax, value - mov ebx, newvalue - LOCK cmpxchg dword ptr [esi], ebx - sete c - pop esi - pop ebx - } - return c; -} - -#endif - -#else #define LOCK "lock ; " @@ -84,6 +56,6 @@ static inline char CAS(volatile UInt32 value, UInt32 newvalue, volatile void* ad return ret; } -#endif +#endif // __MINGW32__ #endif diff --git a/windows/JackNetWinSocket.h b/windows/JackNetWinSocket.h index 8a69c332..4e392fd9 100644 --- a/windows/JackNetWinSocket.h +++ b/windows/JackNetWinSocket.h @@ -22,8 +22,8 @@ #include "JackNetSocket.h" #include -#ifdef __MINGW32__ #include +#ifdef __MINGW32__ #include #endif diff --git a/windows/JackRouter/JackRouter.cpp b/windows/JackRouter/JackRouter.cpp index 28d86dc4..0513efb6 100644 --- a/windows/JackRouter/JackRouter.cpp +++ b/windows/JackRouter/JackRouter.cpp @@ -56,8 +56,7 @@ static const double twoRaisedTo32Reciprocal = 1. / twoRaisedTo32; //------------------------------------------------------------------------------------------ // on windows, we do the COM stuff. -#if WINDOWS -#include "windows.h" +#if _WIN32 #include "mmsystem.h" #ifdef _WIN64 #define JACK_ROUTER "JackRouter.dll" diff --git a/wscript b/wscript index 51c08fd5..2fa9c9c4 100644 --- a/wscript +++ b/wscript @@ -116,10 +116,6 @@ def options(opt): help='Enable Portaudio driver', conf_dest='BUILD_DRIVER_PORTAUDIO') portaudio.check(header_name='windows.h') # only build portaudio on windows - # portaudio.check_cfg( - # package='portaudio-2.0 >= 19', - # uselib_store='PORTAUDIO', - # args='--cflags --libs') winmme = opt.add_auto_option( 'winmme', help='Enable WinMME driver', @@ -209,12 +205,15 @@ def configure(conf): detect_platform(conf) if conf.env['IS_WINDOWS']: - conf.env.append_unique('CCDEFINES', '_POSIX') - conf.env.append_unique('CXXDEFINES', '_POSIX') if conf.env['CC_NAME'] == 'msvc': + conf.env.append_unique('CXXFLAGS', '/MT') # static linking conf.env.append_unique('CXXFLAGS', '/std:c++14') conf.env.append_unique('CXXFLAGS', '/EHsc') + conf.env.append_unique('CXXFLAGS', '/D_WINSOCKAPI_=1') # https://stackoverflow.com/a/1517198 conf.env.append_unique('LIBPATH', os.getcwd() + '\\windows\\lib') + else: + conf.env.append_unique('CCDEFINES', '_POSIX') + conf.env.append_unique('CXXDEFINES', '_POSIX') else: conf.env.append_unique('CXXFLAGS', '-Wall') conf.env.append_unique('CXXFLAGS', '-std=gnu++11') @@ -733,7 +732,7 @@ def build_drivers(bld): target = 'portaudio', source = portaudio_src, use = ['PORTAUDIO'], - win_dll = ['common\\jackserver.lib', '..\\libportaudio64.lib']) + win_dll = ['common\\jackserver.lib', os.getenv('PORTAUDIO_LIBRARY') or 'libportaudio64.lib']) if bld.env['BUILD_DRIVER_WINMME']: create_driver_obj(