Skip to content

Commit

Permalink
Adding FreeBSD build support.
Browse files Browse the repository at this point in the history
  • Loading branch information
LadySerenaKitty committed Feb 2, 2024
1 parent ec69aba commit ede75ed
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 5 deletions.
2 changes: 2 additions & 0 deletions BuildTools/CMake/BuildUtils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,8 @@ function(add_format_validation_target MODULE_NAME MODULE_ROOT_PATH IDE_FOLDER)
set(RUN_VALIDATION_SCRIPT validate_format_win.bat)
elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux")
set(RUN_VALIDATION_SCRIPT ./validate_format_linux.sh)
elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "FreeBSD")
set(RUN_VALIDATION_SCRIPT ./validate_format_freebsd.sh)
elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin")
set(RUN_VALIDATION_SCRIPT ./validate_format_mac.sh)
else()
Expand Down
2 changes: 2 additions & 0 deletions BuildTools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux")
set(CLANG_FORMAT_EXECUTABLE "${CMAKE_CURRENT_SOURCE_DIR}/FormatValidation/clang-format_linux_10.0.0" CACHE INTERNAL "clang-format executable path")
elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin")
set(CLANG_FORMAT_EXECUTABLE "${CMAKE_CURRENT_SOURCE_DIR}/FormatValidation/clang-format_mac_10.0.0" CACHE INTERNAL "clang-format executable path")
elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "FreeBSD")
set(CLANG_FORMAT_EXECUTABLE "/usr/local/llvm10/bin/clang-format" CACHE INTERNAL "clang-format executable path")
endif()

if (NOT EXISTS ${CLANG_FORMAT_EXECUTABLE})
Expand Down
11 changes: 11 additions & 0 deletions BuildTools/FormatValidation/validate_format_freebsd.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/local/bin/bash

source validate_format_freebsd_implementation.sh

validate_format ../../Common ../../Graphics ../../Platforms ../../Primitives ../../Tests \
--exclude ../../Graphics/HLSL2GLSLConverterLib/include/GLSLDefinitions.h \
--exclude ../../Graphics/HLSL2GLSLConverterLib/include/GLSLDefinitions_inc.h \
--exclude ../../Graphics/GraphicsEngineVulkan/shaders \
--exclude ../../Graphics/GraphicsEngine.NET \
--exclude ../../Tests/DiligentCoreAPITest/assets

Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/local/bin/bash

## Get the path of this file no matter where it is called from
## Solution from: https://stackoverflow.com/a/246128/2140449
VALIDATE_FORMAT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"

errcho(){ echo "$@" 1>&2; }

function find_validator_bin() {
local BIN=$(find "$VALIDATE_FORMAT_DIR" -name 'clang-format_freebsd_*')

## Try to launch the bin
eval "$BIN --version >/dev/null 2> /dev/null"
if [ $? -ne 0 ]; then
## BIN failed to run, try to get a system installed clang-format
local SYS_BIN=$(which clang-format 2> /dev/null)
if [ $? -ne 0 ]; then
errcho "WARNING: skipping format validation as no suitable executable was found"
BIN=""
else
local BIN_VERSION=$(echo $BIN | grep -Eo '[0-9]+\.[0-9]+\.[0-9]+')
local SYS_BIN_VERSION=$(eval "$SYS_BIN --version" | grep -Eo '[0-9]+\.[0-9]+\.[0-9]+')
if [ "$BIN_VERSION" != "$SYS_BIN_VERSION" ]; then
errcho "WARNING: could not load the provided clang-format for validation."
errcho " clang-format exists in the system path however its version is $SYS_BIN_VERSION instead of $BIN_VERSION"
errcho " Should the validation fail, you can try skipping it by setting the cmake option:"
errcho " DILIGENT_NO_FORMAT_VALIDATION"
fi
BIN="$SYS_BIN"
fi
fi
echo "$BIN"
}

function validate_format() {
local BIN=$(find_validator_bin)
if [ ! -z "$BIN" ]; then
python3.9 "$VALIDATE_FORMAT_DIR/clang-format-validate.py" --clang-format-executable "$BIN" -r "$@"
fi
}

