Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support XIB compiling for non-Xcode projects #1499

Merged
merged 2 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 24 additions & 32 deletions Sources/Plasma/Apps/plClient/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -109,28 +109,32 @@ 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/[email protected]
Mac-Cocoa/MainMenu.xib
Mac-Cocoa/PLSLoginWindowController.xib
Mac-Cocoa/PLSPatcherWindowController.xib
Mac-Cocoa/banner.png
Mac-Cocoa/[email protected]
win32/res/Dirt.ICO
)

list(APPEND plClient_RESOURCES
win32/res/Dirt.ICO
)
else()
list(APPEND plClient_SOURCES
main.cpp
)
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})
# 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
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
Expand All @@ -141,42 +145,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_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"
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)
Expand Down Expand Up @@ -240,6 +230,8 @@ target_link_libraries(
$<$<BOOL:${PLASMA_PIPELINE_DX}>:pfDXPipeline>
$<$<BOOL:${PLASMA_PIPELINE_GL}>:pfGLPipeline>
CURL::libcurl
"$<$<PLATFORM_ID:Darwin>:-framework Cocoa>"
"$<$<PLATFORM_ID:Darwin>:-framework QuartzCore>"
)
target_include_directories(plClient PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}")

Expand Down Expand Up @@ -269,4 +261,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})
33 changes: 29 additions & 4 deletions cmake/PlasmaTargets.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -27,12 +34,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()
Expand Down Expand Up @@ -68,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 "$<TARGET_BUNDLE_CONTENT_DIR:${TARGET}>/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)
Expand Down