Skip to content

Commit

Permalink
Support XIB compiling for non-Xcode projects
Browse files Browse the repository at this point in the history
  • Loading branch information
dpogue committed Nov 13, 2023
1 parent d65b8e7 commit baf2309
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
7 changes: 5 additions & 2 deletions Sources/Plasma/Apps/plClient/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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"
Expand Down
28 changes: 28 additions & 0 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 Down Expand Up @@ -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 "$<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

0 comments on commit baf2309

Please sign in to comment.