Skip to content

Commit ced3c01

Browse files
committed
MacOS build fixes
MacOS build fix - updated from C++ 14 to C++ 17 to work with the currently available versions of POCO (v1.13.0 and above require C++ 17) - added MacOS specific build logic for including the projectM libraries in the application file - added 'Findutf8proc.cmake' for finding the utf8proc installation to resolve build issue (Mac specific issue for some reason, so only runs if MacOS) changed GLSL version to fix UI on MacOS
1 parent 38cd021 commit ced3c01

File tree

5 files changed

+109
-4
lines changed

5 files changed

+109
-4
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1037,4 +1037,4 @@ _deps
10371037
modules.order
10381038
Module.symvers
10391039
Mkfile.old
1040-
dkms.conf
1040+
dkms.conf

CMakeLists.txt

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cmake_minimum_required(VERSION 3.20 FATAL_ERROR)
22

3-
set(CMAKE_CXX_STANDARD 14)
3+
set(CMAKE_CXX_STANDARD 17) # this can be changed to 14 if Poco is earlier than version 1.13.0
44
set(CMAKE_CXX_STANDARD_REQUIRED YES)
55
set(CMAKE_POSITION_INDEPENDENT_CODE YES)
66

@@ -13,6 +13,12 @@ project(projectMSDL
1313

1414
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
1515

16+
# the following should be set to the 'install' folder of projectM if you encounter issues with it finding the projectM libraries
17+
#list(APPEND CMAKE_PREFIX_PATH "projectM 'install' folder")
18+
19+
# the following should be set to the 'install' folder of projectM if you encounter issues with it finding the projectM libraries
20+
#list(APPEND CMAKE_PREFIX_PATH "projectM 'install' folder")
21+
1622
# Default install layouts.
1723
option(ENABLE_FLAT_PACKAGE "Creates a \"flat\" install layout with files and preset/texture dirs directly in the main dir." OFF)
1824
if(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND NOT ENABLE_FLAT_PACKAGE)
@@ -71,6 +77,12 @@ if(NOT SDL2_LINKAGE STREQUAL "shared" AND NOT SDL2_LINKAGE STREQUAL "static")
7177
)
7278
endif()
7379

80+
# Add utf8proc before Poco
81+
#set(UTF8PROC_ROOT "utf8proc/<version>") # if you get build errors about utf8proc, set this to the path to your utf8proc install
82+
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
83+
find_package(utf8proc REQUIRED)
84+
endif()
85+
7486
find_package(projectM4 REQUIRED COMPONENTS Playlist)
7587
find_package(SDL2 REQUIRED)
7688
find_package(Poco REQUIRED COMPONENTS JSON XML Util Foundation)

cmake/Findutf8proc.cmake

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Find the utf8proc header directory
2+
find_path(UTF8PROC_INCLUDE_DIR
3+
NAMES utf8proc.h
4+
PATHS
5+
$ENV{UTF8PROC_ROOT}/include
6+
/usr/local/include
7+
/usr/include
8+
)
9+
10+
# Find the utf8proc library
11+
find_library(UTF8PROC_LIBRARY
12+
NAMES utf8proc
13+
PATHS
14+
$ENV{UTF8PROC_ROOT}/lib
15+
/usr/local/lib
16+
/usr/lib
17+
)
18+
19+
include(FindPackageHandleStandardArgs)
20+
find_package_handle_standard_args(utf8proc
21+
REQUIRED_VARS
22+
UTF8PROC_LIBRARY
23+
UTF8PROC_INCLUDE_DIR
24+
)
25+
26+
if(utf8proc_FOUND AND NOT TARGET Utf8Proc::Utf8Proc)
27+
add_library(Utf8Proc::Utf8Proc UNKNOWN IMPORTED)
28+
set_target_properties(Utf8Proc::Utf8Proc PROPERTIES
29+
IMPORTED_LOCATION "${UTF8PROC_LIBRARY}"
30+
INTERFACE_INCLUDE_DIRECTORIES "${UTF8PROC_INCLUDE_DIR}"
31+
)
32+
endif()

src/CMakeLists.txt

