From a15fa8d66026a13d3c4a812d9f84f3ef0e67d231 Mon Sep 17 00:00:00 2001 From: jmelovich Date: Fri, 7 Feb 2025 15:05:10 -0500 Subject: [PATCH] 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 --- .gitignore | 2 +- CMakeLists.txt | 14 ++++++++- cmake/Findutf8proc.cmake | 32 ++++++++++++++++++++ src/CMakeLists.txt | 63 +++++++++++++++++++++++++++++++++++++++- src/gui/ProjectMGUI.cpp | 2 +- 5 files changed, 109 insertions(+), 4 deletions(-) create mode 100644 cmake/Findutf8proc.cmake diff --git a/.gitignore b/.gitignore index 5269e44..06d5847 100644 --- a/.gitignore +++ b/.gitignore @@ -1037,4 +1037,4 @@ _deps modules.order Module.symvers Mkfile.old -dkms.conf +dkms.conf \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index e251ce2..662525d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.20 FATAL_ERROR) -set(CMAKE_CXX_STANDARD 14) +set(CMAKE_CXX_STANDARD 17) # this can be changed to 14 if Poco is earlier than version 1.13.0 set(CMAKE_CXX_STANDARD_REQUIRED YES) set(CMAKE_POSITION_INDEPENDENT_CODE YES) @@ -13,6 +13,12 @@ project(projectMSDL list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") +# the following should be set to the 'install' folder of projectM if you encounter issues with it finding the projectM libraries +#list(APPEND CMAKE_PREFIX_PATH "projectM 'install' folder") + +# the following should be set to the 'install' folder of projectM if you encounter issues with it finding the projectM libraries +#list(APPEND CMAKE_PREFIX_PATH "projectM 'install' folder") + # Default install layouts. option(ENABLE_FLAT_PACKAGE "Creates a \"flat\" install layout with files and preset/texture dirs directly in the main dir." OFF) 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") ) endif() +# Add utf8proc before Poco +#set(UTF8PROC_ROOT "utf8proc/") # if you get build errors about utf8proc, set this to the path to your utf8proc install +if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") + find_package(utf8proc REQUIRED) +endif() + find_package(projectM4 REQUIRED COMPONENTS Playlist) find_package(SDL2 REQUIRED) find_package(Poco REQUIRED COMPONENTS JSON XML Util Foundation) diff --git a/cmake/Findutf8proc.cmake b/cmake/Findutf8proc.cmake new file mode 100644 index 0000000..d89f373 --- /dev/null +++ b/cmake/Findutf8proc.cmake @@ -0,0 +1,32 @@ +# Find the utf8proc header directory +find_path(UTF8PROC_INCLUDE_DIR + NAMES utf8proc.h + PATHS + $ENV{UTF8PROC_ROOT}/include + /usr/local/include + /usr/include +) + +# Find the utf8proc library +find_library(UTF8PROC_LIBRARY + NAMES utf8proc + PATHS + $ENV{UTF8PROC_ROOT}/lib + /usr/local/lib + /usr/lib +) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(utf8proc + REQUIRED_VARS + UTF8PROC_LIBRARY + UTF8PROC_INCLUDE_DIR +) + +if(utf8proc_FOUND AND NOT TARGET Utf8Proc::Utf8Proc) + add_library(Utf8Proc::Utf8Proc UNKNOWN IMPORTED) + set_target_properties(Utf8Proc::Utf8Proc PROPERTIES + IMPORTED_LOCATION "${UTF8PROC_LIBRARY}" + INTERFACE_INCLUDE_DIRECTORIES "${UTF8PROC_INCLUDE_DIR}" + ) +endif() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index fb65c11..97ad388 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -60,6 +60,7 @@ target_compile_definitions(projectMSDL PROJECTMSDL_VERSION="${PROJECT_VERSION}" ) + target_link_libraries(projectMSDL PRIVATE ProjectMSDL-GUI @@ -70,7 +71,67 @@ target_link_libraries(projectMSDL SDL2::SDL2main ) -if(MSVC) +# Add the dylib copying for macOS +if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") + function(copy_dylibs_to_frameworks TARGET_NAME DYLIB_SOURCE_DIR) + # Create Frameworks directory + add_custom_command(TARGET ${TARGET_NAME} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E make_directory + "$/../Frameworks" + ) + + # Find all .dylib files in the source directory + file(GLOB DYLIB_FILES "${DYLIB_SOURCE_DIR}/*.dylib") + + # Copy each .dylib file and fix its rpath + foreach(DYLIB_FILE ${DYLIB_FILES}) + get_filename_component(DYLIB_NAME ${DYLIB_FILE} NAME) + add_custom_command(TARGET ${TARGET_NAME} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy + "${DYLIB_FILE}" + "$/../Frameworks/${DYLIB_NAME}" + ) + endforeach() + + # Add rpath to the main executable + add_custom_command(TARGET ${TARGET_NAME} POST_BUILD + COMMAND install_name_tool -add_rpath "@executable_path/../Frameworks" + "$" + ) + endfunction() + + # Try to locate projectm + find_path(PROJECTM_LIBRARY_DIR + NAMES libprojectM-4.dylib # Use a known file from the library directory + PATHS + $ENV{PROJECTM_ROOT}/lib # Check an environment variable + /usr/local/lib/projectm # Common install location + /opt/homebrew/lib/projectm # Homebrew on Apple Silicon + /opt/local/lib/projectm # MacPorts location + PATH_SUFFIXES + lib # Look automatically appended subdirectories like 'lib' + NO_DEFAULT_PATH + ) + + if (NOT PROJECTM_LIBRARY_DIR) + find_path(PROJECTM_LIBRARY_DIR + NAMES libprojectM.dylib + PATHS ${CMAKE_PREFIX_PATH} + PATH_SUFFIXES lib + ) + endif() + + if (PROJECTM_LIBRARY_DIR) + message(STATUS "Found projectM libraries at: ${PROJECTM_LIBRARY_DIR}") + # Call the function to copy dylibs found in PROJECTM_LIBRARY_DIR + copy_dylibs_to_frameworks(projectMSDL "${PROJECTM_LIBRARY_DIR}") + else() + message(WARNING "Could not find projectM libraries. Please set PROJECTM_ROOT or specify the library location manually.") + endif() +endif() + + +if (MSVC) set_target_properties(projectMSDL PROPERTIES VS_DPI_AWARE "PerMonitor" diff --git a/src/gui/ProjectMGUI.cpp b/src/gui/ProjectMGUI.cpp index 415bd7a..d73ba1c 100644 --- a/src/gui/ProjectMGUI.cpp +++ b/src/gui/ProjectMGUI.cpp @@ -43,7 +43,7 @@ void ProjectMGUI::initialize(Poco::Util::Application& app) _glContext = renderingWindow.GetGlContext(); ImGui_ImplSDL2_InitForOpenGL(_renderingWindow, _glContext); - ImGui_ImplOpenGL3_Init("#version 130"); + ImGui_ImplOpenGL3_Init("#version 150"); // changing this from '130' to '150' fixes the UI not displaying on MacOS 15 UpdateFontSize();