Skip to content

Commit 4efa40c

Browse files
authored
Make it easy to build Cemu on BSD (#1632)
1 parent 955ce9b commit 4efa40c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+167
-57
lines changed

BUILD.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
- [Installing Tool Dependencies](#installing-tool-dependencies)
2121
- [Installing Library Dependencies](#installing-library-dependencies)
2222
- [Build Cemu using CMake](#build-cemu-using-cmake)
23+
- [FreeBSD](#freebsd)
24+
- [Installing Dependencies](#installing-dependencies)
25+
- [Build Cemu on BSD with CMake](#build-cemu-on-bsd-with-cmake)
2326
- [Updating Cemu and source code](#updating-cemu-and-source-code)
2427

2528
## Windows
@@ -185,6 +188,33 @@ Then install the dependencies:
185188
#### Troubleshooting steps
186189
- If step 3 gives you an error about not being able to find ninja, try appending `-DCMAKE_MAKE_PROGRAM=/usr/local/bin/ninja` to the command and running it again.
187190

191+
## FreeBSD
192+
193+
The following instructions to build Cemu on FreeBSD are experimental. Some features available on other platforms are not available on FreeBSD (discord rich presence, bluetooth/support for actual Wii U controllers, auto-updates, etc.)
194+
195+
To compile Cemu, a recent enough compiler and STL with C++20 support is required! Clang-15 or higher is what we recommend. Any version of FreeBSD 13.3-RELEASE or higher comes bundled with LLVM > version 15 as part of the base system. However, if for whatever reason your system lacks a recent version of LLVM you can install one by executing:
196+
197+
`sudo pkg install llvm15`
198+
199+
Or a higher version as desired.
200+
201+
### Installing Dependencies
202+
203+
`sudo pkg install boost-libs cmake-core curl glslang gtk3 libzip ninja png pkgconf pugixml rapidjson sdl2 wayland wayland-protocols wx32-gtk3 xorg zstd`
204+
205+
### Build Cemu on BSD with CMake
206+
207+
```
208+
git clone --recursive https://github.com/cemu-project/Cemu
209+
cd Cemu
210+
cmake -B build -DCMAKE_BUILD_TYPE=release -DENABLE_BLUEZ=OFF -DENABLE_DISCORD_RPC=OFF -DENABLE_FERAL_GAMEMODE=OFF -DENABLE_HIDAPI=OFF -DENABLE_VCPKG=OFF -G Ninja
211+
cmake --build build
212+
213+
cd build && ninja install
214+
```
215+
216+
You should now have a Cemu executable file in the /bin folder, which you can run using `./bin/Cemu_release`.
217+
188218
## Updating Cemu and source code
189219
1. To update your Cemu local repository, use the command `git pull --recurse-submodules` (run this command on the Cemu root).
190220
- This should update your local copy of Cemu and all of its dependencies.

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ if (UNIX AND NOT APPLE)
159159
BASENAME viewporter)
160160
add_library(CemuWaylandProtocols STATIC ${WAYLAND_PROTOCOL_SRCS})
161161
target_include_directories(CemuWaylandProtocols PUBLIC "${CMAKE_CURRENT_BINARY_DIR}")
162-
162+
target_include_directories(CemuWaylandProtocols PRIVATE ${Wayland_INCLUDE_DIRS})
163163
add_compile_definitions(HAS_WAYLAND)
164164
endif()
165165
find_package(GTK3 REQUIRED)
@@ -234,4 +234,4 @@ if (NOT ZArchive_FOUND)
234234
add_subdirectory("dependencies/ZArchive" EXCLUDE_FROM_ALL)
235235
endif()
236236

237-
add_subdirectory(src)
237+
add_subdirectory(src)

src/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,3 +150,7 @@ if(UNIX AND NOT APPLE)
150150
# most likely not helpful in debugging problems with cemu code
151151
target_link_options(CemuBin PRIVATE "$<$<CONFIG:Release>:-Xlinker;--strip-debug>")
152152
endif()
153+
154+
if (BSD)
155+
target_link_libraries(CemuBin PRIVATE execinfo SPIRV-Tools SPIRV-Tools-opt)
156+
endif()

src/Cafe/CafeSystem.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969

7070
#if BOOST_OS_LINUX
7171
#include <sys/sysinfo.h>
72-
#elif BOOST_OS_MACOS
72+
#elif BOOST_OS_MACOS || BOOST_OS_BSD
7373
#include <sys/types.h>
7474
#include <sys/sysctl.h>
7575
#endif
@@ -473,6 +473,12 @@ namespace CafeSystem
473473
int64_t totalRam;
474474
size_t size = sizeof(totalRam);
475475
int result = sysctlbyname("hw.memsize", &totalRam, &size, NULL, 0);
476+
if (result == 0)
477+
cemuLog_log(LogType::Force, "RAM: {}MB", (totalRam / 1024LL / 1024LL));
478+
#elif BOOST_OS_BSD
479+
int64_t totalRam;
480+
size_t size = sizeof(totalRam);
481+
int result = sysctlbyname("hw.physmem", &totalRam, &size, NULL, 0);
476482
if (result == 0)
477483
cemuLog_log(LogType::Force, "RAM: {}MB", (totalRam / 1024LL / 1024LL));
478484
#endif
@@ -523,6 +529,16 @@ namespace CafeSystem
523529
platform = "Linux";
524530
#elif BOOST_OS_MACOS
525531
platform = "MacOS";
532+
#elif BOOST_OS_BSD
533+
#if defined(__FreeBSD__)
534+
platform = "FreeBSD";
535+
#elif defined(__OpenBSD__)
536+
platform = "OpenBSD";
537+
#elif defined(__NetBSD__)
538+
platform = "NetBSD";
539+
#else
540+
platform = "Unknown BSD";
541+
#endif
526542
#endif
527543
cemuLog_log(LogType::Force, "Platform: {}", platform);
528544
}

src/Cafe/HW/Latte/LatteAddrLib/LatteAddrLib_Coord.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ using namespace Latte;
77
namespace LatteAddrLib
88
{
99

10-
#if BOOST_OS_LINUX || BOOST_OS_MACOS
10+
#if BOOST_OS_LINUX || BOOST_OS_MACOS || BOOST_OS_BSD
1111
unsigned char _BitScanReverse(uint32* _Index, uint32 _Mask)
1212
{
1313
if (!_Mask)
@@ -402,4 +402,4 @@ namespace LatteAddrLib
402402
return finalMacroTileOffset | pipeOffset | bankOffset;
403403
}
404404

405-
};
405+
};

src/Cafe/HW/Latte/Renderer/OpenGL/OpenGLRenderer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ void LoadOpenGLImports()
241241
#include "Common/GLInclude/glFunctions.h"
242242
#undef GLFUNC
243243
}
244-
#elif BOOST_OS_LINUX
244+
#elif BOOST_OS_LINUX || BOOST_OS_BSD
245245
GL_IMPORT _GetOpenGLFunction(void* hLib, PFNGLXGETPROCADDRESSPROC func, const char* name)
246246
{
247247
GL_IMPORT r = (GL_IMPORT)func((const GLubyte*)name);
@@ -276,7 +276,7 @@ void LoadOpenGLImports()
276276
#undef EGLFUNC
277277
}
278278

279-
#if BOOST_OS_LINUX
279+
#if BOOST_OS_LINUX || BOOST_OS_BSD
280280
// dummy function for all code that is statically linked with cemu and attempts to use eglSwapInterval
281281
// used to suppress wxWidgets calls to eglSwapInterval
282282
extern "C"

src/Cafe/HW/Latte/Renderer/Vulkan/RendererShaderVk.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#include <glslang/Public/ShaderLang.h>
1010
#include <glslang/SPIRV/GlslangToSpv.h>
11-
#include <util/helpers/helpers.h>
11+
#include "util/helpers/helpers.h"
1212

1313
bool s_isLoadingShadersVk{ false };
1414
class FileCache* s_spirvCache{nullptr};

src/Cafe/HW/Latte/Renderer/Vulkan/VulkanAPI.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include "Cafe/HW/Latte/Renderer/Vulkan/VulkanAPI.h"
44
#include <numeric> // for std::iota
55

6-
#if BOOST_OS_LINUX || BOOST_OS_MACOS
6+
#if BOOST_OS_LINUX || BOOST_OS_MACOS || BOOST_OS_BSD
77
#include <dlfcn.h>
88
#endif
99

@@ -138,7 +138,7 @@ bool InitializeDeviceVulkan(VkDevice device)
138138

139139
void* dlopen_vulkan_loader()
140140
{
141-
#if BOOST_OS_LINUX
141+
#if BOOST_OS_LINUX || BOOST_OS_BSD
142142
void* vulkan_so = dlopen("libvulkan.so", RTLD_NOW);
143143
if(!vulkan_so)
144144
vulkan_so = dlopen("libvulkan.so.1", RTLD_NOW);

src/Cafe/HW/Latte/Renderer/Vulkan/VulkanAPI.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ VKFUNC_DEVICE(vkDestroyPipeline);
130130
VKFUNC_DEVICE(vkCmdBindPipeline);
131131

132132
// swapchain
133-
#if BOOST_OS_LINUX
133+
#if BOOST_OS_LINUX || BOOST_OS_BSD
134134
VKFUNC_INSTANCE(vkCreateXlibSurfaceKHR);
135135
VKFUNC_INSTANCE(vkCreateXcbSurfaceKHR);
136136
#ifdef HAS_WAYLAND

src/Cafe/HW/Latte/Renderer/Vulkan/VulkanRenderer.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ std::vector<VulkanRenderer::DeviceInfo> VulkanRenderer::GetDevices()
110110
requiredExtensions.emplace_back(VK_KHR_SURFACE_EXTENSION_NAME);
111111
#if BOOST_OS_WINDOWS
112112
requiredExtensions.emplace_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
113-
#elif BOOST_OS_LINUX
113+
#elif BOOST_OS_LINUX || BOOST_OS_BSD
114114
auto backend = WindowSystem::GetWindowInfo().window_main.backend;
115115
if(backend == WindowSystem::WindowHandleInfo::Backend::X11)
116116
requiredExtensions.emplace_back(VK_KHR_XLIB_SURFACE_EXTENSION_NAME);
@@ -1307,7 +1307,7 @@ std::vector<const char*> VulkanRenderer::CheckInstanceExtensionSupport(FeatureCo
13071307
requiredInstanceExtensions.emplace_back(VK_KHR_SURFACE_EXTENSION_NAME);
13081308
#if BOOST_OS_WINDOWS
13091309
requiredInstanceExtensions.emplace_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
1310-
#elif BOOST_OS_LINUX
1310+
#elif BOOST_OS_LINUX || BOOST_OS_BSD
13111311
auto backend = WindowSystem::GetWindowInfo().window_main.backend;
13121312
if(backend == WindowSystem::WindowHandleInfo::Backend::X11)
13131313
requiredInstanceExtensions.emplace_back(VK_KHR_XLIB_SURFACE_EXTENSION_NAME);
@@ -1394,7 +1394,7 @@ VkSurfaceKHR VulkanRenderer::CreateWinSurface(VkInstance instance, HWND hwindow)
13941394
}
13951395
#endif
13961396

1397-
#if BOOST_OS_LINUX
1397+
#if BOOST_OS_LINUX || BOOST_OS_BSD
13981398
VkSurfaceKHR VulkanRenderer::CreateXlibSurface(VkInstance instance, Display* dpy, Window window)
13991399
{
14001400
VkXlibSurfaceCreateInfoKHR sci{};
@@ -1458,8 +1458,7 @@ VkSurfaceKHR VulkanRenderer::CreateFramebufferSurface(VkInstance instance, Windo
14581458
{
14591459
#if BOOST_OS_WINDOWS
14601460
return CreateWinSurface(instance, static_cast<HWND>(windowInfo.surface));
1461-
#elif BOOST_OS_LINUX
1462-
1461+
#elif BOOST_OS_LINUX || BOOST_OS_BSD
14631462
if(windowInfo.backend == WindowSystem::WindowHandleInfo::Backend::X11)
14641463
return CreateXlibSurface(instance, static_cast<Display*>(windowInfo.display), reinterpret_cast<Window>(windowInfo.surface));
14651464
#ifdef HAS_WAYLAND

0 commit comments

Comments
 (0)