Skip to content

Commit

Permalink
CMake: improve FreeBSD support
Browse files Browse the repository at this point in the history
  • Loading branch information
bsdcode committed Nov 3, 2024
1 parent 9844a22 commit 0b34c49
Show file tree
Hide file tree
Showing 14 changed files with 199 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ make desktop-ui -j8
```
For further configuration options, see the [Build Options] section.

### Linux
### Linux / BSD

###### Prerequisites

Expand Down
1 change: 1 addition & 0 deletions ares/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ target_sources(
cmake/os-macos.cmake
cmake/os-windows.cmake
cmake/os-linux.cmake
cmake/os-freebsd.cmake
)

set_source_files_properties(ares ${ARES_HEADER_SOURCES} PROPERTIES HEADER_FILE_ONLY TRUE)
Expand Down
Empty file added ares/n64/cmake/os-freebsd.cmake
Empty file.
1 change: 1 addition & 0 deletions desktop-ui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ target_sources(
cmake/os-macos.cmake
cmake/os-linux.cmake
cmake/os-windows.cmake
cmake/os-freebsd.cmake
)

include(cmake/sources.cmake)
Expand Down
61 changes: 61 additions & 0 deletions desktop-ui/cmake/os-freebsd.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Stage and install slang shaders
if(ARES_ENABLE_LIBRASHADER)
add_custom_command(
TARGET desktop-ui
POST_BUILD
COMMAND
cp -R "${CMAKE_SOURCE_DIR}/.deps/ares-deps-linux-universal/lib/slang-shaders/."
"${ARES_BUILD_OUTPUT_DIR}/$<CONFIG>/Shaders"
COMMENT "Copying slang shaders to staging directory"
)

install(
DIRECTORY "${CMAKE_SOURCE_DIR}/.deps/ares-deps-linux-universal/lib/slang-shaders/"
DESTINATION "${ARES_INSTALL_DATA_DESTINATION}/Shaders"
USE_SOURCE_PERMISSIONS
COMPONENT Runtime
)
endif()

# Stage and install mia database
add_custom_command(
TARGET desktop-ui
POST_BUILD
COMMAND "${CMAKE_COMMAND}" -E make_directory "${ARES_BUILD_OUTPUT_DIR}/$<CONFIG>/Database"
COMMAND
cp -R "${CMAKE_SOURCE_DIR}/mia/Database/."
"${ARES_BUILD_OUTPUT_DIR}/$<CONFIG>/Database/"
COMMENT "Copying mia database to staging directory"
)

install(
DIRECTORY "${CMAKE_SOURCE_DIR}/mia/Database/"
DESTINATION "${ARES_INSTALL_DATA_DESTINATION}/Database"
USE_SOURCE_PERMISSIONS
COMPONENT Runtime
)

# Stage and install icon, .desktop file
add_custom_command(
TARGET desktop-ui
POST_BUILD
COMMAND
cp "${CMAKE_CURRENT_SOURCE_DIR}/resource/ares.desktop"
"${ARES_BUILD_OUTPUT_DIR}/$<CONFIG>/ares.desktop"
COMMAND
cp "${CMAKE_CURRENT_SOURCE_DIR}/resource/ares.png"
"${ARES_BUILD_OUTPUT_DIR}/$<CONFIG>/ares.png"
COMMENT "Copying icon to staging directory"
)

install(
FILES "${CMAKE_CURRENT_SOURCE_DIR}/resource/ares.desktop"
DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/applications"
COMPONENT Runtime
)

install(
FILES "${CMAKE_CURRENT_SOURCE_DIR}/resource/ares.png"
DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/256x256/apps"
COMPONENT Runtime
)
1 change: 0 additions & 1 deletion hiro/cmake/os-bsd.cmake

This file was deleted.

31 changes: 31 additions & 0 deletions hiro/cmake/os-freebsd.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
find_package(X11)

option(USE_QT5 "Use Qt5 UI backend" OFF)
mark_as_advanced(USE_QT5)

if(NOT USE_QT5)
find_package(GTK REQUIRED)
target_compile_definitions(hiro PRIVATE HIRO_GTK)

target_link_libraries(hiro PRIVATE GTK::GTK X11::X11)

target_enable_feature(hiro "GTK3 UI backend" HIRO_GTK=3)
else()
find_package(Qt6 COMPONENTS Widgets Xcb REQUIRED)

find_program(qt_moc moc-qt6 moc)

execute_process(
COMMAND qt_moc -i -o ${CMAKE_CURRENT_SOURCE_DIR}/qt/qt.moc ${CMAKE_CURRENT_SOURCE_DIR}/qt/qt.hpp
)

target_link_libraries(hiro PRIVATE X11::X11 Qt6::Core Qt6::Gui Qt6::Widgets Qt6::Xcb)

target_enable_feature(hiro "Qt6 UI backend" HIRO_QT=5)
endif()

get_target_property(hiro_SOURCES hiro SOURCES)

set_source_files_properties(hiro ${hiro_SOURCES} PROPERTIES HEADER_FILE_ONLY TRUE)

set_source_files_properties(hiro hiro.cpp PROPERTIES HEADER_FILE_ONLY FALSE)
1 change: 1 addition & 0 deletions hiro/cmake/sources.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -448,4 +448,5 @@ target_sources(
cmake/sources.cmake
cmake/os-windows.cmake
cmake/os-linux.cmake
cmake/os-freebsd.cmake
)
8 changes: 8 additions & 0 deletions nall/cmake/os-freebsd.cmake
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
target_compile_definitions(nall PUBLIC PLATFORM_BSD)

target_sources(
nall
PRIVATE # cmake-format: sortable
xorg/clipboard.hpp
xorg/guard.hpp
xorg/xorg.hpp
)
4 changes: 3 additions & 1 deletion nall/cmake/sources.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,8 @@ target_sources(
PRIVATE
cmake/os-macos.cmake
cmake/os-windows.cmake
cmake/os-linux.cmake)
cmake/os-linux.cmake
cmake/os-freebsd.cmake
)

target_sources(nall PRIVATE cmake/sources.cmake)
2 changes: 1 addition & 1 deletion nall/intrinsics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ namespace nall {
static constexpr bool BSD = 0;
};
#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__OpenBSD__)
#define PLATFORM_BSD
// #define PLATFORM_BSD
struct Platform {
static constexpr bool Windows = 0;
static constexpr bool MacOS = 0;
Expand Down
1 change: 1 addition & 0 deletions ruby/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ target_sources(
cmake/os-macos.cmake
cmake/os-windows.cmake
cmake/os-linux.cmake
cmake/os-freebsd.cmake
)

target_link_libraries(ruby PUBLIC ares::nall)
Expand Down
90 changes: 90 additions & 0 deletions ruby/cmake/os-freebsd.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,93 @@ target_sources(
input/joypad/uhid.cpp
input/joypad/xinput.cpp
)

find_package(X11 REQUIRED)
find_package(OpenGL REQUIRED)

target_link_libraries(ruby PRIVATE X11::Xrandr OpenGL::GLX)

target_enable_feature(ruby "GLX OpenGL video driver" VIDEO_GLX)
target_enable_feature(ruby "Xlib input driver" INPUT_XLIB)

find_package(librashader)
if(librashader_FOUND AND ARES_ENABLE_LIBRASHADER)
target_enable_feature(ruby "librashader OpenGL runtime" LIBRA_RUNTIME_OPENGL)
else()
# continue to define the runtime so openGL compiles
target_compile_definitions(ruby PRIVATE LIBRA_RUNTIME_OPENGL)
endif()

option(ARES_ENABLE_OPENAL "Enable the OpenAL audio driver" ON)
if(ARES_ENABLE_OPENAL)
find_package(OpenAL)
endif()
if(OpenAL_FOUND)
target_enable_feature(ruby "OpenAL audio driver" AUDIO_OPENAL)
else()
target_disable_feature(ruby "OpenAL audio driver")
endif()

option(ARES_ENABLE_SDL "Enable SDL audio and input drivers" ON)
if(ARES_ENABLE_SDL)
find_package(SDL)
endif()
if(SDL_FOUND)
target_enable_feature(ruby "SDL input driver" INPUT_SDL)
target_enable_feature(ruby "SDL audio driver" AUDIO_SDL)
else()
target_disable_feature(ruby "SDL audio driver")
target_disable_feature(ruby "SDL input driver")
endif()

option(ARES_ENABLE_OSS "Enable the OSS audio driver" ON)
if(ARES_ENABLE_OSS)
find_package(OSS)
endif()
if(OSS_FOUND)
target_enable_feature(ruby "OSS audio driver" AUDIO_OSS)
else()
target_disable_feature(ruby "OSS audio driver")
endif()

option(ARES_ENABLE_ALSA "Enable the ALSA audio driver")
if(ARES_ENABLE_ALSA)
find_package(ALSA)
endif()
if(ALSA_FOUND)
target_enable_feature(ruby "ALSA audio driver" AUDIO_ALSA)
else()
target_disable_feature(ruby "ALSA audio driver")
endif()

option(ARES_ENABLE_PULSEAUDIO "Enable the Pulse audio driver" ON)
if(ARES_ENABLE_PULSEAUDIO)
find_package(PulseAudio)
endif()
if(PulseAudio_FOUND)
target_enable_feature(ruby "PulseAudio audio driver" AUDIO_PULSEAUDIO)
else()
target_disable_feature(ruby "PulseAudio audio driver")
endif()

option(ARES_ENABLE_AO "Enable the AO audio driver" ON)
if(ARES_ENABLE_AO)
find_package(AO)
endif()
if(AO_FOUND)
target_enable_feature(ruby "AO audio driver" AUDIO_AO)
else()
target_disable_feature(ruby "AO audio driver")
endif()

target_link_libraries(
ruby
PRIVATE
$<$<BOOL:${SDL_FOUND}>:SDL::SDL>
$<$<BOOL:${OpenAL_FOUND}>:OpenAL::OpenAL>
$<$<BOOL:TRUE>:librashader::librashader>
$<$<BOOL:${OSS_FOUND}>:OSS::OSS>
$<$<BOOL:${ALSA_FOUND}>:ALSA::ALSA>
$<$<BOOL:${PulseAudio_FOUND}>:pulse>
$<$<BOOL:${AO_FOUND}>:AO::AO>
)
Empty file.

0 comments on commit 0b34c49

Please sign in to comment.