-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support XIB compiling for non-Xcode projects
Co-Authored-By: Adam Johnson <[email protected]>
- Loading branch information
Showing
2 changed files
with
33 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |