Skip to content

Commit

Permalink
Support XIB compiling for non-Xcode projects
Browse files Browse the repository at this point in the history
Co-Authored-By: Adam Johnson <[email protected]>
  • Loading branch information
dpogue and Hoikas committed Oct 9, 2023
1 parent 99dad0d commit be98a08
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Sources/Plasma/Apps/plClient/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
include(XcodeHelpers)

set(external_SCRIPTS
external/create_resource_dat.py
external/makeres.py
Expand Down Expand Up @@ -138,7 +140,8 @@ plasma_executable(plClient CLIENT INSTALL_PDB
)

if(APPLE)
target_sources(plClient PRIVATE ${plClient_IBSOURCES})
target_xib_resources(plClient SOURCES ${plClient_IBSOURCES})

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 Down
29 changes: 29 additions & 0 deletions cmake/XcodeHelpers.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Inspired by https://catfox.life/2022/08/14/compiling-xibs-with-cmake-without-xcode/
function(target_xib_resources TARGET)
cmake_parse_arguments(PARSE_ARGV 1 _pxib
""
""
"SOURCES"
)

# 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 (CMAKE_GENERATOR STREQUAL "Xcode")
target_sources(${TARGET} PRIVATE ${_pxib_SOURCES})
else()
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()

foreach(XIBFILE IN LISTS _pxib_SOURCES)
get_filename_component(XIBFILENAME ${XIBFILE} 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}/${XIBFILE}"
COMMENT "Compiling ${XIBFILE} to ${XIBFILENAME}.nib"
VERBATIM
)
endforeach()
endif()
endfunction()

0 comments on commit be98a08

Please sign in to comment.