From 669c6149fa46c72e521905c8a4e23f4fad8a8719 Mon Sep 17 00:00:00 2001 From: Ralph Sennhauser Date: Sun, 18 Aug 2024 12:58:21 +0200 Subject: [PATCH] Drop use of LINUX define Instead of defining LINUX on many platforms just use the standard platform macros. As there is no "config.h" (yet) this also prevents consumers from having to define it. Signed-off-by: Ralph Sennhauser --- CMakeLists.txt | 2 -- FCollada/DLLEntry.cpp | 2 +- FCollada/FCDocument/FCDEffectStandard.h | 6 +--- FCollada/FCDocument/FCDEffectTools.h | 6 +--- FCollada/FCDocument/FCDTexture.h | 6 +--- FCollada/FCDocument/FCDocument.h | 9 ++---- FCollada/FMath/FMFloat.h | 2 -- FCollada/FUtils/FUDebug.cpp | 10 +++---- FCollada/FUtils/FUFileManager.cpp | 24 ++++++++-------- FCollada/FUtils/FUPluginManager.cpp | 6 ++-- FCollada/FUtils/FUPluginManager.h | 2 +- FCollada/FUtils/Platforms.h | 28 ++++++++----------- FColladaTools/FCExport/FCExport.cpp | 4 +-- .../FCProcessImages/FCProcessImages.cpp | 4 +-- .../FCProcessMeshes/FCProcessMeshes.cpp | 4 +-- 15 files changed, 45 insertions(+), 70 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index da5821c..7a4bab7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,8 +38,6 @@ endif() if(WIN32) add_definitions(-DWIN32) -elseif(NOT APPLE) - add_definitions(-DLINUX) endif() if(BUILD_UNICODE) diff --git a/FCollada/DLLEntry.cpp b/FCollada/DLLEntry.cpp index 59477c2..b4b41f4 100644 --- a/FCollada/DLLEntry.cpp +++ b/FCollada/DLLEntry.cpp @@ -43,7 +43,7 @@ BOOL WINAPI DllMain(HINSTANCE _hInstance, ULONG fdwReason, LPVOID UNUSED(lpvRese hInstance = _hInstance; return TRUE; } -#elif defined(__APPLE__) || defined(LINUX) +#else void __attribute((constructor)) DllEntry(void) { } diff --git a/FCollada/FCDocument/FCDEffectStandard.h b/FCollada/FCDocument/FCDEffectStandard.h index 9ddae55..222ac61 100644 --- a/FCollada/FCDocument/FCDEffectStandard.h +++ b/FCollada/FCDocument/FCDEffectStandard.h @@ -35,11 +35,7 @@ class FCDEffect; class FCDTexture; class FCDEffectParameter; -#if defined(WIN32) -template class FCOLLADA_EXPORT FCDEffectParameterAnimatableT; /**< Trick Doxygen. */ -#elif defined(LINUX) || defined(__APPLE__) -template class FCDEffectParameterAnimatableT; /**< Trick Doxygen. */ -#endif // LINUX +template class FCOLLADA_EXPORT FCDEffectParameterAnimatableT; typedef FCDEffectParameterAnimatableT FCDEffectParameterColor4; /**< A RGBA color effect parameter. */ typedef FCDEffectParameterAnimatableT FCDEffectParameterFloat; /**< A floating-point value effect parameter. */ diff --git a/FCollada/FCDocument/FCDEffectTools.h b/FCollada/FCDocument/FCDEffectTools.h index 757ed6d..e4eaa11 100644 --- a/FCollada/FCDocument/FCDEffectTools.h +++ b/FCollada/FCDocument/FCDEffectTools.h @@ -31,11 +31,7 @@ class FCDEffectStandard; class FCDEffectTechnique; class FCDGeometryInstance; -#if defined(WIN32) -template class FCOLLADA_EXPORT FCDEffectParameterAnimatableT; /**< Trick Doxygen. */ -#elif defined(LINUX) || defined(__APPLE__) -template class FCDEffectParameterAnimatableT; /**< Trick Doxygen. */ -#endif // LINUX +template class FCOLLADA_EXPORT FCDEffectParameterAnimatableT; typedef FCDEffectParameterAnimatableT FCDEffectParameterColor4; /**< A RGBA color effect parameter. */ typedef FCDEffectParameterAnimatableT FCDEffectParameterFloat; /**< A floating-point value effect parameter. */ diff --git a/FCollada/FCDocument/FCDTexture.h b/FCollada/FCDocument/FCDTexture.h index cc3e282..ba6ec58 100644 --- a/FCollada/FCDocument/FCDTexture.h +++ b/FCollada/FCDocument/FCDTexture.h @@ -33,11 +33,7 @@ class FCDEffectParameterSampler; class FCDEffectStandard; class FCDImage; -#if defined(WIN32) -template class FCOLLADA_EXPORT FCDEffectParameterT; /**< Trick Doxygen. */ -#elif defined(LINUX) || defined(__APPLE__) -template class FCDEffectParameterT; /**< Trick Doxygen. */ -#endif // LINUX +template class FCOLLADA_EXPORT FCDEffectParameterT; typedef FCDEffectParameterT FCDEffectParameterInt; /**< An integer effect parameter. */ /** diff --git a/FCollada/FCDocument/FCDocument.h b/FCollada/FCDocument/FCDocument.h index 97149ff..c9e96f3 100644 --- a/FCollada/FCDocument/FCDocument.h +++ b/FCollada/FCDocument/FCDocument.h @@ -27,13 +27,8 @@ #include "FUtils/FUParameter.h" #endif // _FU_PARAMETER_H_ -#if defined(WIN32) -template class FCOLLADA_EXPORT FCDLibrary; /**< Trick Doxygen. */ -template class FCOLLADA_EXPORT FUUniqueStringMapT; /**< Trick Doxygen. */ -#elif defined(LINUX) || defined(__APPLE__) -template class FCDLibrary; /**< Trick Doxygen. */ -template class FUUniqueStringMapT; /**< Trick Doxygen. */ -#endif // LINUX +template class FCOLLADA_EXPORT FCDLibrary; +template class FCOLLADA_EXPORT FUUniqueStringMapT; class FCDAnimated; class FCDAnimation; diff --git a/FCollada/FMath/FMFloat.h b/FCollada/FMath/FMFloat.h index fc0609b..e88a3c5 100644 --- a/FCollada/FMath/FMFloat.h +++ b/FCollada/FMath/FMFloat.h @@ -14,9 +14,7 @@ #ifndef _FM_FLOAT_H_ #define _FM_FLOAT_H_ -#if !defined(_INC_FLOAT) && (defined (WIN32) || defined (LINUX) || defined(__APPLE__)) #include -#endif // _INC_FLOAT, WIN32 and LINUX /** The default tolerance for double-sized floating-point comparison functions. */ #define DBL_TOLERANCE 0.0001 diff --git a/FCollada/FUtils/FUDebug.cpp b/FCollada/FUtils/FUDebug.cpp index 063fd51..b5832e9 100644 --- a/FCollada/FUtils/FUDebug.cpp +++ b/FCollada/FUtils/FUDebug.cpp @@ -22,16 +22,16 @@ FUDebug::FUDebug() {} FUDebug::~FUDebug() {} -#if defined(LINUX) || defined(__APPLE__) +#if defined(WIN32) +#define STRING_OUT(sz) OutputDebugString(sz); OutputDebugString(FC("\n")) +#elif defined(__PPU__) +#define STRING_OUT(sz) { fm::string szz = FUStringConversion::ToString(sz); printf(szz.c_str()); printf("\n"); } +#else #if defined(UNICODE) #define STRING_OUT(sz) fmt::print(stderr, "{}", TO_STRING(sz).c_str()); std::fflush(stderr); #else #define STRING_OUT(sz) fmt::print(stderr, "{}", sz); std::fflush(stderr); #endif // UNICODE -#elif defined(WIN32) -#define STRING_OUT(sz) OutputDebugString(sz); OutputDebugString(FC("\n")) -#elif defined(__PPU__) -#define STRING_OUT(sz) { fm::string szz = FUStringConversion::ToString(sz); printf(szz.c_str()); printf("\n"); } #endif #ifdef _DEBUG diff --git a/FCollada/FUtils/FUFileManager.cpp b/FCollada/FUtils/FUFileManager.cpp index 3e3955b..c41e46a 100644 --- a/FCollada/FUtils/FUFileManager.cpp +++ b/FCollada/FUtils/FUFileManager.cpp @@ -26,7 +26,7 @@ #elif defined(__APPLE__) #include #include -#elif defined(LINUX) +#else #include #include #include @@ -216,7 +216,7 @@ bool FUFileManager::MakeDirectory(const fstring& directory) if (_mkdir(TO_STRING(absoluteDirectory).c_str()) == 0) return true; errno_t err; _get_errno(&err); if (err == EEXIST) return true; -#elif defined(LINUX) || defined(__APPLE__) +#else if (mkdir(TO_STRING(absoluteDirectory).c_str(), std::numeric_limits::max()) == 0) return true; // I think this means all permissions.. #endif // WIN32 @@ -378,7 +378,16 @@ fstring FUFileManager::GetApplicationFolderName() GetModuleFileName(NULL, buffer, 1024); buffer[1023] = 0; _uri = buffer; -#elif defined(LINUX) +#elif defined(__APPLE__) + char path[1024]; + uint32_t pathLength = 1023; + if(_NSGetExecutablePath(path, &pathLength)) + { + // doesn't fit + path[0] = '\0'; + } + _uri = TO_FSTRING((const char*) path); +#else char path[1024]; char path2[1024]; struct stat stat_buf; @@ -403,15 +412,6 @@ fstring FUFileManager::GetApplicationFolderName() //"path" should have the application folder path in it. const char * exeName = &path[0]; _uri = TO_FSTRING(exeName); -#elif defined(__APPLE__) - char path[1024]; - uint32_t pathLength = 1023; - if(_NSGetExecutablePath(path, &pathLength)) - { - // doesn't fit - path[0] = '\0'; - } - _uri = TO_FSTRING((const char*) path); #endif // WIN32 fstring out; diff --git a/FCollada/FUtils/FUPluginManager.cpp b/FCollada/FUtils/FUPluginManager.cpp index d8dd17b..e9f0aee 100644 --- a/FCollada/FUtils/FUPluginManager.cpp +++ b/FCollada/FUtils/FUPluginManager.cpp @@ -24,7 +24,7 @@ #define ffindclose _findclose #define ffindnext _findnext #endif -#elif defined(__APPLE__) || defined(LINUX) +#else #include #include #endif //WIN32 @@ -125,7 +125,7 @@ void FUPluginManager::LoadPluginsInFolderName(const fstring& folderName, const f ffindclose(folderHandle); } -#elif defined(__APPLE__) || defined(LINUX) +#else fm::string s_filter = TO_STRING(filter); if (s_filter.length() > 0 && s_filter.front() == '*') s_filter.erase(0, 1); if (s_filter.length() > 0 && s_filter.back() == '*') s_filter.pop_back(); @@ -176,7 +176,7 @@ FUPluginManager::~FUPluginManager() { #if defined(WIN32) if ((*it)->module != NULL) FreeLibrary((*it)->module); -#elif defined(LINUX) || defined(__APPLE__) +#else if ((*it)->module != NULL) dlclose((*it)->module); #endif // WIN32 } diff --git a/FCollada/FUtils/FUPluginManager.h b/FCollada/FUtils/FUPluginManager.h index 3386534..08b9fa6 100644 --- a/FCollada/FUtils/FUPluginManager.h +++ b/FCollada/FUtils/FUPluginManager.h @@ -48,7 +48,7 @@ class FCOLLADA_EXPORT FUPluginManager fstring filename; #if defined(WIN32) HMODULE module; -#elif defined(__APPLE__) || defined(LINUX) +#else void* module; #endif // WIN32 diff --git a/FCollada/FUtils/Platforms.h b/FCollada/FUtils/Platforms.h index 3a16726..a5c9341 100644 --- a/FCollada/FUtils/Platforms.h +++ b/FCollada/FUtils/Platforms.h @@ -50,16 +50,18 @@ #include #include #include -#else -#ifdef __APPLE__ + +#elif __APPLE__ + #include #include #include #include #include #include -#else // __APPLE__ -#if defined(LINUX) || defined(__PPU__) + +#else + #include #include #include @@ -69,12 +71,8 @@ #include #include #include -#else // OTHER... -#error "Unsupported platform." -#endif // LINUX || __PPU__ -#endif // __APPLE__ -#endif // WIN32 +#endif // WIN32 __APPLE__ // Cross-platform type definitions #ifdef WIN32 @@ -88,7 +86,7 @@ typedef unsigned short uint16; typedef unsigned long uint32; typedef unsigned __int64 uint64; -#else // For LINUX and __APPLE__ +#else typedef int8_t int8; typedef int16_t int16; @@ -107,17 +105,15 @@ typedef uint8_t byte; #endif // PLATFORMS // Important functions that some OSes have missing! -#if defined(__APPLE__) || defined (LINUX) +#if defined(__PPU__) +#define glClearDepth glClearDepthf +#elif !defined(WIN32) inline char* strlower(char* str) { char* it = str; while (*it != 0) { *it = tolower(*it); ++it; } return str; } inline wchar_t* wcslwr(wchar_t* str) { wchar_t* it = str; while (*it != 0) { *it = towlower(*it); ++it; } return str; } inline int wcsicmp(const wchar_t* s1, const wchar_t* s2) { wchar_t c1 = *s1, c2 = *s2; while (c1 != 0 && c2 != 0) { if (c1 >= 'a' && c1 <= 'z') c1 -= 'a' + 'A'; if (c2 >= 'a' && c2 <= 'z') c2 -= 'a' + 'A'; if (c2 < c1) return -1; else if (c2 > c1) return 1; c1 = *(++s1); c2 = *(++s2); } return 0; } #define _stricmp strcasecmp #define _getcwd getcwd - -#elif defined(__PPU__) -#define glClearDepth glClearDepthf - -#endif // __APPLE__ and LINUX +#endif // Cross-platform needed functions #ifdef WIN32 diff --git a/FColladaTools/FCExport/FCExport.cpp b/FColladaTools/FCExport/FCExport.cpp index 3ba904e..dc0c5e7 100644 --- a/FColladaTools/FCExport/FCExport.cpp +++ b/FColladaTools/FCExport/FCExport.cpp @@ -21,9 +21,9 @@ int main(int argc, const char* argv[], char* envp[]) { #ifdef WIN32 _environ = envp; -#else //LINUX +#else environ = envp; -#endif //WIN32 and LINUX +#endif // WIN32 if (argc != 3) { std::cout << "Expecting two arguments:" << std::endl; diff --git a/FColladaTools/FCProcessImages/FCProcessImages.cpp b/FColladaTools/FCProcessImages/FCProcessImages.cpp index f293273..a3b753f 100644 --- a/FColladaTools/FCProcessImages/FCProcessImages.cpp +++ b/FColladaTools/FCProcessImages/FCProcessImages.cpp @@ -50,9 +50,9 @@ int main(int argc, const char* argv[], char* envp[]) { #ifdef WIN32 _environ = envp; -#else //LINUX +#else environ = envp; -#endif //WIN32 and LINUX +#endif //WIN32 if (argc != 3) { std::cout << "Expecting two arguments:" << std::endl; diff --git a/FColladaTools/FCProcessMeshes/FCProcessMeshes.cpp b/FColladaTools/FCProcessMeshes/FCProcessMeshes.cpp index c9652f1..13cfe87 100644 --- a/FColladaTools/FCProcessMeshes/FCProcessMeshes.cpp +++ b/FColladaTools/FCProcessMeshes/FCProcessMeshes.cpp @@ -49,9 +49,9 @@ int main(int argc, const char* argv[], char* envp[]) { #ifdef WIN32 _environ = envp; -#else //LINUX +#else environ = envp; -#endif //WIN32 and LINUX +#endif // WIN32 // variables for processing ProcessMeshesOptions options;