diff options
author | Stephan Vedder <vedder@mbits.info> | 2022-04-28 11:16:01 +0300 |
---|---|---|
committer | Stephan Vedder <vedder@mbits.info> | 2022-04-28 11:16:01 +0300 |
commit | bdc833c90191fd3ef4529aefe77f653a001af314 (patch) | |
tree | 8ede4482e23de6f1008a484698f25df87baeddbc | |
parent | bb8e0756a8d235a60037ed57706aac226d4ca720 (diff) |
Detect target environment at compile time
-rw-r--r-- | Libraries/macogg/include/ogg/config_types.h | 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/Logging/logdata.h | 1 | ||||
-rw-r--r-- | Source/Utility/timing.h | 1 |
12 files changed, 61 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/Projects/CMakeLists.txt b/Projects/CMakeLists.txt index fd81c15b..bc858df5 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/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/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 |