├── .gitattributes ├── .gitignore ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── XcodeCustomBuildRule.png └── icebuilder /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore objects and archives. 2 | xcuserdata 3 | build 4 | project.xcworkspace 5 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to the Ice Builder for Xcode 2 | 3 | Thank you for your interest in contributing to the Ice Builder for Xcode! 4 | 5 | ## How to Contribute 6 | 7 | To contribute code or documentation to this project, please follow these steps: 8 | 9 | 1. Review the [ZeroC Contributor Agreement](https://gist.github.com/zcabot/1a4c24dca55adaa83d78cdeabc63226b). 10 | The CLA assistant bot will ask you to sign this agreement when you submit 11 | your first pull request. 12 | 13 | 2. If you're planning to make a significant contribution, such as a new feature 14 | or major changes, please discuss your ideas with the community first by 15 | starting a [discussion](https://github.com/zeroc-ice/ice-builder-xcode/discussions) or by 16 | contacting us via [email](mailto:contributing@zeroc.com). 17 | 18 | 3. Fork this repository. 19 | 20 | 4. When implementing your contribution, please adhere to the project's naming 21 | and coding conventions to maintain consistency in the source code. 22 | 23 | 5. Submit a pull request. 24 | 25 | We review carefully any contribution that we accept, and these reviews may take 26 | some time. Please keep in mind there is no guarantee your contribution will be 27 | accepted: we may reject a pull request for any reason, or no reason. 28 | 29 | ## Contact 30 | 31 | - GitHub Discussions: 32 | - Twitter: 33 | - Email: 34 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | BSD 3-Clause License 2 | 3 | Copyright (c) ZeroC, Inc. All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, this 9 | list of conditions and the following disclaimer. 10 | 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | this list of conditions and the following disclaimer in the documentation 13 | and/or other materials provided with the distribution. 14 | 15 | * Neither the name of the copyright holder nor the names of its 16 | contributors may be used to endorse or promote products derived from 17 | this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 23 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 25 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 26 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 27 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Ice Builder for Xcode 2 | 3 | Ice Builder for Xcode is a command line program to help compile Slice files to 4 | C++ or Objective-C in Xcode. It supports all recent versions of Xcode. 5 | 6 | ## Install 7 | 8 | ### Homebrew 9 | 10 | Install Ice Builder for Xcode using Homebrew by running the following commands: 11 | ``` 12 | brew install zeroc-ice/tap/ice-builder-xcode 13 | ``` 14 | ### Manually 15 | 16 | Download the [icebuilder](icebuilder) shell script to any path on your system. 17 | For example: `/usr/local/bin/icebuilder`. 18 | 19 | ## Usage 20 | 21 | ### Options 22 | 23 | | Option | Description | 24 | | --------------- | ----------------------------------------------- | 25 | | --ice-home HOME | Set the Ice home directory. | 26 | | --cpp | Use `slice2cpp` instead of `slice2objc`. | 27 | | -h, --help | Print usage message. | 28 | | -v, --version | Display the version of Ice Builder. | 29 | | -- ARGS | Arguments passed directly to the Slice compiler.| 30 | 31 | If you do not set the Ice home directory with `--ice-home`, the builder first 32 | scans the `Additional SDKs` of your project, and attempts to find its `Ice home` 33 | in SDKs with `IceTouch` or `IceSDK` in their path. 34 | 35 | If there is no such SDK, the builder uses `/usr/local` as its Ice home 36 | directory. 37 | 38 | Refer to the [slice2cpp][1] and [slice2objc][2] _Command Line Options_ 39 | documentation for a description of the options you can provide through `ARGS`. 40 | You could for example invoke the builder with: 41 | ``` 42 | icebuilder --cpp -- -DFOO=1 --checksum 43 | ``` 44 | 45 | The builder automatically adds the following include directories to the 46 | Slice compilation: 47 | * the Ice Slice files directory provided by `Ice home` 48 | * the directory of the Slice file being compiled 49 | 50 | ### Xcode Build Rule 51 | 52 | To use Ice Builder for Xcode, you must create a custom build rule in your 53 | Xcode project. For example: 54 | 55 | * __Process__ `Source files with names matching:` `*.ice` 56 | * __Using__ `Custom script:` 57 | 58 | ``` 59 | /usr/local/bin/icebuilder [options] 60 | ``` 61 | * __Output Files__: 62 | * `$(DERIVED_FILE_DIR)/$(INPUT_FILE_BASE).h` 63 | * `$(DERIVED_FILE_DIR)/$(INPUT_FILE_BASE).cpp` (For a C++ project) 64 | * `$(DERIVED_FILE_DIR)/$(INPUT_FILE_BASE).m` (For an Objective-C project) 65 | 66 | ![Xcode Custom Build Rule](XcodeCustomBuildRule.png) 67 | 68 | The wildcard `*.ice` means Xcode will execute your custom script for each Slice 69 | file. 70 | 71 | The `Output Files` must list exactly two files: the header file and the 72 | C++ or Objective-C implementation file generated by the Slice compiler. 73 | These two files must be in the same directory: the builder sets `--output-dir` 74 | to this directory when it calls the Slice compiler. 75 | 76 | ### Xcode Build Settings 77 | 78 | Refer to the release notes of your Ice or Ice Touch distribution: 79 | * [Ice 3.7 Release Notes][3] 80 | * [Ice Touch 3.6 Release Notes][4] 81 | * [Ice Touch 1.3 Release Notes][5] 82 | 83 | ### Generating Code using Xcode 84 | 85 | The builder will always compile a Slice file when executed by an Xcode custom 86 | build rule; however, Xcode custom build rules are only executed when either the 87 | given `Output Files` do not exist or are older than the file being processed. 88 | To force your Slice files to be re-compiled you need to clean (⇧⌘K) your 89 | project, then build (⌘B). 90 | 91 | [1]: https://doc.zeroc.com/display/Ice/slice2cpp+Command-Line+Options 92 | [2]: https://doc.zeroc.com/display/Ice/slice2objc+Command-Line+Options 93 | [3]: https://doc.zeroc.com/display/Ice37/Using+the+macOS+Binary+Distribution 94 | [4]: https://doc.zeroc.com/display/Ice36/Using+the+Ice+Touch+Binary+Distribution 95 | [5]: https://doc.zeroc.com/display/IceTouch/Using+the+Binary+Distribution 96 | -------------------------------------------------------------------------------- /XcodeCustomBuildRule.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeroc-ice/ice-builder-xcode/d3a70f5c880b96ac95909c60cc5d6c89eff7cfb7/XcodeCustomBuildRule.png -------------------------------------------------------------------------------- /icebuilder: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # Copyright (c) ZeroC, Inc. All rights reserved. 4 | # 5 | set -eo pipefail 6 | 7 | readonly ICE_BUILDER_XCODE_VERSION=3.1.0 8 | 9 | logDebug() 10 | { 11 | [ -z "$DEBUG" ] || echo "$*" 12 | } 13 | 14 | logError() 15 | { 16 | echo "$*" >&2 17 | } 18 | 19 | calledFromXcode() 20 | { 21 | if [[ -z $XCODE_PRODUCT_BUILD_VERSION || -z $DERIVED_FILE_DIR || -z $INPUT_FILE_PATH ]]; then 22 | return 1 23 | fi 24 | return 0 25 | } 26 | 27 | # Run slice sliceCompiler. We always include Ice slice file directory as well as the INPUT_FILE_DIR. 28 | compileSliceFile() 29 | { 30 | logDebug "Compiling slice file: $INPUT_FILE_NAME" 31 | set -x # print the executed slice compiler command 32 | $sliceCompiler -I"$INPUT_FILE_DIR" \ 33 | -I"$sliceDir" \ 34 | --output-dir "$outputDir" \ 35 | "${sliceCompilerArguments[@]}" \ 36 | "$INPUT_FILE_PATH" 37 | } 38 | 39 | # Output directory is detected by comparing the SCRIPT_OUTPUT_FILE_{0,1} variables. 40 | # These are expected to the be the destination of the slice compiler generated header 41 | # and source files. Both files must share the same base directory, as this is how we 42 | # determine the output directory to pass to the slice compiler. 43 | setOutputDir() 44 | { 45 | if [ "$SCRIPT_OUTPUT_FILE_COUNT" -ne 2 ]; then 46 | logError "Please specify a header and source output file." 47 | return 1 48 | fi 49 | 50 | local -r outputFile0=${SCRIPT_OUTPUT_FILE_0} 51 | logDebug "Output file 0: $outputFile0" 52 | local -r outputFile1=${SCRIPT_OUTPUT_FILE_1} 53 | logDebug "Output file 1: $outputFile1" 54 | 55 | local -r outputFileDir0=$(dirname "$outputFile0") 56 | local -r outputFileDir1=$(dirname "$outputFile1") 57 | 58 | if [ "$outputFileDir0" != "$outputFileDir1" ]; then 59 | logError "Output files must be in the same directory." 60 | return 1 61 | fi 62 | 63 | outputDir="$outputFileDir0" 64 | } 65 | 66 | main() 67 | { 68 | if ! calledFromXcode; then 69 | logError "Ice Builder for Xcode must be executed from an Xcode environment." 70 | exit 0 71 | fi 72 | 73 | if ! setOutputDir; then 74 | exit 1 75 | fi 76 | 77 | # Always check user specified Ice home. Fail if the specified 78 | # directory does not exist or is not a valid Ice installation 79 | if [ -n "$iceHome" ]; then 80 | if ! setIceHomeDir "$iceHome"; then 81 | logError "${iceHome} is not a valid Ice distribution." 82 | exit 1 83 | fi 84 | else 85 | # Try the following in order: 86 | # 1. Search $ADDITIONAL_SDK_DIRS for a IceTouch-like SDK layout 87 | # 2. Search for an Ice installation in `/usr/local` 88 | if setIceSDKDir; then 89 | logDebug "Ice SDK (absolute path): $iceSDKDir" 90 | elif setIceHomeDir '/usr/local'; then 91 | logDebug "Ice Home: $iceHomeDir" 92 | else 93 | logError "Unable to find valid Ice, Ice SDK, or Ice Touch distribution." 94 | exit 1 95 | fi 96 | 97 | fi 98 | 99 | readonly iceVersion=$("$sliceCompiler" -v 2>&1) 100 | logDebug "Ice version: $iceVersion" 101 | 102 | compileSliceFile 103 | } 104 | 105 | # Check if given directory is a valid Ice installation and set required variables 106 | setIceHomeDir() 107 | { 108 | iceHomeDir="$1" 109 | 110 | # source build 111 | sliceDir="${iceHomeDir}/slice" 112 | sliceCompiler="${iceHomeDir}/cpp/bin/slice2${language}" 113 | [ -d "$sliceDir" ] && [ -x "$sliceCompiler" ] && return 0 114 | 115 | # "usr" style install 116 | sliceDir="${iceHomeDir}/share/ice/slice" 117 | sliceCompiler="${iceHomeDir}/bin/slice2${language}" 118 | [ -d "$sliceDir" ] && [ -x "$sliceCompiler" ] && return 0 119 | 120 | # "opt" style install 121 | sliceDir="${iceHomeDir}/slice" 122 | sliceCompiler="${iceHomeDir}/bin/slice2${language}" 123 | [ -d "$sliceDir" ] && [ -x "$sliceCompiler" ] && return 0 124 | 125 | # Unable to find Ice home; unset variables 126 | iceHomeDir= 127 | sliceDir= 128 | sliceCompiler= 129 | return 1 130 | } 131 | 132 | # Find SDK from ADDITIONAL_SDK_DIRS and set required variables 133 | setIceSDKDir() 134 | { 135 | for sdk in $ADDITIONAL_SDK_DIRS 136 | do 137 | local -r sdkDir=$(dirname "$sdk") 138 | 139 | # IceTouch == IceTouch 1.3 and 3.6 140 | # IceSDK == Ice 3.7 beta 141 | if [[ "$sdk" =~ "IceTouch" ]] || [[ "$sdk" =~ "IceSDK" ]]; then 142 | iceSDKDir="$sdk" 143 | sliceDir="${sdkDir}/slice" # Slice file directory included the SDK 144 | sliceCompiler="${sdkDir}/bin/slice2${language}" # Either 'slice2cpp' or 'slice2objc' 145 | 146 | # Check that the slice directory exists, and that the slice compiler exists and is executable 147 | [ -d "$sliceDir" ] && [ -x "$sliceCompiler" ] && return 0 148 | fi 149 | done 150 | 151 | # Unable to find Ice SDK; unset variables 152 | iceSDKDir= 153 | sliceDir= 154 | sliceCompiler= 155 | return 1 156 | } 157 | 158 | printUsage() 159 | { 160 | cat <] 162 | Options: 163 | -h, --help Show this message. 164 | -v, --version Display Ice Builder for Xcode version. 165 | --cpp Use slice2cpp. Default is slice2objc. 166 | --ice-home Location of Ice install. 167 | -- ARGS Pass agruments directly to the slice compiler. 168 | EOF 169 | } 170 | 171 | # 172 | # Process arguments and run slice compiler 173 | # 174 | logDebug "Ice Builder for Xcode version: $ICE_BUILDER_XCODE_VERSION" 175 | 176 | sliceCompilerArguments=() 177 | language=objc 178 | 179 | while [[ $# -gt 0 ]]; do 180 | opt="$1" 181 | case $opt in 182 | --cpp) 183 | language=cpp 184 | ;; 185 | -h|--help) 186 | printUsage 187 | exit 188 | ;; 189 | --ice-home) 190 | shift 191 | iceHome="$1" 192 | ;; 193 | -v|--version) 194 | echo "$ICE_BUILDER_XCODE_VERSION" 195 | exit 196 | ;; 197 | --) 198 | shift 199 | sliceCompilerArguments=("$@") 200 | break 201 | ;; 202 | *) 203 | logError "Unknown option: '$opt'" 204 | exit 1 205 | ;; 206 | esac 207 | shift 208 | done 209 | 210 | main 211 | --------------------------------------------------------------------------------