From d65b8e79f7f691831ce19fe1066cf3703615cbb1 Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Sun, 1 Oct 2023 21:27:27 -0700 Subject: [PATCH 1/2] Cleanup plClient CMake project a bit --- Sources/Plasma/Apps/plClient/CMakeLists.txt | 53 ++++++++------------- cmake/PlasmaTargets.cmake | 5 +- 2 files changed, 22 insertions(+), 36 deletions(-) diff --git a/Sources/Plasma/Apps/plClient/CMakeLists.txt b/Sources/Plasma/Apps/plClient/CMakeLists.txt index b5b724fde7..3b5272fda3 100644 --- a/Sources/Plasma/Apps/plClient/CMakeLists.txt +++ b/Sources/Plasma/Apps/plClient/CMakeLists.txt @@ -90,7 +90,7 @@ if(WIN32) win32/res/headspin.ico ) elseif(APPLE) - set(plClient_SOURCES ${plClient_SOURCES} + list(APPEND plClient_SOURCES Mac-Cocoa/main.mm Mac-Cocoa/NSString+StringTheory.mm Mac-Cocoa/PLSKeyboardEventMonitor.mm @@ -100,7 +100,7 @@ elseif(APPLE) Mac-Cocoa/PLSPatcher.mm Mac-Cocoa/PLSServerStatus.mm ) - set(plClient_HEADERS ${plClient_HEADERS} + list(APPEND plClient_HEADERS Mac-Cocoa/NSString+StringTheory.h Mac-Cocoa/PLSKeyboardEventMonitor.h Mac-Cocoa/PLSView.h @@ -109,17 +109,13 @@ elseif(APPLE) Mac-Cocoa/PLSPatcher.h Mac-Cocoa/PLSServerStatus.h ) - set(RESOURCES + list(APPEND plClient_RESOURCES + Mac-Cocoa/Assets.xcassets + Mac-Cocoa/banner.png + Mac-Cocoa/banner@2x.png Mac-Cocoa/MainMenu.xib Mac-Cocoa/PLSLoginWindowController.xib Mac-Cocoa/PLSPatcherWindowController.xib - Mac-Cocoa/banner.png - Mac-Cocoa/banner@2x.png - win32/res/Dirt.ICO - ) - - list(APPEND plClient_RESOURCES - win32/res/Dirt.ICO ) else() list(APPEND plClient_SOURCES @@ -127,10 +123,15 @@ else() ) endif() +plasma_executable(plClient CLIENT INSTALL_PDB + SOURCES + ${plClient_SOURCES} ${plClient_HEADERS} + ${plClient_TEXT} ${plClient_RESOURCES} +) + if(APPLE) - plasma_executable(plClient CLIENT INSTALL_PDB SOURCES ${plClient_SOURCES} ${plClient_HEADERS} ${RESOURCES}) + target_sources(plClient PRIVATE ${plClient_IBSOURCES}) set_target_properties(plClient PROPERTIES - BUNDLE TRUE MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/Mac-Cocoa/Info.plist.in" # Hard coding the app name here intentionally. # Should prevent macOS from tripping over secured resources being @@ -141,42 +142,28 @@ if(APPLE) MACOSX_BUNDLE_GUI_IDENTIFIER org.Huru.UruExplorer MACOSX_BUNDLE_BUNDLE_VERSION "0.1" MACOSX_BUNDLE_SHORT_VERSION_STRING "0.1" + RESOURCE "${plClient_RESOURCES} ${plClient_IBSOURCES}" XCODE_ATTRIBUTE_ASSETCATALOG_COMPILER_APPICON_NAME AppIcon XCODE_ATTRIBUTE_MTL_FAST_MATH "YES" XCODE_ATTRIBUTE_MTL_ENABLE_DEBUG_INFO[variant=Debug] "INCLUDE_SOURCE" XCODE_ATTRIBUTE_MTL_ENABLE_DEBUG_INFO[variant=RelWithDebInfo] "INCLUDE_SOURCE" XCODE_ATTRIBUTE_GCC_GENERATE_DEBUGGING_SYMBOLS[variant=Debug] "YES" XCODE_ATTRIBUTE_GCC_GENERATE_DEBUGGING_SYMBOLS[variant=RelWithDebInfo] "YES" - XCODE_ATTRIBUTE_MTL_HEADER_SEARCH_PATHS ${Plasma_SOURCE_DIR}/Sources/Plasma/NucleusLib/inc/ + XCODE_ATTRIBUTE_MTL_HEADER_SEARCH_PATHS "${Plasma_SOURCE_DIR}/Sources/Plasma/NucleusLib/inc/" XCODE_ATTRIBUTE_INSTALL_PATH "/Applications" XCODE_ATTRIBUTE_SKIP_INSTALL "NO" - XCODE_ATTRIBUTE_CODE_SIGN_ENTITLEMENTS ${CMAKE_CURRENT_SOURCE_DIR}/Mac-Cocoa/plClient.entitlements + XCODE_ATTRIBUTE_CODE_SIGN_ENTITLEMENTS "${CMAKE_CURRENT_SOURCE_DIR}/Mac-Cocoa/plClient.entitlements" XCODE_ATTRIBUTE_ENABLE_HARDENED_RUNTIME "YES" + XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_ARC "YES" ) target_compile_options(plClient PRIVATE -fobjc-arc) - target_sources(plClient PRIVATE Mac-Cocoa/Assets.xcassets) - set_source_files_properties(Mac-Cocoa/Assets.xcassets ${RESOURCES} PROPERTIES - MACOSX_PACKAGE_LOCATION Resources - ) - target_link_libraries(plClient PRIVATE "-framework Cocoa") - target_link_libraries(plClient PRIVATE "-framework QuartzCore") - install( - TARGETS plClient - DESTINATION client - ) - + if(PLASMA_APPLE_DEVELOPMENT_TEAM_ID) set_target_properties(plClient PROPERTIES XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "Apple Development" XCODE_ATTRIBUTE_DEVELOPMENT_TEAM ${PLASMA_APPLE_DEVELOPMENT_TEAM_ID} ) endif() -else() - plasma_executable(plClient WIN32 CLIENT INSTALL_PDB - SOURCES - ${plClient_SOURCES} ${plClient_HEADERS} - ${plClient_TEXT} ${plClient_RESOURCES} - ) endif() if(PLASMA_BUILD_RESOURCE_DAT) @@ -240,6 +227,8 @@ target_link_libraries( $<$:pfDXPipeline> $<$:pfGLPipeline> CURL::libcurl + "$<$:-framework Cocoa>" + "$<$:-framework QuartzCore>" ) target_include_directories(plClient PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}") @@ -269,4 +258,4 @@ endif() source_group("Source Files" FILES ${plClient_SOURCES}) source_group("Header Files" FILES ${plClient_HEADERS}) source_group("Text" FILES ${plClient_TEXT}) -source_group("Windows Resource Files" FILES ${plClient_RESOURCES}) +source_group("Resources" FILES ${plClient_RESOURCES}) diff --git a/cmake/PlasmaTargets.cmake b/cmake/PlasmaTargets.cmake index 18a32eb5b2..d79fd1b1c2 100644 --- a/cmake/PlasmaTargets.cmake +++ b/cmake/PlasmaTargets.cmake @@ -27,12 +27,9 @@ function(plasma_executable TARGET) if(_pex_WIN32) list(APPEND addexe_args WIN32) endif() - if(_pex_QT_GUI) + if(_pex_QT_GUI OR _pex_CLIENT) list(APPEND addexe_args WIN32 MACOSX_BUNDLE) endif() - if(_pex_CLIENT) - list(APPEND addexe_args MACOSX_BUNDLE) - endif() if(_pex_EXCLUDE_FROM_ALL) list(APPEND addexe_args EXCLUDE_FROM_ALL) endif() From baf230988594d71c9e9085ffd88bba85e20da5ab Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Sun, 5 Nov 2023 17:27:10 -0800 Subject: [PATCH 2/2] Support XIB compiling for non-Xcode projects --- Sources/Plasma/Apps/plClient/CMakeLists.txt | 7 ++++-- cmake/PlasmaTargets.cmake | 28 +++++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/Sources/Plasma/Apps/plClient/CMakeLists.txt b/Sources/Plasma/Apps/plClient/CMakeLists.txt index 3b5272fda3..72b9ace7a8 100644 --- a/Sources/Plasma/Apps/plClient/CMakeLists.txt +++ b/Sources/Plasma/Apps/plClient/CMakeLists.txt @@ -130,7 +130,10 @@ plasma_executable(plClient CLIENT INSTALL_PDB ) if(APPLE) - target_sources(plClient PRIVATE ${plClient_IBSOURCES}) + # We need to filter out the XIB files so the source XML files don't get bundled + set(plClient_XCODE_RESOURCES ${plClient_RESOURCES}) + list(FILTER plClient_XCODE_RESOURCES EXCLUDE REGEX "\\.xib$") + set_target_properties(plClient PROPERTIES MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/Mac-Cocoa/Info.plist.in" # Hard coding the app name here intentionally. @@ -142,7 +145,7 @@ if(APPLE) MACOSX_BUNDLE_GUI_IDENTIFIER org.Huru.UruExplorer MACOSX_BUNDLE_BUNDLE_VERSION "0.1" MACOSX_BUNDLE_SHORT_VERSION_STRING "0.1" - RESOURCE "${plClient_RESOURCES} ${plClient_IBSOURCES}" + RESOURCE "${plClient_XCODE_RESOURCES}" XCODE_ATTRIBUTE_ASSETCATALOG_COMPILER_APPICON_NAME AppIcon XCODE_ATTRIBUTE_MTL_FAST_MATH "YES" XCODE_ATTRIBUTE_MTL_ENABLE_DEBUG_INFO[variant=Debug] "INCLUDE_SOURCE" diff --git a/cmake/PlasmaTargets.cmake b/cmake/PlasmaTargets.cmake index d79fd1b1c2..dbdd6495ca 100644 --- a/cmake/PlasmaTargets.cmake +++ b/cmake/PlasmaTargets.cmake @@ -17,6 +17,13 @@ cmake_dependent_option( OFF ) +if(APPLE AND NOT CMAKE_GENERATOR STREQUAL "Xcode") + find_program(IBTOOL ibtool HINTS "/usr/bin" "${OSX_DEVELOPER_ROOT}/usr/bin") + if(NOT IBTOOL) + message(SEND_ERROR "Could not find Xcode's ibtool to process .xib files") + endif() +endif() + function(plasma_executable TARGET) cmake_parse_arguments(PARSE_ARGV 1 _pex "WIN32;CLIENT;TOOL;QT_GUI;EXCLUDE_FROM_ALL;NO_SANITIZE;INSTALL_PDB" @@ -65,6 +72,27 @@ function(plasma_executable TARGET) plasma_sanitize_target(${TARGET}) endif() + # Xcode will automatically run ibtool to compile the XIB files into NIB + # resources, but if we're generating Makefiles or Ninja projects then we + # need to handle that ourselves... + if(APPLE AND _pex_CLIENT) + foreach(SRCFILE IN LISTS _pex_SOURCES) + get_filename_component(SRCEXTENSION ${SRCFILE} LAST_EXT) + + if(CMAKE_GENERATOR STREQUAL "Xcode" AND ${SRCEXTENSION} STREQUAL ".xib") + set_source_files_properties(${SRCFILE} PROPERTIES MACOSX_PACKAGE_LOCATION Resources) + elseif(${SRCEXTENSION} STREQUAL ".xib") + set_source_files_properties(${SRCFILE} PROPERTIES HEADER_FILE_ONLY ON) + get_filename_component(XIBFILENAME ${SRCFILE} NAME_WE) + add_custom_command(TARGET ${TARGET} POST_BUILD + COMMAND ${IBTOOL} --output-format human-readable-text --compile "$/Resources/${XIBFILENAME}.nib" "${CMAKE_CURRENT_SOURCE_DIR}/${SRCFILE}" + COMMENT "Compiling ${SRCFILE} to ${XIBFILENAME}.nib" + VERBATIM + ) + endif() + endforeach() + endif() + if(DEFINED install_destination) install(TARGETS ${TARGET} DESTINATION ${install_destination}) if(_pex_INSTALL_PDB AND WIN32 AND NOT MINGW)