Skip to content

Commit ce62f53

Browse files
Adding FreeBSD build support.
1 parent c2a8c2d commit ce62f53

File tree

9 files changed

+104
-5
lines changed

9 files changed

+104
-5
lines changed

BuildTools/CMake/BuildUtils.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,8 @@ function(add_format_validation_target MODULE_NAME MODULE_ROOT_PATH IDE_FOLDER)
397397
set(RUN_VALIDATION_SCRIPT validate_format_win.bat)
398398
elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux")
399399
set(RUN_VALIDATION_SCRIPT ./validate_format_linux.sh)
400+
elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "FreeBSD")
401+
set(RUN_VALIDATION_SCRIPT ./validate_format_freebsd.sh)
400402
elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin")
401403
set(RUN_VALIDATION_SCRIPT ./validate_format_mac.sh)
402404
endif()

BuildTools/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux")
88
set(CLANG_FORMAT_EXECUTABLE "${CMAKE_CURRENT_SOURCE_DIR}/FormatValidation/clang-format_linux_10.0.0" CACHE INTERNAL "clang-format executable path")
99
elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin")
1010
set(CLANG_FORMAT_EXECUTABLE "${CMAKE_CURRENT_SOURCE_DIR}/FormatValidation/clang-format_mac_10.0.0" CACHE INTERNAL "clang-format executable path")
11+
elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "FreeBSD")
12+
set(CLANG_FORMAT_EXECUTABLE "/usr/local/llvm10/bin/clang-format" CACHE INTERNAL "clang-format executable path")
1113
endif()
1214

1315
if (NOT EXISTS ${CLANG_FORMAT_EXECUTABLE})
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/local/bin/bash
2+
3+
source validate_format_freebsd_implementation.sh
4+
5+
validate_format ../../Common ../../Graphics ../../Platforms ../../Primitives ../../Tests \
6+
--exclude ../../Graphics/HLSL2GLSLConverterLib/include/GLSLDefinitions.h \
7+
--exclude ../../Graphics/HLSL2GLSLConverterLib/include/GLSLDefinitions_inc.h \
8+
--exclude ../../Graphics/GraphicsEngineVulkan/shaders \
9+
--exclude ../../Graphics/GraphicsEngine.NET \
10+
--exclude ../../Tests/DiligentCoreAPITest/assets
11+
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/usr/local/bin/bash
2+
3+
## Get the path of this file no matter where it is called from
4+
## Solution from: https://stackoverflow.com/a/246128/2140449
5+
VALIDATE_FORMAT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
6+
7+
errcho(){ echo "$@" 1>&2; }
8+
9+
function find_validator_bin() {
10+
local BIN=$(find "$VALIDATE_FORMAT_DIR" -name 'clang-format_freebsd_*')
11+
12+
## Try to launch the bin
13+
eval "$BIN --version >/dev/null 2> /dev/null"
14+
if [ $? -ne 0 ]; then
15+
## BIN failed to run, try to get a system installed clang-format
16+
local SYS_BIN=$(which clang-format 2> /dev/null)
17+
if [ $? -ne 0 ]; then
18+
errcho "WARNING: skipping format validation as no suitable executable was found"
19+
BIN=""
20+
else
21+
local BIN_VERSION=$(echo $BIN | grep -Eo '[0-9]+\.[0-9]+\.[0-9]+')
22+
local SYS_BIN_VERSION=$(eval "$SYS_BIN --version" | grep -Eo '[0-9]+\.[0-9]+\.[0-9]+')
23+
if [ "$BIN_VERSION" != "$SYS_BIN_VERSION" ]; then
24+
errcho "WARNING: could not load the provided clang-format for validation."
25+
errcho " clang-format exists in the system path however its version is $SYS_BIN_VERSION instead of $BIN_VERSION"
26+
errcho " Should the validation fail, you can try skipping it by setting the cmake option:"
27+
errcho " DILIGENT_NO_FORMAT_VALIDATION"
28+
fi
29+
BIN="$SYS_BIN"
30+
fi
31+
fi
32+
echo "$BIN"
33+
}
34+
35+
function validate_format() {
36+
local BIN=$(find_validator_bin)
37+
if [ ! -z "$BIN" ]; then
38+
python3.9 "$VALIDATE_FORMAT_DIR/clang-format-validate.py" --clang-format-executable "$BIN" -r "$@"
39+
fi
40+
}
41+
42+
## Example usage:
43+
#
44+
# #!/bin/bash
45+
# source /PATH/TO/THIS/FILE/validate_format_linux_implementation.sh
46+
#
47+
# validate_format ../../Common ../../Graphics ../../Platforms ../../Primitives ../../Tests \
48+
# --exclude ../../Graphics/HLSL2GLSLConverterLib/include/GLSLDefinitions.h \
49+
# --exclude ../../Graphics/HLSL2GLSLConverterLib/include/GLSLDefinitions_inc.h \
50+
# --exclude ../../Graphics/GraphicsEngineVulkan/shaders/GenerateMipsCS_inc.h \
51+
# --exclude ../../Tests/DiligentCoreAPITest/assets/*
52+
#