## Example usage:
#
# #!/bin/bash
# source /PATH/TO/THIS/FILE/validate_format_linux_implementation.sh
#
# validate_format ../../Common ../../Graphics ../../Platforms ../../Primitives ../../Tests \
# --exclude ../../Graphics/HLSL2GLSLConverterLib/include/GLSLDefinitions.h \
# --exclude ../../Graphics/HLSL2GLSLConverterLib/include/GLSLDefinitions_inc.h \
# --exclude ../../Graphics/GraphicsEngineVulkan/shaders/GenerateMipsCS_inc.h \
# --exclude ../../Tests/DiligentCoreAPITest/assets/*
#
14 changes: 13 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ set(PLATFORM_WIN32 FALSE CACHE INTERNAL "")
set(PLATFORM_UNIVERSAL_WINDOWS FALSE CACHE INTERNAL "")
set(PLATFORM_ANDROID FALSE CACHE INTERNAL "")
set(PLATFORM_LINUX FALSE CACHE INTERNAL "")
set(PLATFORM_FREEBSD FALSE CACHE INTERNAL "")
set(PLATFORM_MACOS FALSE CACHE INTERNAL "")
set(PLATFORM_IOS FALSE CACHE INTERNAL "")
set(PLATFORM_TVOS FALSE CACHE INTERNAL "")
Expand Down Expand Up @@ -125,6 +126,10 @@ else()
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
set(PLATFORM_LINUX TRUE CACHE INTERNAL "Target platform: Linux")
message("Target platform: Linux " ${ARCH})
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD")
set(PLATFORM_LINUX TRUE CACHE INTERNAL "Target platform: Linux")
set(PLATFORM_FREEBSD TRUE CACHE INTERNAL "Target platform: FreeBSD")
message("Target platform: FreeBSD " ${ARCH})
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
if(IOS)
set(PLATFORM_IOS TRUE CACHE INTERNAL "Target platform: iOS")
Expand Down Expand Up @@ -197,7 +202,14 @@ elseif(PLATFORM_LINUX)
set(GL_SUPPORTED TRUE CACHE INTERNAL "OpenGL is supported on Linux platform")
set(VULKAN_SUPPORTED TRUE CACHE INTERNAL "Vulkan is supported on Linux platform")
set(ARCHIVER_SUPPORTED TRUE CACHE INTERNAL "Archiver is supported on Linux platform")
target_compile_definitions(Diligent-PublicBuildSettings INTERFACE PLATFORM_LINUX=1)
if(PLATFORM_FREEBSD)
target_compile_definitions(Diligent-PublicBuildSettings INTERFACE PLATFORM_LINUX=1 PLATFORM_FREEBSD=1)
if(EXISTS /usr/local/include)
include_directories(/usr/local/include)
endif()
else()
target_compile_definitions(Diligent-PublicBuildSettings INTERFACE PLATFORM_LINUX=1)
endif()
elseif(PLATFORM_MACOS)
set(GL_SUPPORTED TRUE CACHE INTERNAL "OpenGL is supported on MacOS platform")
set(VULKAN_SUPPORTED TRUE CACHE INTERNAL "Vulkan is enabled through MoltenVK on MacOS platform")
Expand Down
13 changes: 10 additions & 3 deletions Graphics/Archiver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,14 @@ if(GL_SUPPORTED OR GLES_SUPPORTED)
if(PLATFORM_WIN32)
target_link_libraries(Diligent-Archiver-static PRIVATE GLEW::glew opengl32.lib)
elseif(PLATFORM_LINUX)
target_link_libraries(Diligent-Archiver-static PRIVATE GLEW::glew GL X11)
if(PLATFORM_FREEBSD)
find_package(OpenGL REQUIRED)
find_package(X11 REQUIRED)
else()
set(OPENGL_gl_LIBRARY GL)
set(X11_LIBRARIES X11)
endif()
target_link_libraries(Diligent-Archiver-static PRIVATE GLEW::glew ${OPENGL_gl_LIBRARY} ${X11_LIBRARIES})
elseif(PLATFORM_MACOS)
find_package(OpenGL REQUIRED)
target_link_libraries(Diligent-Archiver-static PRIVATE GLEW::glew ${OPENGL_LIBRARY})
Expand All @@ -146,11 +153,11 @@ endif()
if(METAL_SUPPORTED)
target_link_libraries(Diligent-Archiver-static
PRIVATE
Diligent-GraphicsEngineMetal-static
Diligent-GraphicsEngineMetal-static
spirv-cross-core
spirv-cross-msl
spirv-cross-glsl
)
)
target_include_directories(Diligent-Archiver-static PRIVATE ../../../DiligentCorePro/Graphics/GraphicsEngineMetal/include)
endif()

Expand Down
9 changes: 8 additions & 1 deletion Graphics/GraphicsEngineOpenGL/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,14 @@ if(PLATFORM_WIN32)
elseif(PLATFORM_ANDROID)
set(PRIVATE_DEPENDENCIES ${PRIVATE_DEPENDENCIES} GLESv3 EGL)
elseif(PLATFORM_LINUX)
set(PRIVATE_DEPENDENCIES ${PRIVATE_DEPENDENCIES} GLEW::glew GL X11)
if(PLATFORM_FREEBSD)
find_package(OpenGL REQUIRED)
find_package(X11 REQUIRED)
else()
set(OPENGL_gl_LIBRARY GL)
set(X11_LIBRARIES X11)
endif()
set(PRIVATE_DEPENDENCIES ${PRIVATE_DEPENDENCIES} GLEW::glew ${OPENGL_gl_LIBRARY} ${X11_LIBRARIES})
elseif(PLATFORM_MACOS)
find_package(OpenGL REQUIRED)
set(PRIVATE_DEPENDENCIES ${PRIVATE_DEPENDENCIES} GLEW::glew ${OPENGL_LIBRARY})
Expand Down
4 changes: 4 additions & 0 deletions Platforms/Linux/src/LinuxPlatformMisc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@

#include <pthread.h>

#ifdef PLATFORM_FREEBSD
#include <pthread_np.h>
#endif

namespace Diligent
{

Expand Down
2 changes: 2 additions & 0 deletions ThirdParty/DirectXShaderCompiler/dxc/WinAdapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,9 @@
#define __stdcall
#define __vectorcall
#define __thiscall
#ifndef PLATFORM_FREEBSD
#define __fastcall
#endif
#define __clrcall
#endif // __GNUC__

Expand Down

0 comments on commit ede75ed

Please sign in to comment.