Skip to content

[CORE][CMAKE] Fix Linux compilation of WWLib #698

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions Core/Libraries/Source/WWVegas/WWLib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ set(WWLIB_SRC
#md5.h
mempool.h
mmsys.h
mpu.cpp
MPU.H
multilist.cpp
multilist.h
mutex.cpp
Expand All @@ -91,8 +89,6 @@ set(WWLIB_SRC
RANDOM.H
rawfile.cpp
RAWFILE.H
rcfile.cpp
rcfile.h
readline.cpp
readline.h
realcrc.cpp
Expand All @@ -102,8 +98,6 @@ set(WWLIB_SRC
refcount.h
#regexpr.cpp
#regexpr.h
registry.cpp
registry.h
#search.h
sharebuf.h
Signaler.h
Expand Down Expand Up @@ -134,14 +128,10 @@ set(WWLIB_SRC
uarray.h
vector.cpp
Vector.H
verchk.cpp
verchk.h
visualc.h
widestring.cpp
widestring.h
win.h
WWCOMUtil.cpp
WWCOMUtil.h
wwfile.cpp
WWFILE.H
wwstring.cpp
Expand All @@ -152,6 +142,21 @@ set(WWLIB_SRC
XSTRAW.H
)

if(WIN32)
list(APPEND WWLIB_SRC
mpu.cpp
MPU.H
rcfile.cpp
rcfile.h
registry.cpp
registry.h
verchk.cpp
verchk.h
WWCOMUtil.cpp
WWCOMUtil.h
)
endif()

# Targets to build.
add_library(core_wwlib STATIC)
set_target_properties(core_wwlib PROPERTIES OUTPUT_NAME wwlib)
Expand Down
6 changes: 3 additions & 3 deletions Core/Libraries/Source/WWVegas/WWLib/CRC.H
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@
#define CRC_H

#include <stdlib.h>
#ifdef _UNIX
#include "osdep.h"
#endif

// TheSuperHackers @compile feliwir 17/04/2025 include _ltrotl macros
#include <Utility/intrin_compat.h>

/*
** This is a CRC engine class. It will process submitted data and generate a CRC from it.
Expand Down
2 changes: 1 addition & 1 deletion Core/Libraries/Source/WWVegas/WWLib/FastAllocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/

#include "FastAllocator.h"
#include <new.h>
#include <new>

static FastAllocatorGeneral* generalAllocator; //This general allocator will do all allocations for us.

Expand Down
2 changes: 1 addition & 1 deletion Core/Libraries/Source/WWVegas/WWLib/Vector.H
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <new.h>
#include <new>

#ifdef _MSC_VER
#pragma warning (disable : 4702) // unreachable code, happens with some uses of these templates
Expand Down
4 changes: 0 additions & 4 deletions Core/Libraries/Source/WWVegas/WWLib/WWFILE.H
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@
#ifndef WWFILE_Hx
#define WWFILE_Hx

#ifdef _UNIX
#include "osdep.h"
#endif

#define YEAR(dt) (((dt & 0xFE000000) >> (9 + 16)) + 1980)
#define MONTH(dt) ((dt & 0x01E00000) >> (5 + 16))
#define DAY(dt) ((dt & 0x001F0000) >> (0 + 16))
Expand Down
3 changes: 3 additions & 0 deletions Core/Libraries/Source/WWVegas/WWLib/always.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
#include <assert.h>
#include <new>

// TheSuperHackers @compile feliwir 17/04/2025 include utility macros for cross-platform compatibility
#include <Utility/compat.h>

// Disable warning about exception handling not being enabled. It's used as part of STL - in a part of STL we don't use.
#pragma warning(disable : 4530)

Expand Down
4 changes: 0 additions & 4 deletions Core/Libraries/Source/WWVegas/WWLib/argv.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@
#include "always.h"
#endif

#ifdef _UNIX
#include "osdep.h"
#endif

// Used to parse command line that is passed into WinMain.
// It also has the ability to load a file with values to append to the command line.
// Normally in WinMain() there would be a call Argv::Init(lpCmdLine, fileprefix).
Expand Down
23 changes: 15 additions & 8 deletions Core/Libraries/Source/WWVegas/WWLib/cpudetect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@
#include "wwdebug.h"
#include "thread.h"
#pragma warning (disable : 4201) // Nonstandard extension - nameless struct
#include <windows.h>
#include "systimer.h"
#include <Utility/intrin_compat.h>

#ifdef _WIN32
#include <windows.h>
#endif

#ifdef _UNIX
# include <time.h> // for time(), localtime() and timezone variable.
#endif
Expand Down Expand Up @@ -57,7 +60,7 @@ int CPUDetectClass::ProcessorFamily;
int CPUDetectClass::ProcessorModel;
int CPUDetectClass::ProcessorRevision;
int CPUDetectClass::ProcessorSpeed;
__int64 CPUDetectClass::ProcessorTicksPerSecond; // Ticks per second
sint64 CPUDetectClass::ProcessorTicksPerSecond; // Ticks per second
double CPUDetectClass::InvProcessorTicksPerSecond; // 1.0 / Ticks per second

unsigned CPUDetectClass::FeatureBits;
Expand Down Expand Up @@ -125,10 +128,10 @@ const char* CPUDetectClass::Get_Processor_Manufacturer_Name()

#define ASM_RDTSC _asm _emit 0x0f _asm _emit 0x31

static unsigned Calculate_Processor_Speed(__int64& ticks_per_second)
static unsigned Calculate_Processor_Speed(sint64& ticks_per_second)
{
unsigned __int64 timer0=0;
unsigned __int64 timer1=0;
sint64 timer0=0;
sint64 timer1=0;

timer0=_rdtsc();

Expand All @@ -138,8 +141,8 @@ static unsigned Calculate_Processor_Speed(__int64& ticks_per_second)
timer1=_rdtsc();
}

__int64 t=timer1-timer0;
ticks_per_second=(__int64)((1000.0/(double)elapsed)*(double)t); // Ticks per second
sint64 t=timer1-timer0;
ticks_per_second=(sint64)((1000.0/(double)elapsed)*(double)t); // Ticks per second
return unsigned((double)t/(double)(elapsed*1000));
}

Expand Down Expand Up @@ -898,8 +901,8 @@ void CPUDetectClass::Init_Memory()

void CPUDetectClass::Init_OS()
{
OSVERSIONINFO os;
#ifdef WIN32
OSVERSIONINFO os;
os.dwOSVersionInfoSize = sizeof(os);
GetVersionEx(&os);

Expand Down Expand Up @@ -940,9 +943,11 @@ void CPUDetectClass::Init_Processor_Log()

SYSLOG(("Operating System: "));
switch (OSVersionPlatformId) {
#ifdef _WIN32
case VER_PLATFORM_WIN32s: SYSLOG(("Windows 3.1")); break;
case VER_PLATFORM_WIN32_WINDOWS: SYSLOG(("Windows 9x")); break;
case VER_PLATFORM_WIN32_NT: SYSLOG(("Windows NT")); break;
#endif
}
SYSLOG(("\r\n"));

Expand Down Expand Up @@ -1223,6 +1228,7 @@ void Get_OS_Info(
switch (OSVersionPlatformId) {
default:
break;
#ifdef _WIN32
case VER_PLATFORM_WIN32_WINDOWS:
{
for(int i=0;i<sizeof(Windows9xVersionTable)/sizeof(os_info);++i) {
Expand Down Expand Up @@ -1304,5 +1310,6 @@ void Get_OS_Info(

// No more-specific version detected; fallback to XX
os_info.Code="WINXX";
#endif
}
}
3 changes: 0 additions & 3 deletions Core/Libraries/Source/WWVegas/WWLib/hash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@
#include "hash.h"
#include "wwdebug.h"
#include "realcrc.h"
#ifdef _UNIX
#include "osdep.h"
#endif

#include <string.h>

Expand Down
8 changes: 7 additions & 1 deletion Core/Libraries/Source/WWVegas/WWLib/mempool.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
#include "bittype.h"
#include "wwdebug.h"
#include "mutex.h"
#include <new.h>
#include <new>
#include <stdlib.h>
#include <stddef.h>

Expand Down Expand Up @@ -157,8 +157,14 @@ class AutoPoolClass
** Macro to declare the allocator for your class. Put this in the cpp file for
** the class.
*/
#if defined(_MSC_VER) && _MSC_VER < 1300
#define DEFINE_AUTO_POOL(T,BLOCKSIZE) \
ObjectPoolClass<T,BLOCKSIZE> AutoPoolClass<T,BLOCKSIZE>::Allocator;
#else
#define DEFINE_AUTO_POOL(T,BLOCKSIZE) \
template<>\
ObjectPoolClass<T,BLOCKSIZE> AutoPoolClass<T,BLOCKSIZE>::Allocator = {}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this separation really necessary? Cannot just add template<> for all compilers?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No template<> doesn't work when not using = {} as the initializer here. VC6 doesn't support that

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the compile error that this causes? Something about dependent name? It is odd that this requires a initializer because ObjectPoolClass does have a default constructor.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If i remember it was: missing implementation .....

#endif


/***********************************************************************************************
Expand Down
3 changes: 2 additions & 1 deletion Core/Libraries/Source/WWVegas/WWLib/mutex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@

#include "mutex.h"
#include "wwdebug.h"
#ifdef _WIN32
#include <windows.h>

#endif

// ----------------------------------------------------------------------------

Expand Down
7 changes: 4 additions & 3 deletions Core/Libraries/Source/WWVegas/WWLib/refcount.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@


#include "refcount.h"
#include <windows.h>

// TheSuperHackers @compile feliwir 17/04/2025 include __debugbreak macros
#include <Utility/intrin_compat.h>

#ifndef NDEBUG

Expand Down Expand Up @@ -174,7 +175,7 @@ void RefCountClass::Add_Ref(void) const

// See if programmer set break on for a specific address.
if (this == BreakOnReference) {
DebugBreak(); // trigger the debugger
__debugbreak(); // trigger the debugger
}
Inc_Total_Refs(this);
}
Expand All @@ -201,7 +202,7 @@ void RefCountClass::Dec_Total_Refs(const RefCountClass * obj)

// See if programmer set break on for a specific address.
if (obj == BreakOnReference) {
DebugBreak(); // trigger the debugger
__debugbreak(); // trigger the debugger
}
}

Expand Down
14 changes: 14 additions & 0 deletions Core/Libraries/Source/WWVegas/WWLib/systimer.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,25 @@
#ifndef _SYSTIMER_H

#include "always.h"
#ifdef _WIN32
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can add empty line before this.

#include <windows.h>
#include "mmsys.h"

#define TIMEGETTIME SystemTime.Get
#define MS_TIMER_SECOND 1000
#else
#include <sys/time.h>

inline unsigned long systimerGetMS(void)
{
struct timeval tv;
gettimeofday(&tv, NULL);
return (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
}

#define TIMEGETTIME systimerGetMS
#define MS_TIMER_SECOND 1000
#endif

/*
** Class that just wraps around timeGetTime()
Expand Down
6 changes: 4 additions & 2 deletions Core/Libraries/Source/WWVegas/WWLib/thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@
#include "thread.h"
#include "Except.h"
#include "wwdebug.h"
#include <process.h>
#include <windows.h>
#pragma warning ( push )
#pragma warning ( disable : 4201 )
#include "systimer.h"
#pragma warning ( pop )

#ifdef _WIN32
#include <process.h>
#include <windows.h>
#endif

ThreadClass::ThreadClass(const char *thread_name, ExceptionHandlerType exception_handler) : handle(0), running(false), thread_priority(0)
{
Expand Down
3 changes: 0 additions & 3 deletions Core/Libraries/Source/WWVegas/WWLib/thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@
#if defined(_MSC_VER)
#pragma once
#endif
#ifdef _UNIX
#include "osdep.h"
#endif

#include "always.h"
#include "Vector.H"
Expand Down
3 changes: 0 additions & 3 deletions Core/Libraries/Source/WWVegas/WWLib/widestring.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@
#include "wwstring.h"
#include "trim.h"
#include <wchar.h>
#ifdef _UNIX
#include "osdep.h"
#endif

//////////////////////////////////////////////////////////////////////
//
Expand Down
7 changes: 4 additions & 3 deletions Core/Libraries/Source/WWVegas/WWLib/win.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
** 4069, 4200, 4237, 4103, 4001, 4035, 4164. Makes you wonder, eh?
*/

#ifdef _WIN32

// When including windows, lets just bump the warning level back to 3...
#if (_MSC_VER >= 1200)
#pragma warning(push, 3)
Expand All @@ -69,7 +71,6 @@
#pragma warning(pop)
#endif

#ifdef _WINDOWS
extern HINSTANCE ProgramInstance;
extern HWND MainWindow;
extern bool GameInFocus;
Expand All @@ -84,8 +85,8 @@ void __cdecl Print_Win32Error(unsigned long win32Error);

#endif // _DEBUG

#else // _WINDOWS
#else // _WIN32
//#include <unistd.h> // file does not exist
#endif // _WINDOWS
#endif // _WIN32

#endif // WIN_H
3 changes: 3 additions & 0 deletions Core/Libraries/Source/WWVegas/WWLib/wwfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
#include <memory.h>
#include "WWFILE.H"

// TheSuperHackers @compile feliwir 17/04/2025 include _vsnprintf macros
#include <Utility/compat.h>

#pragma warning(disable : 4514)

int FileClass::Printf(char *str, ...)
Expand Down
Loading