CMakeLists.txt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ set(PLATFORM_WIN32 FALSE CACHE INTERNAL "")
4444
set(PLATFORM_UNIVERSAL_WINDOWS FALSE CACHE INTERNAL "")
4545
set(PLATFORM_ANDROID FALSE CACHE INTERNAL "")
4646
set(PLATFORM_LINUX FALSE CACHE INTERNAL "")
47+
set(PLATFORM_FREEBSD FALSE CACHE INTERNAL "")
4748
set(PLATFORM_MACOS FALSE CACHE INTERNAL "")
4849
set(PLATFORM_IOS FALSE CACHE INTERNAL "")
4950
set(PLATFORM_TVOS FALSE CACHE INTERNAL "")
@@ -125,6 +126,10 @@ else()
125126
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
126127
set(PLATFORM_LINUX TRUE CACHE INTERNAL "Target platform: Linux")
127128
message("Target platform: Linux " ${ARCH})
129+
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD")
130+
set(PLATFORM_LINUX TRUE CACHE INTERNAL "Target platform: Linux")
131+
set(PLATFORM_FREEBSD TRUE CACHE INTERNAL "Target platform: FreeBSD")
132+
message("Target platform: FreeBSD " ${ARCH})
128133
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
129134
if(IOS)
130135
set(PLATFORM_IOS TRUE CACHE INTERNAL "Target platform: iOS")
@@ -197,7 +202,14 @@ elseif(PLATFORM_LINUX)
197202
set(GL_SUPPORTED TRUE CACHE INTERNAL "OpenGL is supported on Linux platform")
198203
set(VULKAN_SUPPORTED TRUE CACHE INTERNAL "Vulkan is supported on Linux platform")
199204
set(ARCHIVER_SUPPORTED TRUE CACHE INTERNAL "Archiver is supported on Linux platform")
200-
target_compile_definitions(Diligent-PublicBuildSettings INTERFACE PLATFORM_LINUX=1)
205+
if(PLATFORM_FREEBSD)
206+
target_compile_definitions(Diligent-PublicBuildSettings INTERFACE PLATFORM_LINUX=1 PLATFORM_FREEBSD=1)
207+
if(EXISTS /usr/local/include)
208+
include_directories(/usr/local/include)
209+
endif()
210+
else()
211+
target_compile_definitions(Diligent-PublicBuildSettings INTERFACE PLATFORM_LINUX=1)
212+
endif()
201213
elseif(PLATFORM_MACOS)
202214
set(GL_SUPPORTED TRUE CACHE INTERNAL "OpenGL is supported on MacOS platform")
203215
set(VULKAN_SUPPORTED TRUE CACHE INTERNAL "Vulkan is enabled through MoltenVK on MacOS platform")

Graphics/Archiver/CMakeLists.txt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,14 @@ if(GL_SUPPORTED OR GLES_SUPPORTED)
132132
if(PLATFORM_WIN32)
133133
target_link_libraries(Diligent-Archiver-static PRIVATE GLEW::glew opengl32.lib)
134134
elseif(PLATFORM_LINUX)
135-
target_link_libraries(Diligent-Archiver-static PRIVATE GLEW::glew GL X11)
135+
if(PLATFORM_FREEBSD)
136+
find_package(OpenGL REQUIRED)
137+
find_package(X11 REQUIRED)
138+
else()
139+
set(OPENGL_gl_LIBRARY GL)
140+
set(X11_LIBRARIES X11)
141+
endif()
142+
target_link_libraries(Diligent-Archiver-static PRIVATE GLEW::glew ${OPENGL_gl_LIBRARY} ${X11_LIBRARIES})
136143
elseif(PLATFORM_MACOS)
137144
find_package(OpenGL REQUIRED)
138145
target_link_libraries(Diligent-Archiver-static PRIVATE GLEW::glew ${OPENGL_LIBRARY})
@@ -146,11 +153,11 @@ endif()
146153
if(METAL_SUPPORTED)
147154
target_link_libraries(Diligent-Archiver-static
148155
PRIVATE
149-
Diligent-GraphicsEngineMetal-static
156+
Diligent-GraphicsEngineMetal-static
150157
spirv-cross-core
151158
spirv-cross-msl
152159
spirv-cross-glsl
153-
)
160+
)
154161
target_include_directories(Diligent-Archiver-static PRIVATE ../../../DiligentCorePro/Graphics/GraphicsEngineMetal/include)
155162
endif()
156163

Graphics/GraphicsEngineOpenGL/CMakeLists.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,14 @@ if(PLATFORM_WIN32)
198198
elseif(PLATFORM_ANDROID)
199199
set(PRIVATE_DEPENDENCIES ${PRIVATE_DEPENDENCIES} GLESv3 EGL)
200200
elseif(PLATFORM_LINUX)
201-
set(PRIVATE_DEPENDENCIES ${PRIVATE_DEPENDENCIES} GLEW::glew GL X11)
201+
if(PLATFORM_FREEBSD)
202+
find_package(OpenGL REQUIRED)
203+
find_package(X11 REQUIRED)
204+
else()
205+
set(OPENGL_gl_LIBRARY GL)
206+
set(X11_LIBRARIES X11)
207+
endif()
208+
set(PRIVATE_DEPENDENCIES ${PRIVATE_DEPENDENCIES} GLEW::glew ${OPENGL_gl_LIBRARY} ${X11_LIBRARIES})
202209
elseif(PLATFORM_MACOS)
203210
find_package(OpenGL REQUIRED)
204211
set(PRIVATE_DEPENDENCIES ${PRIVATE_DEPENDENCIES} GLEW::glew ${OPENGL_LIBRARY})

Platforms/Linux/src/LinuxPlatformMisc.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828

2929
#include <pthread.h>
3030

31+
#ifdef PLATFORM_FREEBSD
32+
#include <pthread_np.h>
33+
#endif
34+
3135
namespace Diligent
3236
{
3337

ThirdParty/DirectXShaderCompiler/dxc/WinAdapter.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,9 @@
342342
#define __stdcall
343343
#define __vectorcall
344344
#define __thiscall
345+
#ifndef PLATFORM_FREEBSD
345346
#define __fastcall
347+
#endif
346348
#define __clrcall
347349
#endif // __GNUC__
348350

0 commit comments

Comments
 (0)