diff options
author | Neal Gompa (ニール・ゴンパ) <ngompa13@gmail.com> | 2022-04-28 15:15:05 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-28 15:15:05 +0300 |
commit | 1875c2f0bc7eb95d4193e181ab4e34f5a1065284 (patch) | |
tree | 6ae76bc9627bec221974811b8444a997d018f8f2 | |
parent | ad92ff36e02b05ec3c18e61c62b356a01d5275a8 (diff) | |
parent | 0abc75332df32b7d890426682968e313b8eeab01 (diff) |
Merge pull request #42 from feliwir/platform-header
Detect target environment at compile time
-rw-r--r-- | Libraries/macogg/include/ogg/config_types.h | 1 | ||||
-rw-r--r-- | Libraries/tinyxml/tinyxml.cpp | 1 | ||||
-rw-r--r-- | Projects/CMakeLists.txt | 8 | ||||
-rw-r--r-- | Source/Compat/Linux/linux_compat.cpp | 1 | ||||
-rw-r--r-- | Source/Compat/UNIX/unix_compat.cpp | 1 | ||||
-rw-r--r-- | Source/Compat/UNIX/unix_filepath.cpp | 1 | ||||
-rw-r--r-- | Source/Compat/Win/win_compat.cpp | 1 | ||||
-rw-r--r-- | Source/Compat/Win/win_filepath.cpp | 1 | ||||
-rw-r--r-- | Source/Compat/compat.h | 1 | ||||
-rw-r--r-- | Source/Compat/platform.h | 50 | ||||
-rw-r--r-- | Source/Compat/platformsetup.h | 4 | ||||
-rw-r--r-- | Source/Internal/error.cpp | 1 | ||||
-rw-r--r-- | Source/Logging/logdata.h | 1 | ||||
-rw-r--r-- | Source/Timing/timestamp.h | 2 | ||||
-rw-r--r-- | Source/Utility/stacktrace.h | 1 | ||||
-rw-r--r-- | Source/Utility/timing.h | 1 |
16 files changed, 66 insertions, 10 deletions
diff --git a/Libraries/macogg/include/ogg/config_types.h b/Libraries/macogg/include/ogg/config_types.h index 298226fe..c02ab7c5 100644 --- a/Libraries/macogg/include/ogg/config_types.h +++ b/Libraries/macogg/include/ogg/config_types.h @@ -1,6 +1,7 @@ #ifndef __CONFIG_TYPES_H__ #define __CONFIG_TYPES_H__ +#include <Compat/platform.h> #if PLATFORM_UNIX #include <stdint.h> #endif diff --git a/Libraries/tinyxml/tinyxml.cpp b/Libraries/tinyxml/tinyxml.cpp index f598003f..514ee90c 100644 --- a/Libraries/tinyxml/tinyxml.cpp +++ b/Libraries/tinyxml/tinyxml.cpp @@ -32,6 +32,7 @@ distribution. #include "tinyxml.h" +#include <Compat/platform.h> #ifdef PLATFORM_WINDOWS #include <windows.h> #endif diff --git a/Projects/CMakeLists.txt b/Projects/CMakeLists.txt index 9bbacc53..21c9fce2 100644 --- a/Projects/CMakeLists.txt +++ b/Projects/CMakeLists.txt @@ -232,7 +232,6 @@ if(LINUX) SET(ARCH_OUT "amd64") SET(TOOL_BIN_NAME "bin64") set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS ON) - ADD_DEFINITIONS(-DPLATFORM_64=1) ELSE() SET(LIB_SUFFIX "lib") SET(BIN_SUFFIX ".bin.x86") @@ -243,7 +242,6 @@ if(LINUX) ### Ensure LargeFileSupport on 32bit linux set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_FILE_OFFSET_BITS=64") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_FILE_OFFSET_BITS=64") - ADD_DEFINITIONS(-DPLATFORM_32=1) ENDIF() endif() @@ -408,11 +406,7 @@ ELSE() ENDIF() # Add preprocessor definitions so that the code can use platform #ifdefs -IF(UNIX) - ADD_DEFINITIONS(-DPLATFORM_UNIX=1) -ENDIF() IF(LINUX) - ADD_DEFINITIONS(-DPLATFORM_LINUX=1) ADD_DEFINITIONS(${GTK2_DEFINITIONS}) #-no-strict-aliasing for the sake of angelscript @@ -424,7 +418,6 @@ IF(LINUX) ENDIF() IF(APPLE) - ADD_DEFINITIONS(-DPLATFORM_MACOSX=1) #-no-strict-aliasing for the sake of angelscript set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-strict-aliasing") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -fno-strict-aliasing") @@ -447,7 +440,6 @@ SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DNDEBUG") #enable .pdb symbol generation for Release target on Windows IF(WIN32) #Disable warnings when using standard c functions in visual studio - ADD_DEFINITIONS(-DPLATFORM_WINDOWS=1) ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /GF -D_CRT_SECURE_NO_WARNINGS -DNEED_SNPRINTF_ONLY /EHsc") diff --git a/Source/Compat/Linux/linux_compat.cpp b/Source/Compat/Linux/linux_compat.cpp index 90886da5..db59a47d 100644 --- a/Source/Compat/Linux/linux_compat.cpp +++ b/Source/Compat/Linux/linux_compat.cpp @@ -20,6 +20,7 @@ // limitations under the License. // //----------------------------------------------------------------------------- +#include <Compat/platform.h> #if !PLATFORM_LINUX #error Do not compile this. #endif diff --git a/Source/Compat/UNIX/unix_compat.cpp b/Source/Compat/UNIX/unix_compat.cpp index 90e095bb..f15073ad 100644 --- a/Source/Compat/UNIX/unix_compat.cpp +++ b/Source/Compat/UNIX/unix_compat.cpp @@ -20,6 +20,7 @@ // limitations under the License. // //----------------------------------------------------------------------------- +#include <Compat/platform.h> #if !PLATFORM_UNIX #error Do not compile this. #endif diff --git a/Source/Compat/UNIX/unix_filepath.cpp b/Source/Compat/UNIX/unix_filepath.cpp index ab66b591..a7e8eaea 100644 --- a/Source/Compat/UNIX/unix_filepath.cpp +++ b/Source/Compat/UNIX/unix_filepath.cpp @@ -20,6 +20,7 @@ // limitations under the License. // //----------------------------------------------------------------------------- +#include <Compat/platform.h> #if !PLATFORM_UNIX #error Do not compile this. #endif diff --git a/Source/Compat/Win/win_compat.cpp b/Source/Compat/Win/win_compat.cpp index 13c2a1c6..b06687be 100644 --- a/Source/Compat/Win/win_compat.cpp +++ b/Source/Compat/Win/win_compat.cpp @@ -20,6 +20,7 @@ // limitations under the License. // //----------------------------------------------------------------------------- +#include <Compat/platform.h> #if !PLATFORM_WINDOWS #error Do not compile this. #endif diff --git a/Source/Compat/Win/win_filepath.cpp b/Source/Compat/Win/win_filepath.cpp index 46c9c8b3..8f7f9bb1 100644 --- a/Source/Compat/Win/win_filepath.cpp +++ b/Source/Compat/Win/win_filepath.cpp @@ -20,6 +20,7 @@ // limitations under the License. // //----------------------------------------------------------------------------- +#include <Compat/platform.h> #if !PLATFORM_WINDOWS #error Do not compile this. #endif diff --git a/Source/Compat/compat.h b/Source/Compat/compat.h index c76ce5f2..038222e0 100644 --- a/Source/Compat/compat.h +++ b/Source/Compat/compat.h @@ -51,6 +51,7 @@ bool checkFileAccess(const char* path); void createParentDirs(const char* abs_path); bool areSame(const char* path1, const char* path2 ); +#include <Compat/platform.h> #if PLATFORM_UNIX == 1 //This is shared on mac and linux. #include <Compat/UNIX/unix_compat.h> #endif diff --git a/Source/Compat/platform.h b/Source/Compat/platform.h new file mode 100644 index 00000000..e70ef80f --- /dev/null +++ b/Source/Compat/platform.h @@ -0,0 +1,50 @@ +//----------------------------------------------------------------------------- +// Name: compat.h +// Developer: Wolfire Games LLC +// Description: Compiler macros to detect the target platform +// License: Read below +//----------------------------------------------------------------------------- +// +// Copyright 2022 Wolfire Games LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//----------------------------------------------------------------------------- +#pragma once + +// Check pointer size +#if defined _M_X64 || defined _M_AMD64 || defined __amd64__ || defined __amd64 || defined __x86_64__ || defined __x86_64 || defined _WIN64 || defined __64BIT__ || defined __LP64 || defined _LP64 || defined __LP64__ || defined _ADDR64 +#define PLATFORM_64 1 +#else +#define PLATFORM_32 1 +#endif + +// Check windows +#if defined _WIN32 || defined_WIN64 +#define PLATFORM_WINDOWS 1 +#endif + +// Check unix +#if defined __unix__ +#define PLATFORM_UNIX 1 +#endif + +// Check Linux +#if defined linux || defined __linux +#define PLATFORM_LINUX 1 +#endif + +// Check macos +#if defined __APPLE__ +#define PLATFORM_MACOSX 1 +#endif
\ No newline at end of file diff --git a/Source/Compat/platformsetup.h b/Source/Compat/platformsetup.h index 52bdd945..807164e1 100644 --- a/Source/Compat/platformsetup.h +++ b/Source/Compat/platformsetup.h @@ -22,12 +22,12 @@ //----------------------------------------------------------------------------- #pragma once +#include <Compat/compat.h> + #if !PLATFORM_UNIX #define _WIN32 1 #endif -#include <Compat/compat.h> - //Disable console #ifdef _WIN32 #pragma comment( linker, "/subsystem:\"windows\" \ diff --git a/Source/Internal/error.cpp b/Source/Internal/error.cpp index 48e4b453..2318961d 100644 --- a/Source/Internal/error.cpp +++ b/Source/Internal/error.cpp @@ -32,6 +32,7 @@ #include <Graphics/graphics.h> #include <Threading/thread_sanity.h> #include <Compat/os_dialogs.h> +#include <Compat/platform.h> #include <Utility/stacktrace.h> #include <map> diff --git a/Source/Logging/logdata.h b/Source/Logging/logdata.h index 9f8aebf4..2e0cd151 100644 --- a/Source/Logging/logdata.h +++ b/Source/Logging/logdata.h @@ -28,6 +28,7 @@ #include <cstring> #include "Utility/compiler_macros.h" +#include <Compat/platform.h> #define LOGGER_LIMIT 4 diff --git a/Source/Timing/timestamp.h b/Source/Timing/timestamp.h index 598b1274..12576f6c 100644 --- a/Source/Timing/timestamp.h +++ b/Source/Timing/timestamp.h @@ -24,6 +24,8 @@ //----------------------------------------------------------------------------- #pragma once +#include <Compat/platform.h> + inline uint64_t GetTimestamp() { // Use rdtsc instruction to get the tsc or Time Stamp Counter #if (defined(PLATFORM_LINUX) || defined(PLATFORM_MACOSX)) && (defined(__i386__) || defined(__x86_64__)) diff --git a/Source/Utility/stacktrace.h b/Source/Utility/stacktrace.h index dd0d69d1..c93e5843 100644 --- a/Source/Utility/stacktrace.h +++ b/Source/Utility/stacktrace.h @@ -22,6 +22,7 @@ //----------------------------------------------------------------------------- #include <sstream> +#include <Compat/platform.h> #if PLATFORM_LINUX || PLATFORM_MACOSX #include <Memory/allocation.h> #include <sys/time.h> diff --git a/Source/Utility/timing.h b/Source/Utility/timing.h index 55363140..b72d8a40 100644 --- a/Source/Utility/timing.h +++ b/Source/Utility/timing.h @@ -22,6 +22,7 @@ //----------------------------------------------------------------------------- #pragma once +#include <Compat/platform.h> #if defined(PLATFORM_WINDOWS) && _MSC_VER >= 1600 #include <intrin.h> #endif |