From 08dae0c605188c1d9eb33497b959a4baade2a3b3 Mon Sep 17 00:00:00 2001 From: Yamagi Burmeister Date: Tue, 12 Apr 2016 19:21:10 +0200 Subject: [PATCH 1/4] Add FreeBSD defined to CMakeLists.txt - Detect FreeBSD. - Set both PLATFORM_UNIX and PLATFORM_FREEBSD. The latter is required to distinguish FreeBSD from other unixoid platforms like Linux. - On FreeBSD 3rd party libs are installed to /usr/local, we need to add /usr/local/include as include directory. - Add linker options for FreeBSD. FreeBSD has no -ldl. --- Sources/CMakeLists.txt | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/Sources/CMakeLists.txt b/Sources/CMakeLists.txt index 30e7290..c5cc838 100644 --- a/Sources/CMakeLists.txt +++ b/Sources/CMakeLists.txt @@ -28,6 +28,9 @@ endif() if(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME MATCHES "GNU|kFreeBSD") SET(LINUX TRUE) endif() +if(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD") + SET(FREEBSD TRUE) +endif() if(APPLE) SET(MACOSX TRUE) endif() @@ -71,6 +74,16 @@ if(LINUX) add_definitions(-DPRAGMA_ONCE=1) endif() +if(FREEBSD) + set(CMAKE_SKIP_RPATH ON CACHE BOOL "Skip RPATH" FORCE) + add_definitions(-DPLATFORM_UNIX=1) + add_definitions(-DPLATFORM_FREEBSD=1) + add_definitions(-D_FILE_OFFSET_BITS=64) + add_definitions(-D_LARGEFILE_SOURCE=1) + add_definitions(-DPRAGMA_ONCE=1) + include_directories("/usr/local/include") +endif() + if(MACOSX) add_definitions(-DPLATFORM_UNIX=1) add_definitions(-DPLATFORM_MACOSX=1) @@ -826,6 +839,19 @@ if(LINUX) endif() endif() +if(FREEBSD) + set_target_properties(ssam PROPERTIES LINK_FLAGS "-Wl,-rpath,$ORIGIN") + target_link_libraries(ssam "m") + target_link_libraries(ssam "pthread") + target_link_libraries(ssam ${SDL2_LIBRARY}) + if(BUILD_DEDICATED_SERVER) + set_target_properties(SeriousSamDedicated PROPERTIES LINK_FLAGS "-Wl,-rpath,$ORIGIN") + target_link_libraries(SeriousSamDedicated "m") + target_link_libraries(SeriousSamDedicated "pthread") + target_link_libraries(SeriousSamDedicated ${SDL2_LIBRARY}) + endif() +endif() + if(TFE) set_target_properties(ssam PROPERTIES OUTPUT_NAME "ssam-tfe") endif() From d1d9c8d094d2f3345503caffd75cc57be9fd547f Mon Sep 17 00:00:00 2001 From: Yamagi Burmeister Date: Tue, 12 Apr 2016 19:24:57 +0200 Subject: [PATCH 2/4] There's no malloc.h on FreeBSD. Like in OS X malloc() is part of stdlib.h. --- Sources/Ecc/StdH.h | 2 +- Sources/Engine/Engine.h | 2 +- Sources/Engine/StdH.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/Ecc/StdH.h b/Sources/Ecc/StdH.h index 8c19296..1b048a0 100644 --- a/Sources/Ecc/StdH.h +++ b/Sources/Ecc/StdH.h @@ -21,7 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include #include -#if !PLATFORM_MACOSX +#if !defined(PLATFORM_MACOSX) && !defined(PLATFORM_FREEBSD) #include #endif diff --git a/Sources/Engine/Engine.h b/Sources/Engine/Engine.h index eb17bdf..d63fae4 100644 --- a/Sources/Engine/Engine.h +++ b/Sources/Engine/Engine.h @@ -38,7 +38,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include // for qsort #include // for FPU control -#if !PLATFORM_MACOSX +#if !defined(PLATFORM_MACOSX) && !defined(PLATFORM_FREEBSD) #include #endif diff --git a/Sources/Engine/StdH.h b/Sources/Engine/StdH.h index 61fae43..d889b87 100644 --- a/Sources/Engine/StdH.h +++ b/Sources/Engine/StdH.h @@ -27,7 +27,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include // for qsort #include // for FPU control -#if !PLATFORM_MACOSX +#if !defined(PLATFORM_MACOSX) && !defined(PLATFORM_FREEBSD) #include #endif From b299789db5cf623d7976f1c5359b71cbb4c7d682 Mon Sep 17 00:00:00 2001 From: Yamagi Burmeister Date: Tue, 12 Apr 2016 19:25:58 +0200 Subject: [PATCH 3/4] mntent.h is another linuxism and unnecessary on FreeBSD. --- Sources/SeriousSam/SeriousSam.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/SeriousSam/SeriousSam.cpp b/Sources/SeriousSam/SeriousSam.cpp index fa487d3..9b76471 100644 --- a/Sources/SeriousSam/SeriousSam.cpp +++ b/Sources/SeriousSam/SeriousSam.cpp @@ -23,7 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc., // !!! FIXME: rcg01082002 Do something with these. #ifdef PLATFORM_UNIX #include - #if !PLATFORM_MACOSX + #if !defined(PLATFORM_MACOSX) && !defined(PLATFORM_FREEBSD) #include #endif #endif From 0e672b866e36b47de70a583615ff76364e999275 Mon Sep 17 00:00:00 2001 From: Yamagi Burmeister Date: Wed, 13 Apr 2016 19:24:51 +0200 Subject: [PATCH 4/4] Determine CPU speed on FreeBSD --- Sources/Engine/Base/Timer.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Sources/Engine/Base/Timer.cpp b/Sources/Engine/Base/Timer.cpp index 43be607..8922297 100644 --- a/Sources/Engine/Base/Timer.cpp +++ b/Sources/Engine/Base/Timer.cpp @@ -37,6 +37,11 @@ with this program; if not, write to the Free Software Foundation, Inc., #include #endif +#if PLATFORM_FREEBSD +#include +#include +#endif + // Read the Pentium TimeStampCounter (or something like that). static inline __int64 ReadTSC(void) { @@ -340,6 +345,13 @@ CTimer::CTimer(BOOL bInterrupt /*=TRUE*/) #elif PLATFORM_MACOSX tm_llPerformanceCounterFrequency = tm_llCPUSpeedHZ = ((__int64) GetCPUSpeed()) * 1000000; +#elif PLATFORM_FREEBSD + __int64 mhz = 0; + size_t len = sizeof(mhz); + + sysctlbyname("hw.clockrate", &mhz, &len, NULL, 0); + tm_llPerformanceCounterFrequency = tm_llCPUSpeedHZ = (__int64) (mhz * 1000000); + #else // !!! FIXME : This is an ugly hack. double mhz = 0.0;