Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding FreeBSD build support. #460

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions BuildTools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,3 @@ elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux")
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")
endif()

if (NOT EXISTS ${CLANG_FORMAT_EXECUTABLE})
message(FATAL_ERROR "clang-format executable is not found.")
endif()
LadySerenaKitty marked this conversation as resolved.
Show resolved Hide resolved
14 changes: 13 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,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")
LadySerenaKitty marked this conversation as resolved.
Show resolved Hide resolved
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 +201,11 @@ 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)
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 Expand Up @@ -514,6 +522,10 @@ else()
set(DILIGENT_INSTALL_PDB OFF)
endif()

if(PLATFORM_FREEBSD AND EXISTS /usr/local/include)
target_include_directories(Diligent-BuildSettings SYSTEM AFTER INTERFACE /usr/local/include)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to find some info about this problem, and I think that the right way to fix this is to set CMAKE_REQUIRED_INCLUDES at your project's CMake level:

dotnet/runtime#4073

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you try setting the CMAKE_REQUIRED_INCLUDES in your project CMake?

endif()

file(RELATIVE_PATH DILIGENT_CORE_DIR "${CMAKE_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}")
SET(DILIGENT_CORE_DIR ${DILIGENT_CORE_DIR} CACHE INTERNAL "Diligent Core installation directory")

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>
TheMostDiligent marked this conversation as resolved.
Show resolved Hide resolved
#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 @@ -286,7 +286,9 @@
#define __stdcall
#define __vectorcall
#define __thiscall
#ifndef PLATFORM_FREEBSD
#define __fastcall
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is __fastcall a recognized keyword when compiling on FreeBSD?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On this one, the compiler was complaining about fastcall being redefined, as FreeBSD's headers already define fastcall.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which compiler are you using?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Believe it or not, the entirety of DiligentEngine was built using the compiler provided by the base system: clang 16.0.6.
image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is actually strange why it only complains about __fastcall. It also recognized all other attributes
https://clang.llvm.org/docs/AttributeReference.html#target-version

Can you post the error that the compiler produces?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what happens without skipping __fastcall:

[ 35%] Building CXX object DiligentCore/Graphics/ShaderTools/CMakeFiles/Diligent-ShaderTools.dir/src/DXCompiler.cpp.o
In file included from /usr/home/jlhawkwell/Projects/DiligentEngine/DiligentCore/Graphics/ShaderTools/src/DXCompiler.cpp:42:
In file included from /usr/home/jlhawkwell/Projects/DiligentEngine/DiligentCore/Graphics/ShaderTools/include/DXCompilerBaseLinux.hpp:31:
In file included from /usr/home/jlhawkwell/Projects/DiligentEngine/DiligentCore/Graphics/ShaderTools/../../ThirdParty/DirectXShaderCompiler/dxc/dxcapi.h:37:
/usr/home/jlhawkwell/Projects/DiligentEngine/DiligentCore/Graphics/ShaderTools/../../ThirdParty/DirectXShaderCompiler/dxc/WinAdapter.h:345:9: error: '__fastcall' macro redefined [-Werror,-Wmacro-redefined]
#define __fastcall
        ^
/usr/include/sys/cdefs.h:365:9: note: previous definition is here
#define __fastcall      __attribute__((__fastcall__))
        ^
1 error generated.
gmake[2]: *** [DiligentCore/Graphics/ShaderTools/CMakeFiles/Diligent-ShaderTools.dir/build.make:122: DiligentCore/Graphics/ShaderTools/CMakeFiles/Diligent-ShaderTools.dir/src/DXCompiler.cpp.o] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:3521: DiligentCore/Graphics/ShaderTools/CMakeFiles/Diligent-ShaderTools.dir/all] Error 2
gmake: *** [Makefile:156: all] Error 2

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated DXC headers, so this should work now - please try the latest version

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A better way to fix this is to check

#ifndef __fastcall

Though I do really not understand why it only complains about __fastcall. All other macros are defined in the same way.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The __fastcall macro is already defined in /usr/include/sys/cdefs.h on line 365.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I suggested is to use the #ifndef __fastcall guard instead of #ifndef PLATFORM_FREEBSD.
Also note that this file is a third-party header so with the next update, it may break again.

#endif
#define __clrcall
#endif // __GNUC__

Expand Down
Loading