+62-1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ target_compile_definitions(projectMSDL
6060
PROJECTMSDL_VERSION="${PROJECT_VERSION}"
6161
)
6262

63+
6364
target_link_libraries(projectMSDL
6465
PRIVATE
6566
ProjectMSDL-GUI
@@ -70,7 +71,67 @@ target_link_libraries(projectMSDL
7071
SDL2::SDL2main
7172
)
7273

73-
if(MSVC)
74+
# Add the dylib copying for macOS
75+
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
76+
function(copy_dylibs_to_frameworks TARGET_NAME DYLIB_SOURCE_DIR)
77+
# Create Frameworks directory
78+
add_custom_command(TARGET ${TARGET_NAME} POST_BUILD
79+
COMMAND ${CMAKE_COMMAND} -E make_directory
80+
"$<TARGET_FILE_DIR:${TARGET_NAME}>/../Frameworks"
81+
)
82+
83+
# Find all .dylib files in the source directory
84+
file(GLOB DYLIB_FILES "${DYLIB_SOURCE_DIR}/*.dylib")
85+
86+
# Copy each .dylib file and fix its rpath
87+
foreach(DYLIB_FILE ${DYLIB_FILES})
88+
get_filename_component(DYLIB_NAME ${DYLIB_FILE} NAME)
89+
add_custom_command(TARGET ${TARGET_NAME} POST_BUILD
90+
COMMAND ${CMAKE_COMMAND} -E copy
91+
"${DYLIB_FILE}"
92+
"$<TARGET_FILE_DIR:${TARGET_NAME}>/../Frameworks/${DYLIB_NAME}"
93+
)
94+
endforeach()
95+
96+
# Add rpath to the main executable
97+
add_custom_command(TARGET ${TARGET_NAME} POST_BUILD
98+
COMMAND install_name_tool -add_rpath "@executable_path/../Frameworks"
99+
"$<TARGET_FILE:${TARGET_NAME}>"
100+
)
101+
endfunction()
102+
103+
# Try to locate projectm
104+
find_path(PROJECTM_LIBRARY_DIR
105+
NAMES libprojectM-4.dylib # Use a known file from the library directory
106+
PATHS
107+
$ENV{PROJECTM_ROOT}/lib # Check an environment variable
108+
/usr/local/lib/projectm # Common install location
109+
/opt/homebrew/lib/projectm # Homebrew on Apple Silicon
110+
/opt/local/lib/projectm # MacPorts location
111+
PATH_SUFFIXES
112+
lib # Look automatically appended subdirectories like 'lib'
113+
NO_DEFAULT_PATH
114+
)
115+
116+
if (NOT PROJECTM_LIBRARY_DIR)
117+
find_path(PROJECTM_LIBRARY_DIR
118+
NAMES libprojectM.dylib
119+
PATHS ${CMAKE_PREFIX_PATH}
120+
PATH_SUFFIXES lib
121+
)
122+
endif()
123+
124+
if (PROJECTM_LIBRARY_DIR)
125+
message(STATUS "Found projectM libraries at: ${PROJECTM_LIBRARY_DIR}")
126+
# Call the function to copy dylibs found in PROJECTM_LIBRARY_DIR
127+
copy_dylibs_to_frameworks(projectMSDL "${PROJECTM_LIBRARY_DIR}")
128+
else()
129+
message(WARNING "Could not find projectM libraries. Please set PROJECTM_ROOT or specify the library location manually.")
130+
endif()
131+
endif()
132+
133+
134+
if (MSVC)
74135
set_target_properties(projectMSDL
75136
PROPERTIES
76137
VS_DPI_AWARE "PerMonitor"

src/gui/ProjectMGUI.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ void ProjectMGUI::initialize(Poco::Util::Application& app)
4343
_glContext = renderingWindow.GetGlContext();
4444

4545
ImGui_ImplSDL2_InitForOpenGL(_renderingWindow, _glContext);
46-
ImGui_ImplOpenGL3_Init("#version 130");
46+
ImGui_ImplOpenGL3_Init("#version 150"); // changing this from '130' to '150' fixes the UI not displaying on MacOS 15
4747

4848
UpdateFontSize();
4949

0 commit comments

Comments
 (0)