diff --git a/CMake/CMakeMacros.cmake b/CMake/CMakeMacros.cmake index 5049e4fbc7..7e85ddd870 100644 --- a/CMake/CMakeMacros.cmake +++ b/CMake/CMakeMacros.cmake @@ -55,3 +55,4 @@ function(disable_project_warnings projectName) endif() endif() endfunction() + diff --git a/CMake/DefineOptions.cmake b/CMake/DefineOptions.cmake index 6e14ffe92d..3963314ec2 100644 --- a/CMake/DefineOptions.cmake +++ b/CMake/DefineOptions.cmake @@ -1,6 +1,11 @@ # Prep options that are needed for each platform. + +# This option allows for networking support with StepMania. option(WITH_NETWORKING "Build with networking support." ON) +# This option allows for additional version information to be built-in. +option(WITH_VERSION_INFO "Build with version information." ON) + # This option quiets warnings that are a part of external projects. option(WITH_EXTERNAL_WARNINGS "Build with warnings for all components, not just StepMania." OFF) diff --git a/StepmaniaCore.cmake b/StepmaniaCore.cmake index 8e2994a399..2a9109f523 100644 --- a/StepmaniaCore.cmake +++ b/StepmaniaCore.cmake @@ -45,8 +45,67 @@ include("${CMAKE_CURRENT_LIST_DIR}/CMake/SMDefs.cmake") # Put the predefined targets in separate groups. set_property(GLOBAL PROPERTY USE_FOLDERS ON) +# Checks the standard include directories for c-style headers. +# We may use C++ in this project, but the check works better with plain C headers. +include(CheckIncludeFiles) +check_include_files(math.h HAVE_MATH_H) +check_include_files(alloca.h HAVE_ALLOCA_H) +check_include_files(dirent.h HAVE_DIRENT_H) +check_include_files(inttypes.h HAVE_INTTYPES_H) +check_include_files(stdint.h HAVE_STDINT_H) +check_include_files(endian.h HAVE_ENDIAN_H) +check_include_files(sys/endian.h HAVE_SYS_ENDIAN_H) +check_include_files(machine/endian.h HAVE_MACHINE_ENDIAN_H) +check_include_files(sys/param.h HAVE_SYS_PARAM_H) +check_include_files(sys/utsname.h HAVE_SYS_UTSNAME_H) +check_include_files(fcntl.h HAVE_FCNTL_H) +check_include_files(unistd.h HAVE_UNISTD_H) + +include(CheckFunctionExists) +include(CheckSymbolExists) +include(CheckCXXSymbolExists) +if (WIN32 AND MSVC) + check_function_exists(_mkdir HAVE__MKDIR) + check_function_exists(_snprintf HAVE__SNPRINTF) +else() + check_function_exists(mkdir HAVE_MKDIR) + check_function_exists(snprintf HAVE_SNPRINTF) +endif() +check_cxx_symbol_exists(powf cmath HAVE_POWF) +check_cxx_symbol_exists(sqrtf cmath HAVE_SQRTF) +check_cxx_symbol_exists(sinf cmath HAVE_SINF) +check_cxx_symbol_exists(tanf cmath HAVE_TANF) +check_cxx_symbol_exists(cosf cmath HAVE_COSF) +check_cxx_symbol_exists(acosf cmath HAVE_ACOSF) +check_cxx_symbol_exists(truncf cmath HAVE_TRUNCF) +check_cxx_symbol_exists(roundf cmath HAVE_ROUNDF) +check_cxx_symbol_exists(lrintf cmath HAVE_LRINTF) +check_cxx_symbol_exists(strtof cstdlib HAVE_STRTOF) +check_symbol_exists(M_PI math.h HAVE_M_PI) + +# Checks to make it easier to work with 32-bit/64-bit builds if required. +include(CheckTypeSize) +check_type_size(intptr_t SIZEOF_INTPTR_T) +check_type_size(pid_t SIZEOF_PID_T) +check_type_size(size_t SIZEOF_SIZE_T) +check_type_size(ssize_t SIZEOF_SSIZE_T) + +include(TestBigEndian) +test_big_endian(BIGENDIAN) +if (${BIGENDIAN}) + set(ENDIAN_BIG 1) +else() + set(ENDIAN_LITTLE 1) +endif() + +if (WITH_VERSION_INFO) + set(HAVE_VERSION_INFO 1) +endif() + +configure_file("${SM_SRC_DIR}/config.in.hpp" "${SM_SRC_DIR}/generated/config.hpp") + # Dependencies go here. -set(ENDIANNESS "ENDIAN_LITTLE") + if(WIN32) set(HAS_OGG TRUE) set(HAS_MP3 TRUE) @@ -114,7 +173,6 @@ elseif(MACOSX) MAC_FRAME_QUICKTIME ) elseif(LINUX) - include(TestBigEndian) include(ExternalProject) if(NOT WITH_GPL_LIBS) @@ -321,11 +379,6 @@ elseif(LINUX) message(FATAL_ERROR "GLEW required to compile StepMania.") endif() - test_big_endian(BIGENDIAN) - if (${BIGENDIAN}) - set(ENDIANNESS "ENDIAN_BIG") - endif() - endif() # Define installer based items for cpack. diff --git a/src/CMakeData-gtk.cmake b/src/CMakeData-gtk.cmake index 63b6d358aa..7082744c79 100644 --- a/src/CMakeData-gtk.cmake +++ b/src/CMakeData-gtk.cmake @@ -7,7 +7,6 @@ add_library("GtkModule" "arch/LoadingWindow/LoadingWindow_GtkModule.cpp" "arch/LoadingWindow/LoadingWindow_GtkModule.h" ) -sm_add_compile_definition("GtkModule" "${ENDIANNESS}") # It is normally not appropriate to set the prefix to the empty string. # This is to maintain compatibility with the current source. @@ -23,7 +22,11 @@ target_link_libraries("GtkModule" ${GTK2_LIBRARIES}) set_property(TARGET "GtkModule" PROPERTY FOLDER "Internal Libraries") list(APPEND SM_GTK_INCLUDE_DIRS "${SM_SRC_DIR}" + "${SM_SRC_DIR}/generated" "${SM_SRC_DIR}/arch/LoadingWindow" "${GTK2_INCLUDE_DIRS}" ) + +sm_add_compile_definition("GtkModule" CMAKE_POWERED) + target_include_directories("GtkModule" PUBLIC ${SM_GTK_INCLUDE_DIRS}) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 32f8aaaf3c..ca7e2bb151 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -38,6 +38,7 @@ list(APPEND SMDATA_GLOBAL_FILES_SRC ) list(APPEND SMDATA_GLOBAL_FILES_HPP + "generated/config.hpp" "GameLoop.h" "global.h" "ProductInfo.h" # TODO: Have this be auto-generated. @@ -204,6 +205,10 @@ set_target_properties("${SM_EXE_NAME}" PROPERTIES RELWITHDEBINFO_OUTPUT_NAME "${SM_NAME_RELWITHDEBINFO}" ) +if (WITH_VERSION_INFO) + sm_add_compile_definition("${SM_EXE_NAME}" HAVE_VERSION_INFO) +endif() + if (WITH_PORTABLE_TOMCRYPT) sm_add_compile_definition("${SM_EXE_NAME}" LTC_NO_ASM) elseif (WITH_NO_ROLC_TOMCRYPT OR APPLE) @@ -365,8 +370,6 @@ elseif(APPLE) COMMAND ${CMAKE_COMMAND} -E copy "${SM_XCODE_DIR}/Hardware.plist" "$/../Resources/" ) else() # Linux - # TODO: Have this compile definition be used all over. Currently fixed for Windows and Mac, but in headers. - sm_add_compile_definition("${SM_EXE_NAME}" "${ENDIANNESS}") set_target_properties("${SM_EXE_NAME}" PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${SM_ROOT_DIR}" RUNTIME_OUTPUT_DIRECTORY_RELEASE "${SM_ROOT_DIR}" @@ -610,6 +613,7 @@ target_link_libraries("${SM_EXE_NAME}" ${SMDATA_LINK_LIB}) list(APPEND SM_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR} + "${SM_SRC_DIR}/generated" "${SM_EXTERN_DIR}/vorbis" ) if(NOT APPLE) diff --git a/src/RageException.h b/src/RageException.h index 803bcb4c4d..210b8bac49 100644 --- a/src/RageException.h +++ b/src/RageException.h @@ -1,5 +1,10 @@ #ifndef RAGE_EXCEPTION_H #define RAGE_EXCEPTION_H + +#if defined(CMAKE_POWERED) +#include "config.hpp" +#endif + /** * @brief Namespace for throwing fatal errors. * diff --git a/src/RageFileDriverDirect.cpp b/src/RageFileDriverDirect.cpp index b9be858378..54d9f70ae0 100644 --- a/src/RageFileDriverDirect.cpp +++ b/src/RageFileDriverDirect.cpp @@ -6,14 +6,19 @@ #include "RageUtil_FileDB.h" #include "RageLog.h" +#if defined(HAVE_FCNTL_H) #include +#endif #include #include #include #if !defined(WIN32) + +#if defined(HAVE_DIRENT_H) #include -#include +#endif + #else #include "archutils/Win32/ErrorStrings.h" #include diff --git a/src/RageFileDriverDirectHelpers.cpp b/src/RageFileDriverDirectHelpers.cpp index fd8aa8d048..219878103c 100644 --- a/src/RageFileDriverDirectHelpers.cpp +++ b/src/RageFileDriverDirectHelpers.cpp @@ -9,8 +9,11 @@ #include #if !defined(WIN32) + +#if defined(HAVE_DIRENT_H) #include -#include +#endif + #else #include #include diff --git a/src/RageFileDriverDirectHelpers.h b/src/RageFileDriverDirectHelpers.h index 91b2f0d9d4..7d37f08f2e 100644 --- a/src/RageFileDriverDirectHelpers.h +++ b/src/RageFileDriverDirectHelpers.h @@ -3,7 +3,9 @@ #ifndef RAGE_FILE_DRIVER_DIRECT_HELPERS_H #define RAGE_FILE_DRIVER_DIRECT_HELPERS_H +#if defined(HAVE_FCNTL_H) #include +#endif #define DoOpen open #define DoStat stat diff --git a/src/RageFileDriverReadAhead.cpp b/src/RageFileDriverReadAhead.cpp index 098acc29ac..57b8966cd1 100644 --- a/src/RageFileDriverReadAhead.cpp +++ b/src/RageFileDriverReadAhead.cpp @@ -43,7 +43,9 @@ #include "RageUtil.h" #include "RageFileManager_ReadAhead.h" +#if defined(HAVE_FCNTL_H) #include +#endif #include #if defined(WIN32) #include diff --git a/src/RageFileManager_ReadAhead.cpp b/src/RageFileManager_ReadAhead.cpp index f955856282..c174f0bde0 100644 --- a/src/RageFileManager_ReadAhead.cpp +++ b/src/RageFileManager_ReadAhead.cpp @@ -3,7 +3,9 @@ #include "RageThreads.h" #include "RageLog.h" +#if defined(HAVE_FCNTL_H) #include +#endif #include #if defined(WIN32) #include diff --git a/src/RageSoundReader_ThreadedBuffer.cpp b/src/RageSoundReader_ThreadedBuffer.cpp index b14de5afb3..14dac250a9 100644 --- a/src/RageSoundReader_ThreadedBuffer.cpp +++ b/src/RageSoundReader_ThreadedBuffer.cpp @@ -5,10 +5,6 @@ #include "Foreach.h" #include "RageLog.h" -#if !defined(_WINDOWS) -#include -#endif - /* Implement threaded read-ahead buffering. * * If a buffer is low on data, keep filling until it has a g_iMinFillFrames. diff --git a/src/RageUtil.h b/src/RageUtil.h index 1ea979a785..5895fe9498 100644 --- a/src/RageUtil.h +++ b/src/RageUtil.h @@ -563,7 +563,7 @@ RString Basename( const RString &dir ); RString Dirname( const RString &dir ); RString Capitalize( const RString &s ); -#ifndef WIN32 +#if defined(HAVE_UNISTD_H) #include /* correct place with correct definitions */ #endif diff --git a/src/arch/ArchHooks/ArchHooks_Unix.cpp b/src/arch/ArchHooks/ArchHooks_Unix.cpp index 31033727a4..d70ec997b7 100644 --- a/src/arch/ArchHooks/ArchHooks_Unix.cpp +++ b/src/arch/ArchHooks/ArchHooks_Unix.cpp @@ -11,7 +11,9 @@ #include "archutils/Common/PthreadHelpers.h" #include "archutils/Unix/EmergencyShutdown.h" #include "archutils/Unix/AssertionHandler.h" +#if defined(HAVE_UNISTD_H) #include +#endif #include #include #include diff --git a/src/arch/InputHandler/InputHandler_Linux_Event.cpp b/src/arch/InputHandler/InputHandler_Linux_Event.cpp index 4f26f60831..be60412c29 100644 --- a/src/arch/InputHandler/InputHandler_Linux_Event.cpp +++ b/src/arch/InputHandler/InputHandler_Linux_Event.cpp @@ -5,8 +5,13 @@ #include "LinuxInputManager.h" #include "GamePreferences.h" //needed for Axis Fix +#if defined(HAVE_UNISTD_H) #include +#endif + +#if defined(HAVE_FCNTL_H) #include +#endif #include #include diff --git a/src/arch/InputHandler/InputHandler_Linux_Joystick.cpp b/src/arch/InputHandler/InputHandler_Linux_Joystick.cpp index 96cba13f02..e5e729eb16 100644 --- a/src/arch/InputHandler/InputHandler_Linux_Joystick.cpp +++ b/src/arch/InputHandler/InputHandler_Linux_Joystick.cpp @@ -5,8 +5,12 @@ #include "LinuxInputManager.h" #include "RageInputDevice.h" // NUM_JOYSTICKS +#if defined(HAVE_UNISTD_H) #include +#endif +#if defined(HAVE_FCNTL_H) #include +#endif #include #include diff --git a/src/arch/InputHandler/InputHandler_Linux_PIUIO.cpp b/src/arch/InputHandler/InputHandler_Linux_PIUIO.cpp index 1febef3722..2a82553f1f 100644 --- a/src/arch/InputHandler/InputHandler_Linux_PIUIO.cpp +++ b/src/arch/InputHandler/InputHandler_Linux_PIUIO.cpp @@ -5,8 +5,12 @@ #include #include +#if defined(HAVE_UNISTD_H) #include +#endif +#if defined(HAVE_FCNTL_H) #include +#endif #include #include diff --git a/src/arch/InputHandler/InputHandler_Linux_tty.cpp b/src/arch/InputHandler/InputHandler_Linux_tty.cpp index 88015caa08..cbadef03ae 100644 --- a/src/arch/InputHandler/InputHandler_Linux_tty.cpp +++ b/src/arch/InputHandler/InputHandler_Linux_tty.cpp @@ -16,7 +16,9 @@ #include #include +#if defined(HAVE_FCNTL_H) #include +#endif #include #include diff --git a/src/arch/InputHandler/LinuxInputManager.cpp b/src/arch/InputHandler/LinuxInputManager.cpp index e657dd58b7..395d5e3c3f 100644 --- a/src/arch/InputHandler/LinuxInputManager.cpp +++ b/src/arch/InputHandler/LinuxInputManager.cpp @@ -8,7 +8,11 @@ #include "Foreach.h" #include // std::string::npos + +#if defined(HAVE_DIRENT_H) #include +#endif + #include RString getDevice(RString inputDir, RString type) diff --git a/src/arch/Lights/LightsDriver_LinuxWeedTech.cpp b/src/arch/Lights/LightsDriver_LinuxWeedTech.cpp index 7376118651..4c10a5fe0d 100644 --- a/src/arch/Lights/LightsDriver_LinuxWeedTech.cpp +++ b/src/arch/Lights/LightsDriver_LinuxWeedTech.cpp @@ -1,9 +1,15 @@ #include "global.h" #include +#if defined(HAVE_UNISTD_H) #include +#endif #include #include + +#if defined(HAVE_FCNTL_H) #include +#endif + #include #include #include "LightsDriver_LinuxWeedTech.h" diff --git a/src/arch/Lights/LightsDriver_Linux_PIUIO.cpp b/src/arch/Lights/LightsDriver_Linux_PIUIO.cpp index 8895567f11..9225206fa5 100644 --- a/src/arch/Lights/LightsDriver_Linux_PIUIO.cpp +++ b/src/arch/Lights/LightsDriver_Linux_PIUIO.cpp @@ -1,9 +1,15 @@ #include "global.h" #include +#if defined(HAVE_UNISTD_H) #include +#endif #include #include + +#if defined(HAVE_FCNTL_H) #include +#endif + #include #include "LightsDriver_Linux_PIUIO.h" #include "GameState.h" diff --git a/src/arch/Lights/LightsDriver_Linux_PIUIO_Leds.cpp b/src/arch/Lights/LightsDriver_Linux_PIUIO_Leds.cpp index 8da40318db..c0c24a7244 100644 --- a/src/arch/Lights/LightsDriver_Linux_PIUIO_Leds.cpp +++ b/src/arch/Lights/LightsDriver_Linux_PIUIO_Leds.cpp @@ -1,9 +1,15 @@ #include "global.h" #include +#if defined(HAVE_UNISTD_H) #include +#endif #include #include + +#if defined(HAVE_FCNTL_H) #include +#endif + #include #include "LightsDriver_Linux_PIUIO_Leds.h" #include "GameState.h" diff --git a/src/arch/MemoryCard/MemoryCardDriverThreaded_Linux.cpp b/src/arch/MemoryCard/MemoryCardDriverThreaded_Linux.cpp index 96d770b41a..e6ea69fa85 100644 --- a/src/arch/MemoryCard/MemoryCardDriverThreaded_Linux.cpp +++ b/src/arch/MemoryCard/MemoryCardDriverThreaded_Linux.cpp @@ -6,8 +6,14 @@ #include "RageTimer.h" #include +#if defined(HAVE_FCNTL_H) #include +#endif + +#if defined(HAVE_DIRENT_H) #include +#endif + #include #include #include diff --git a/src/arch/MemoryCard/MemoryCardDriverThreaded_MacOSX.cpp b/src/arch/MemoryCard/MemoryCardDriverThreaded_MacOSX.cpp index 7c745beeb2..96595a685e 100644 --- a/src/arch/MemoryCard/MemoryCardDriverThreaded_MacOSX.cpp +++ b/src/arch/MemoryCard/MemoryCardDriverThreaded_MacOSX.cpp @@ -9,11 +9,15 @@ #include #include #include +#if defined(HAVE_SYS_PARAM_H) #include +#endif #include #include #include +#if defined(HAVE_UNISTD_H) #include +#endif class MemoryCardDriverThreaded_MacOSX::Helper { diff --git a/src/arch/Sound/RageSoundDriver_OSS.cpp b/src/arch/Sound/RageSoundDriver_OSS.cpp index 06d1737a98..b91b767309 100644 --- a/src/arch/Sound/RageSoundDriver_OSS.cpp +++ b/src/arch/Sound/RageSoundDriver_OSS.cpp @@ -6,8 +6,12 @@ #include "RageSoundManager.h" #include "RageUtil.h" +#if defined(HAVE_UNISTD_H) #include +#endif +#if defined(HAVE_FCNTL_H) #include +#endif #include #include #include diff --git a/src/archutils/Common/PthreadHelpers.cpp b/src/archutils/Common/PthreadHelpers.cpp index 49c35cdc55..edfa3ecc8e 100644 --- a/src/archutils/Common/PthreadHelpers.cpp +++ b/src/archutils/Common/PthreadHelpers.cpp @@ -10,9 +10,13 @@ #endif #if defined(LINUX) +#if defined(HAVE_UNISTD_H) #include +#endif #include +#if defined(HAVE_FCNTL_H) #include +#endif #include #include #include diff --git a/src/archutils/Common/PthreadHelpers.h b/src/archutils/Common/PthreadHelpers.h index 301523c880..3ed725e4fb 100644 --- a/src/archutils/Common/PthreadHelpers.h +++ b/src/archutils/Common/PthreadHelpers.h @@ -1,7 +1,9 @@ #ifndef PID_THREAD_HELPERS_H #define PID_THREAD_HELPERS_H +#if defined(HAVE_STDINT_H) #include +#endif #include "global.h" RString ThreadsVersion(); diff --git a/src/archutils/Common/gcc_byte_swaps.h b/src/archutils/Common/gcc_byte_swaps.h index 46290693b6..a9006240b6 100644 --- a/src/archutils/Common/gcc_byte_swaps.h +++ b/src/archutils/Common/gcc_byte_swaps.h @@ -3,7 +3,9 @@ #if defined(CPU_X86) +#if defined(HAVE_STDINT_H) #include +#endif inline uint32_t ArchSwap32( uint32_t n ) { diff --git a/src/archutils/Darwin/Crash.cpp b/src/archutils/Darwin/Crash.cpp index a67f970bd4..68c9521dc6 100644 --- a/src/archutils/Darwin/Crash.cpp +++ b/src/archutils/Darwin/Crash.cpp @@ -4,7 +4,9 @@ #include "arch/ArchHooks/ArchHooks.h" #include #include +#if defined(HAVE_UNISTD_H) #include +#endif #include RString CrashHandler::GetLogsDirectory() diff --git a/src/archutils/Darwin/arch_setup.h b/src/archutils/Darwin/arch_setup.h index 2c5f81e613..24e5fd6579 100644 --- a/src/archutils/Darwin/arch_setup.h +++ b/src/archutils/Darwin/arch_setup.h @@ -4,7 +4,6 @@ // Replace the main function. extern "C" int sm_main( int argc, char *argv[] ); -#define HAVE_VERSION_INFO #define HAVE_CXA_DEMANGLE #define HAVE_FFMPEG #define HAVE_PTHREAD_COND_TIMEDWAIT @@ -12,11 +11,6 @@ extern "C" int sm_main( int argc, char *argv[] ); * this in all cases. If only they could be consistent... */ #define HAVE_DECL_SIGUSR1 1 -/* We have which gets pulled in when we use gcc 4.0's - * but no . The definitions of LITTLE_ENDIAN, BIG_ENDIAN and end up conflicting - * even though they resolve to the same thing (bug in gcc?). */ -#define HAVE_MACHINE_ENDIAN_H -#define HAVE_INTTYPES_H #define __STDC_FORMAT_MACROS #define CRASH_HANDLER @@ -25,7 +19,6 @@ extern "C" int sm_main( int argc, char *argv[] ); #define NO_GL_FLUSH #define CPU_X86 -#define ENDIAN_LITTLE #define BACKTRACE_METHOD_X86_DARWIN #define BACKTRACE_LOOKUP_METHOD_DLADDR diff --git a/src/archutils/Unix/AssertionHandler.cpp b/src/archutils/Unix/AssertionHandler.cpp index f49e04f4fd..8e14e8ad6d 100644 --- a/src/archutils/Unix/AssertionHandler.cpp +++ b/src/archutils/Unix/AssertionHandler.cpp @@ -2,7 +2,9 @@ #include "RageUtil.h" #include "RageException.h" #include "archutils/Unix/EmergencyShutdown.h" +#if defined(HAVE_UNISTD_H) #include +#endif #include /* We can define this symbol to catch failed assert() calls. This is only used diff --git a/src/archutils/Unix/Backtrace.cpp b/src/archutils/Unix/Backtrace.cpp index 3faa821108..032ce36f07 100644 --- a/src/archutils/Unix/Backtrace.cpp +++ b/src/archutils/Unix/Backtrace.cpp @@ -2,13 +2,17 @@ #include "Backtrace.h" #include "RageUtil.h" +#if defined(HAVE_UNISTD_H) #include +#endif #include #include #include #include #include +#if defined(HAVE_FCNTL_H) #include +#endif #if defined(BACKTRACE_METHOD_X86_LINUX) #include "archutils/Common/PthreadHelpers.h" diff --git a/src/archutils/Unix/BacktraceNames.cpp b/src/archutils/Unix/BacktraceNames.cpp index 016ab7a79f..a5aee0221a 100644 --- a/src/archutils/Unix/BacktraceNames.cpp +++ b/src/archutils/Unix/BacktraceNames.cpp @@ -6,7 +6,9 @@ #include #include #include +#if defined(HAVE_UNISTD_H) #include +#endif #include #include diff --git a/src/archutils/Unix/CrashHandler.cpp b/src/archutils/Unix/CrashHandler.cpp index abbef3de25..323abcd365 100644 --- a/src/archutils/Unix/CrashHandler.cpp +++ b/src/archutils/Unix/CrashHandler.cpp @@ -3,10 +3,14 @@ #include #include #include +#if defined(HAVE_UNISTD_H) #include +#endif #include #include +#if defined(HAVE_FCNTL_H) #include +#endif #include #include "RageLog.h" /* for RageLog::GetAdditionalLog, etc, only */ diff --git a/src/archutils/Unix/GetSysInfo.cpp b/src/archutils/Unix/GetSysInfo.cpp index 1eaaa9bd37..bfa3d5024b 100644 --- a/src/archutils/Unix/GetSysInfo.cpp +++ b/src/archutils/Unix/GetSysInfo.cpp @@ -1,7 +1,9 @@ #include "global.h" #include "GetSysInfo.h" +#if defined(HAVE_SYS_UTSNAME_H) #include +#endif void GetKernel( RString &sys, int &iVersion ) { diff --git a/src/archutils/Unix/SignalHandler.cpp b/src/archutils/Unix/SignalHandler.cpp index 41bcea2de6..adfc9891cb 100644 --- a/src/archutils/Unix/SignalHandler.cpp +++ b/src/archutils/Unix/SignalHandler.cpp @@ -8,7 +8,9 @@ #include "archutils/Common/PthreadHelpers.h" #endif +#if defined(HAVE_UNISTD_H) #include +#endif #include #include diff --git a/src/archutils/Unix/arch_setup.h b/src/archutils/Unix/arch_setup.h index 165ce532a7..ad393a2a04 100644 --- a/src/archutils/Unix/arch_setup.h +++ b/src/archutils/Unix/arch_setup.h @@ -9,7 +9,7 @@ #include #endif -#if !defined(MISSING_STDINT_H) /* need to define int64_t if so */ +#if defined(HAVE_STDINT_H) /* need to define int64_t if so */ #include #endif @@ -19,13 +19,7 @@ #ifdef BSD #undef ALIGN #undef MACHINE -#if defined(__NetBSD_Version__) && __NetBSD_Version__ < 299000900 -#define lrintf(x) ((int)rint(x)) #endif -#endif - -/* For RageLog */ -#define HAVE_VERSION_INFO #include "archutils/Common/gcc_byte_swaps.h" diff --git a/src/archutils/Win32/CrashHandlerChild.cpp b/src/archutils/Win32/CrashHandlerChild.cpp index 4914348541..b3eefd601f 100644 --- a/src/archutils/Win32/CrashHandlerChild.cpp +++ b/src/archutils/Win32/CrashHandlerChild.cpp @@ -7,7 +7,9 @@ #include #include "archutils/Win32/ddk/dbghelp.h" #include +#if defined(HAVE_FCNTL_H) #include +#endif #include #include "arch/ArchHooks/ArchHooks.h" diff --git a/src/archutils/Win32/arch_setup.h b/src/archutils/Win32/arch_setup.h index 576cb0c89c..4fc0ace9dc 100644 --- a/src/archutils/Win32/arch_setup.h +++ b/src/archutils/Win32/arch_setup.h @@ -24,8 +24,6 @@ #pragma warning (disable : 4005) // macro redefinitions (ARRAYSIZE) #endif -#define snprintf _snprintf // Unsure if this goes with __MINGW32__ right now. - /* The following warnings are disabled in all builds. Enable them in the project file at your peril (or if you feel like @@ -82,7 +80,6 @@ C4355: 'this' : used in base member initializer list #endif -#include // has stuff that should be in unistd.h #include // needs to be included before our fixes below #define lstat stat @@ -90,9 +87,6 @@ C4355: 'this' : used in base member initializer list #define isnan _isnan #define isfinite _finite -// mkdir is missing the mode arg -#define mkdir(p,m) mkdir(p) - typedef time_t time_t; struct tm; struct tm *my_localtime_r( const time_t *timep, struct tm *result ); @@ -135,43 +129,12 @@ int64_t llabs( int64_t i ) { return i >= 0 ? i : -i; } #undef max #define NOMINMAX // make sure Windows doesn't try to define this -// Windows is missing some basic math functions: -// But MinGW isn't. -#if !defined(__MINGW32__) && (!defined(_MSC_VER) || _MSC_VER < 1700) // cstdint and truncf were first implemented in Visual Studio 2012 -#define NEED_TRUNCF -#define MISSING_STDINT_H -#endif - -// MinGW provides us with this function already - -#if !defined(__MINGW32__) && (!defined(_MSC_VER) || _MSC_VER < 1800) // lrintf, roundf and strtof were first implemented in Visual Studio 2013 -#define NEED_ROUNDF -#define NEED_STRTOF -inline long int lrintf( float f ) -{ - int retval; - - _asm fld f; - _asm fistp retval; - - return retval; -} -#endif - -// For RageLog. -#define HAVE_VERSION_INFO - /* We implement the crash handler interface (though that interface isn't * completely uniform across platforms yet). */ #if !defined(SMPACKAGE) #define CRASH_HANDLER #endif -// autoconf does this for us -#if !defined(__MINGW32__) -#define ENDIAN_LITTLE -#endif - #if defined(__GNUC__) // It might be MinGW or Cygwin(?) #include "archutils/Common/gcc_byte_swaps.h" #elif defined(_MSC_VER) && (_MSC_VER >= 1310) // Byte swap functions were first implemented in Visual Studio .NET 2003 diff --git a/src/config.in.hpp b/src/config.in.hpp new file mode 100644 index 0000000000..be4369c870 --- /dev/null +++ b/src/config.in.hpp @@ -0,0 +1,249 @@ +#ifndef CONFIG_HPP_ +#define CONFIG_HPP_ + +/* Auto-generated config.h file powered by cmake. */ + +/* Defined to 1 if is found. */ +#cmakedefine HAVE_ALLOCA_H 1 + +/* Defined to 1 if is found. */ +#cmakedefine HAVE_DIRENT_H 1 + +/* Defined to 1 if is found. */ +#cmakedefine HAVE_INTTYPES_H 1 + +/* Defined to 1 if is found. */ +#cmakedefine HAVE_STDINT_H 1 + +/* Defined to 1 if is found. */ +#cmakedefine HAVE_ENDIAN_H 1 + +/* Defined to 1 if is found. */ +#cmakedefine HAVE_SYS_ENDIAN_H 1 + +/* Defined to 1 if is found. */ +#cmakedefine HAVE_MACHINE_ENDIAN_H 1 + +/* Defined to 1 if is found. */ +#cmakedefine HAVE_SYS_PARAM_H 1 + +/* Defined to 1 if is found. */ +#cmakedefine HAVE_SYS_UTSNAME_H 1 + +/* Defined to 1 if is found. */ +#cmakedefine HAVE_FCNTL_H 1 + +/* Defined to 1 if is found. */ +#cmakedefine HAVE_UNISTD_H 1 + +/* Defined to 1 if the underlying system provides the _mkdir function. */ +#cmakedefine HAVE__MKDIR 1 + +/* Defined to 1 if the underlying system provides the mkdir function. */ +#cmakedefine HAVE_MKDIR 1 + +/* Defined to 1 if the underlying system provides the _snprintf function. */ +#cmakedefine HAVE__SNPRINTF 1 + +/* Defined to 1 if the underlying system provides the snprintf function. */ +#cmakedefine HAVE_SNPRINTF 1 + +/* Defined to 1 if the underlying system provides the powf function. */ +#cmakedefine HAVE_POWF 1 + +/* Defined to 1 if the underlying system provides the sqrtf function. */ +#cmakedefine HAVE_SQRTF 1 + +/* Defined to 1 if the underlying system provides the sinf function. */ +#cmakedefine HAVE_SINF 1 + +/* Defined to 1 if the underlying system provides the tanf function. */ +#cmakedefine HAVE_TANF 1 + +/* Defined to 1 if the underlying system provides the cos function. */ +#cmakedefine HAVE_COSF 1 + +/* Defined to 1 if the underlying system provides the acos function. */ +#cmakedefine HAVE_ACOSF 1 + +/* Defined to 1 if the underlying system provides the truncf function. */ +#cmakedefine HAVE_TRUNCF 1 + +/* Defined to 1 if the underlying system provides the roundf function. */ +#cmakedefine HAVE_ROUNDF 1 + +/* Defined to 1 if the underlying system provides the lrintf function. */ +#cmakedefine HAVE_LRINTF 1 + +/* Defined to 1 if the underlying system provides the strtof function. */ +#cmakedefine HAVE_STRTOF 1 + +/* Defined to 1 if the underlying system provides the M_PI constant. */ +#cmakedefine HAVE_M_PI 1 + +/* Provide a fallback if intptr_t is not defined. */ +#cmakedefine HAVE_SIZEOF_INTPTR_T 1 +#if !defined(HAVE_SIZEOF_INTPTR_T) +typedef unsigned int intptr_t; +#endif + +/* Provide a fallback if pid_t is not defined. */ +#cmakedefine HAVE_SIZEOF_PID_T 1 +#if !defined(HAVE_SIZEOF_PID_T) +typedef int pid_t; +#endif + +/* Provide a fallback if size_t is not defined. */ +#cmakedefine HAVE_SIZEOF_SIZE_T 1 +#if !defined(HAVE_SIZEOF_SIZE_T) +typedef unsigned long size_t; +#endif + +/* Provide a fallback if ssize_t is not defined. */ +#cmakedefine HAVE_SIZEOF_SSIZE_T 1 +#if !defined(HAVE_SIZEOF_SSIZE_T) +typedef long ssize_t; +#endif + +/* Defined to 1 if the underlying system uses little endian. */ +#cmakedefine ENDIAN_LITTLE 1 + +/* Defined to 1 if the underlying system uses big endian. */ +#cmakedefine ENDIAN_BIG 1 + +/* Defined to 1 if version information will be printed out. */ +#cmakedefine HAVE_VERSION_INFO 1 + +#if defined(__GNUC__) +/** @brief Define a macro to tell the compiler that a function has printf() + * semantics, to aid warning output. */ +#define PRINTF(a,b) __attribute__((format(__printf__,a,b))) +#define CONST_FUNCTION __attribute__((const)) +#else +/** @brief A dummy define to keep things going smoothly. */ +#define PRINTF(a,b) +/** @brief A dummy define to keep things going smoothly. */ +#define CONST_FUNCTION +#endif + +/* Ensure we have a function that acts like a size limited sprintf. */ +#if defined(HAVE__SNPRINTF) +#define snprintf _snprintf +#elif !defined(HAVE_SNPRINTF) +#error "No size limited sprintf function available. Aborting." +#endif + +/* Ensure we have a function that can create a directory on the file system. */ +#if defined(HAVE__MKDIR) +#include +#define mkdir(path, mode) _mkdir(path) +#else +#if !defined(HAVE_MKDIR) +#error "No create directory function available. Aborting." +#else +#include +#include +#if defined(__MINGW32__) || defined(__MINGW64__) +#define mkdir(path, mode) mkdir(path) +#endif +#endif +#endif + +/* Ensure we have a function for raising a number by a power to a float. */ +#if !defined(HAVE_POWF) +inline float powf( float x, float y ) CONST_FUNCTION; +float powf( float x, float y ) { return float( pow(double(x), double(y)) ); } +#endif + +/* Ensure we have a function for getting the square root of a number to a float. */ +#if !defined(HAVE_SQRTF) +inline float sqrtf( float x ) CONST_FUNCTION; +float sqrtf( float x ) { return float( sqrt(double(x)) ); } +#endif + +/* Ensure we have a function for getting the sin of a number to a float. */ +#if !defined(HAVE_SINF) +inline float sinf( float x ) CONST_FUNCTION; +float sinf( float x ) { return float( sin(double(x)) ); } +#endif + +/* Ensure we have a function for getting the tan of a number to a float. */ +#if !defined(HAVE_TANF) +inline float tanf( float x ) CONST_FUNCTION; +float tanf( float x ) { return float( tan(double(x)) ); } +#endif + +/* Ensure we have a function for getting the cos of a number to a float. */ +#if !defined(HAVE_COSF) +inline float cosf( float x ) CONST_FUNCTION; +float cosf( float x ){ return float( cos(double(x)) ); } +#endif + +/* Ensure we have a function for getting the arc cos of a number to a float. */ +#if !defined(HAVE_ACOSF) +inline float acosf( float x ) CONST_FUNCTION; +float acosf( float x ) { return float( acos(double(x)) ); } +#endif + +/* Ensure we have a function for truncating a number to a float. */ +#if !defined(HAVE_TRUNCF) +inline float truncf( float f ) CONST_FUNCTION; +float truncf( float f ) { return float( int(f) ); } +#endif + +/* Ensure we have a function for rounding a number to a float. */ +#if !defined(HAVE_ROUNDF) +inline float roundf( float f ) CONST_FUNCTION; +float roundf( float f ) { if( f < 0.0f ) return truncf( f-0.5f ); return truncf( f+0.5f ); } +#endif + +/* Ensure we have a function for converting a string to a float. */ +#if !defined(HAVE_STRTOF) +inline float strtof( const char *s, char **se ) { return (float) strtod( s, se ); } +#endif + +#if !defined(HAVE_LRINTF) +#if defined(_MSC_VER) +inline long lrintf( float f ) +{ + int retval; + + _asm fld f; + _asm fistp retval; + + return retval; +} +#else +#define lrintf(x) ((int)rint(x)) +#endif +#endif + +#if !defined(HAVE_M_PI) +/* This is only called if the math header files don't include it: stating it here is fine. */ +#define M_PI 3.1415926535897932384626433832795 +#endif + +/* Ensure we have an endianness defined. */ +#if !defined(ENDIAN_LITTLE) && !defined(ENDIAN_BIG) +#error "Neither ENDIAN_LITTLE nor ENDIAN_BIG defined. Aborting." +#endif + +/* Define standard endianness macros, if they're missing. */ +#if defined(HAVE_ENDIAN_H) +#include +#elif defined(HAVE_MACHINE_ENDIAN_H) +#include +#else +/** @brief The macro for little endian order. */ +#define LITTLE_ENDIAN 1234 +/** @brief The macro for big endian order. */ +#define BIG_ENDIAN 4321 +#if defined(ENDIAN_LITTLE) +#define BYTE_ORDER LITTLE_ENDIAN +#elif defined(ENDIAN_BIG) +#define BYTE_ORDER BIG_ENDIAN +#endif + +#endif + +#endif diff --git a/src/ezsockets.cpp b/src/ezsockets.cpp index 18a4d8ee3e..88125b9b26 100644 --- a/src/ezsockets.cpp +++ b/src/ezsockets.cpp @@ -15,7 +15,9 @@ #elif !defined(__MINGW32__) #include #include +#if defined(HAVE_UNISTD_H) #include +#endif #include #include #endif diff --git a/src/ezsockets.h b/src/ezsockets.h index a679cd4e94..4a7c8b6b9c 100644 --- a/src/ezsockets.h +++ b/src/ezsockets.h @@ -16,7 +16,9 @@ #include #include #include +#if defined(HAVE_FCNTL_H) #include +#endif #include #if defined(_WINDOWS) diff --git a/src/global.cpp b/src/global.cpp index b1791c03e8..080c7abd29 100644 --- a/src/global.cpp +++ b/src/global.cpp @@ -1,5 +1,9 @@ #include "global.h" +#if defined(HAVE_UNISTD_H) +#include +#endif + #if defined(_WINDOWS) # if defined(CRASH_HANDLER) # define _WIN32_WINDOWS 0x0410 // include Win98 stuff @@ -9,11 +13,8 @@ #elif defined(MACOSX) # include "archutils/Darwin/Crash.h" # include -# include using CrashHandler::IsDebuggerPresent; using CrashHandler::DebugBreak; -#else -# include #endif #if defined(CRASH_HANDLER) && (defined(UNIX) || defined(MACOSX)) diff --git a/src/global.h b/src/global.h index b76ca3912f..67f4156d0b 100644 --- a/src/global.h +++ b/src/global.h @@ -1,7 +1,9 @@ #ifndef GLOBAL_H #define GLOBAL_H -#ifdef HAVE_CONFIG_H +#if defined(CMAKE_POWERED) +#include "config.hpp" +#elif defined(HAVE_CONFIG_H) #include "config.h" #endif @@ -23,30 +25,6 @@ #include "archutils/Unix/arch_setup.h" #endif -/* Set one of these in arch_setup.h. (Don't bother trying to fall back on BYTE_ORDER - * if it was already set; too many systems are missing endian.h.) */ -#if !defined(ENDIAN_LITTLE) && !defined(ENDIAN_BIG) -#error Neither ENDIAN_LITTLE nor ENDIAN_BIG defined -#endif - -/* Define standard endianness macros, if they're missing. */ -#if defined(HAVE_ENDIAN_H) -#include -#elif defined(HAVE_MACHINE_ENDIAN_H) -#include -#else -/** @brief The macro for little endian order. */ -#define LITTLE_ENDIAN 1234 -/** @brief The macro for big endian order. */ -#define BIG_ENDIAN 4321 -#if defined(ENDIAN_LITTLE) -#define BYTE_ORDER LITTLE_ENDIAN -#elif defined(ENDIAN_BIG) -#define BYTE_ORDER BIG_ENDIAN -#endif - -#endif - /* Make sure everyone has min and max: */ #include @@ -56,7 +34,7 @@ /* And vector: */ #include -#if !defined(MISSING_STDINT_H) /* need to define int64_t if so */ +#if defined(HAVE_STDINT_H) /* need to define int64_t if so */ #include #endif #if defined(HAVE_INTTYPES_H) @@ -108,7 +86,7 @@ namespace Checkpoints #endif /** - * @brief A crash has occured, and we're not getting out of it easily. + * @brief A crash has occurred, and we're not getting out of it easily. * * For most users, this will result in a crashinfo.txt file being generated. * For anyone that is using a debug build, a debug break will be thrown to @@ -165,18 +143,6 @@ template <> struct CompileAssert { }; template struct CompileAssertDecl { }; #define COMPILE_ASSERT(COND) typedef CompileAssertDecl< sizeof(CompileAssert) > CompileAssertInst -#if defined(__GNUC__) -/** @brief Define a macro to tell the compiler that a function has printf() - * semantics, to aid warning output. */ -#define PRINTF(a,b) __attribute__((format(__printf__,a,b))) -#define CONST_FUNCTION __attribute__((const)) -#else -/** @brief A dummy define to keep things going smoothly. */ -#define PRINTF(a,b) -/** @brief A dummy define to keep things going smoothly. */ -#define CONST_FUNCTION -#endif - #include "StdString.h" /** @brief Use RStrings throughout the program. */ typedef StdString::CStdString RString; @@ -193,55 +159,6 @@ typedef StdString::CStdString RString; /* Define a few functions if necessary */ #include -#ifndef M_PI -/** @brief Define Pi to many digits. */ -#define M_PI 3.1415926535897932384626433832795 -#endif - -#ifdef NEED_POWF -inline float powf( float x, float y ) CONST_FUNCTION; -float powf( float x, float y ) { return float( pow(double(x), double(y)) ); } -#endif - -#ifdef NEED_SQRTF -inline float sqrtf( float x ) CONST_FUNCTION; -float sqrtf( float x ) { return float( sqrt(double(x)) ); } -#endif - -#ifdef NEED_SINF -inline float sinf( float x ) CONST_FUNCTION; -float sinf( float x ) { return float( sin(double(x)) ); } -#endif - -#ifdef NEED_TANF -inline float tanf( float x ) CONST_FUNCTION; -float tanf( float x ) { return float( tan(double(x)) ); } -#endif - -#ifdef NEED_COSF -inline float cosf( float x ) CONST_FUNCTION; -float cosf( float x ){ return float( cos(double(x)) ); } -#endif - -#ifdef NEED_ACOSF -inline float acosf( float x ) CONST_FUNCTION; -float acosf( float x ) { return float( acos(double(x)) ); } -#endif - -#ifdef NEED_TRUNCF -inline float truncf( float f ) CONST_FUNCTION; -float truncf( float f ) { return float( int(f) ); } -#endif - -#ifdef NEED_ROUNDF -inline float roundf( float f ) CONST_FUNCTION; -float roundf( float f ) { if( f < 0.0f ) return truncf( f-0.5f ); return truncf( f+0.5f ); } -#endif - -#ifdef NEED_STRTOF -inline float strtof( const char *s, char **se ) { return (float) strtod( s, se ); } -#endif - /* Don't include our own headers here, since they tend to change often. */ #endif