Coder Social home page Coder Social logo

mulle-xcode-to-cmake's Introduction

mulle-xcode-to-cmake

A little tool to convert Xcode projects to cmake CMakeLists.txt.

You can specify the target to export. If you don't specify a target, all targets are exported. It doesn't do a perfect job, but it's better than doing it all by hand. It can convert most targets, but it will do better with libraries and tools or frameworks.

This is useful for "one-shot" conversions. For continous conversions from Xcode to cmake, use mulle-sde.

Build Status Version
CI Mulle kybernetiK tag

Install

MacOS : Apple

Use the homebrew package manager to install it, or build it yourself with Xcode:

brew install mulle-kybernetik/software/mulle-xcode-to-cmake

Build

MacOS / Linux / FreeBSD : mulle-objc

Get foundation-developer installed and then build mulle-xcode-to-cmake with:

mulle-sde clean cache
mulle-sde craft --release
mulle-sde run mulle-make install --prefix /usr/local/bin

Windows / Linux : GNUstep

It is also possible to build with GNUstep using cmake and the CMakeLists.txt file generated by mulle-xcode-to-cmake itself. After checking out the sources, change into the source directory and then:

mkdir build && cd build
cmake -Wno-dev ..
make
sudo make install

On Mac this should work without installing any additional dependencies. On other platforms it is suggested to install a recent clang version (5 or later) and you will need libobjc and the gnustep-base developer package, both from GNUstep (or another implementation of the ObjC runtime and the Foundation library).

On Windows, it is a bit tricky : please refer to this little guide here

Usage

usage: mulle-xcode-to-cmake [options] <commands> <file.xcodeproj>

Options:
   -2          : CMakeLists.txt includes CMakeSourcesAndHeaders.txt
   -a          : always prefix cmake variables with target
   -b          : suppress boilerplate definitions
   -d          : create static and shared library
   -f          : suppress Foundation (implicitly added)
   -i          : print global include_directories
   -l <lang>   : specify project language (c,c++,objc) (default: objc)
   -n          : suppress find_library trace
   -p          : suppress project
   -P <prefix> : prefix filepaths
   -r          : suppress reminder, what generated this file
   -s <suffix> : create standalone test library (framework/shared)
   -t <target> : target to export
   -u          : add UIKIt
   -w <name>   : add weight to name for sorting

Commands:
   export      : export CMakeLists.txt to stdout
   list        : list targets
   sexport     : export CMakeSourcesAndHeaders.txt to stdout

Environment:
   VERBOSE     : dump some info to stderr

Examples

List all project targets:

$ mulle-xcode-to-cmake list mulle-xcode-to-cmake.xcodeproj
mulle-xcode-to-cmake
mullepbx

Create "CMakeLists.txt" for target mullepbx leaving out some boilerplate template code. Invoking mulle-xcode-to-cmake -b export mulle-xcode-to-cmake.xcodeproj yields:

# Generated by mulle-xcode-to-cmake [2017-2-21 18:16:4]

project( mulle-xcode-to-cmake)

cmake_minimum_required (VERSION 3.4)


##
## mulle-xcode-to-cmake Files
##

set( MULLE_XCODE_TO_CMAKE_SOURCES
src/mulle-xcode-to-cmake/NSArray+Path.m
src/mulle-xcode-to-cmake/NSString+ExternalName.m
src/mulle-xcode-to-cmake/PBXHeadersBuildPhase+Export.m
src/mulle-xcode-to-cmake/PBXPathObject+HierarchyAndPaths.m
src/mulle-xcode-to-cmake/main.m
)

find_library( MULLEPBX_LIBRARY mullepbx)
message( STATUS "MULLEPBX_LIBRARY is ${MULLEPBX_LIBRARY}")

set( MULLE_XCODE_TO_CMAKE_STATIC_DEPENDENCIES
${MULLEPBX_LIBRARY}
)

find_library( FOUNDATION_LIBRARY Foundation)
message( STATUS "FOUNDATION_LIBRARY is ${FOUNDATION_LIBRARY}")

set( MULLE_XCODE_TO_CMAKE_DEPENDENCIES
${FOUNDATION_LIBRARY}
)


##
## mullepbx Files
##

set( MULLEPBX_PUBLIC_HEADERS
src/PBXReading/MullePBXUnarchiver.h
src/PBXReading/PBXObject.h
src/PBXWriting/MullePBXArchiver.h
src/PBXWriting/PBXObject+PBXEncoding.h
)

set( MULLEPBX_PROJECT_HEADERS
)

set( MULLEPBX_PRIVATE_HEADERS
src/PBXReading/NSObject+DecodeWithObjectStorage.h
src/PBXReading/NSString+KeyFromSetterSelector.h
src/PBXReading/NSString+LeadingDotExpansion.h
src/PBXReading/PBXProjectProxy.h
src/PBXWriting/MulleSortedKeyDictionary.h
)

set( MULLEPBX_SOURCES
src/PBXReading/MullePBXUnarchiver.m
src/PBXReading/NSObject+DecodeWithObjectStorage.m
src/PBXReading/NSString+KeyFromSetterSelector.m
src/PBXReading/NSString+LeadingDotExpansion.m
src/PBXReading/PBXObject.m
src/PBXReading/PBXProjectProxy.m
src/PBXWriting/MullePBXArchiver.m
src/PBXWriting/MulleSortedKeyDictionary.m
src/PBXWriting/PBXObject+PBXEncoding.m
)


##
## mulle-xcode-to-cmake
##

add_executable( mulle-xcode-to-cmake MACOSX_BUNDLE
${MULLE_XCODE_TO_CMAKE_SOURCES}
${MULLE_XCODE_TO_CMAKE_PUBLIC_HEADERS}
${MULLE_XCODE_TO_CMAKE_PROJECT_HEADERS}
${MULLE_XCODE_TO_CMAKE_PRIVATE_HEADERS}
${MULLE_XCODE_TO_CMAKE_RESOURCES}
)

target_include_directories( mulle-xcode-to-cmake
   PUBLIC
      src/PBXReading
      src/PBXWriting
)

add_dependencies( mulle-xcode-to-cmake mullepbx)

target_link_libraries( mulle-xcode-to-cmake
${MULLE_XCODE_TO_CMAKE_STATIC_DEPENDENCIES}
${MULLE_XCODE_TO_CMAKE_DEPENDENCIES}
)


##
## mullepbx
##

add_library( mullepbx STATIC
${MULLEPBX_SOURCES}
${MULLEPBX_PUBLIC_HEADERS}
${MULLEPBX_PROJECT_HEADERS}
${MULLEPBX_PRIVATE_HEADERS}
${MULLEPBX_RESOURCES}
)

target_include_directories( mullepbx
   PUBLIC
      src/PBXReading
      src/PBXWriting
)

install( TARGETS mullepbx DESTINATION "lib")
install( FILES ${MULLEPBX_PUBLIC_HEADERS} DESTINATION "include/mullepbx")

You have your own CMakeLists.txt template and just want to include() the list of sources as they change in the Xcode project:

mulle-xcode-to-cmake sexport mulle-xcode-to-cmake.xcodeproj yields:

##
## mulle-xcode-to-cmake Files
##

set( MULLE_XCODE_TO_CMAKE_SOURCES
src/mulle-xcode-to-cmake/NSArray+Path.m
src/mulle-xcode-to-cmake/NSString+ExternalName.m
src/mulle-xcode-to-cmake/PBXHeadersBuildPhase+Export.m
src/mulle-xcode-to-cmake/PBXPathObject+HierarchyAndPaths.m
src/mulle-xcode-to-cmake/main.m
)


##
## mullepbx Files
##

set( MULLEPBX_PUBLIC_HEADERS
src/PBXReading/MullePBXUnarchiver.h
src/PBXReading/PBXObject.h
src/PBXWriting/MullePBXArchiver.h
src/PBXWriting/PBXObject+PBXEncoding.h
)

set( MULLEPBX_SOURCES
src/PBXReading/MullePBXUnarchiver.m
src/PBXReading/NSObject+DecodeWithObjectStorage.m
src/PBXReading/NSString+KeyFromSetterSelector.m
src/PBXReading/NSString+LeadingDotExpansion.m
src/PBXReading/PBXObject.m
src/PBXReading/PBXProjectProxy.m
src/PBXWriting/MullePBXArchiver.m
src/PBXWriting/MulleSortedKeyDictionary.m
src/PBXWriting/PBXObject+PBXEncoding.m
)

History

This is basically a stripped down version of mulle_xcode_utility.

See the RELEASENOTES.md for what has changed.

Author

Coded by Nat!

Contributors

Contributors

mulle-xcode-to-cmake's People

Contributors

codeon-nat avatar elmostafaidrassi avatar mingwandroid avatar mulle-nat avatar rjvb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

mulle-xcode-to-cmake's Issues

CMake project name not quoted when name contains spaces

When generating a CMakeLists.txt file for an Xcode project which includes space characters in its name: https://github.com/saxbophone/Blank-Mack-Oss-Screensaver/tree/f2487de098cde50e4901b5259989889923dc5f06

The CMake file does not quote the project name that contains spaces: https://github.com/saxbophone/Blank-Mack-Oss-Screensaver/blob/ccf8ed83ec45cf7d74b7f4967e6359b3365f02a1/CMakeLists.txt#L1-L5

# Generated on 2019-4-16 1:50:56 by version CURRENT_PROJECT_VERSION of mulle-xcode-to-cmake 
# Command line: 
#    mulle-xcode-to-cmake export Blank Mack-Oss Screensaver.xcodeproj/ 

project( Blank Mack-Oss Screensaver) 

This is inconvenient because it leads to a CMake file that will not build, the project name has to be quoted if it contains spaces due to CMake argument-passing conventions.

This issue is present in v0.7.1 and at least one other earlier version too.

Syntax error with `set_target_properties`.

I am trying to convert the MoltenVK xcodeprojs into CMakeLists.txt files using this software and while things work really well, far better than I expected, I am getting syntax errors due to an extra paren being emitted as follows:

set_target_properties( MoltenVK-macOS_shared
   PROPERTIES
   OUTPUT_NAME MoltenVK-macOS)
)

We see a closing paren after the output name then another on the next line.

Fails to correct paths from "hidden" Xcode projects

Xcode projects do not have to be in the project root directory, but can be in a subdirectory.
For example, VLC ships a vlc.xcodeproj as extras/package/macosx/vlc.xcodeproj.
mulle-xcode-to-cmake creates a CMakeSourcesAndHeaders.txt file that contains paths that are
relative to the .xcodeproj file's directory, instead of relative to the toplevel directory
(if that's where mulle-xcode-to-cmake is invoked).

Converting xcode with REZ files?

Hey
I'm in need of having rez -resource file generated from my xcode... any idea if this lib could be extended to support them?

Failed case with Photoshop SDK

Hey,
I tried to use your product on the default photoshop plugin SDK project.
The files' paths in the output CmakeLists.txt file were incorrect and the plist definition seems to be incorrect

A zip of the project itself (without the full SDK):
poormanstypetool.xcodeproj.zip

Thanks!

Feature request: path modifier

I love this tool! Thank you for creating it!

Would be excellent addition ability to modify/extended path to files with some argument.

PROJECT() called before CMAKE_MINIMUM_REQUIRED() in CMake export

When exporting this Xcode project I have: https://github.com/saxbophone/Blank-Mack-Oss-Screensaver/tree/f2487de098cde50e4901b5259989889923dc5f06

The generated CMakeLists.txt file contains a call to project() first, before a call to cmake_minimum_required(): https://github.com/saxbophone/Blank-Mack-Oss-Screensaver/blob/ccf8ed83ec45cf7d74b7f4967e6359b3365f02a1/CMakeLists.txt#L1-L7

# Generated on 2019-4-16 1:50:56 by version CURRENT_PROJECT_VERSION of mulle-xcode-to-cmake 
# Command line: 
#    mulle-xcode-to-cmake export Blank Mack-Oss Screensaver.xcodeproj/ 

project( Blank Mack-Oss Screensaver) 

cmake_minimum_required (VERSION 3.4) 

This can be problematic because if for example, I want to use features of project() that only a specific version of CMake includes (like the VERSION property), I need to specify the CMake version first.

I think in general, it is conventional to specify the minimum required CMake version before any other commands in a CMake file.

This issue is present in v0.7.1 and at least one other earlier version too.

error: tool 'xcodebuild' requires Xcode

$ brew install mulle-kybernetik/software/mulle-xcode-to-cmake
Updating Homebrew...
==> Auto-updated Homebrew!
Updated Homebrew from a8aed381c to 23da62471.
Updated 2 taps (homebrew/cask-versions and homebrew/core).
==> Updated Formulae
beagle              fatsort             [email protected]        netdata
bison               krakend             [email protected]        scrcpy
bitwarden-cli       libpq               meson               shfmt
botan               libtensorflow       mkvtoolnix          xonsh

==> Tapping mulle-kybernetik/software
Cloning into '/usr/local/Homebrew/Library/Taps/mulle-kybernetik/homebrew-software'...
remote: Enumerating objects: 53, done.
remote: Counting objects: 100% (53/53), done.
remote: Compressing objects: 100% (52/52), done.
remote: Total 53 (delta 21), reused 5 (delta 0), pack-reused 0
Unpacking objects: 100% (53/53), done.
Tapped 49 formulae (127 files, 82.7KB).
==> Installing mulle-xcode-to-cmake from mulle-kybernetik/software
==> Downloading https://github.com/mulle-nat/mulle-xcode-to-cmake/archive/0.7.0.
==> Downloading from https://codeload.github.com/mulle-nat/mulle-xcode-to-cmake/
######################################################################## 100.0%
==> xcodebuild DSTROOT=/usr/local/Cellar/mulle-xcode-to-cmake/0.7.0 INSTALL_PATH
Last 15 lines from /Users/nguyenhachi/Library/Logs/Homebrew/mulle-xcode-to-cmake/01.xcodebuild:
2018-11-12 14:06:31 +0700

xcodebuild
DSTROOT=/usr/local/Cellar/mulle-xcode-to-cmake/0.7.0
INSTALL_PATH=/bin
install

xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance

If reporting this issue please do so at (not Homebrew/brew or Homebrew/core):
https://github.com/mulle-kybernetik/homebrew-software/issues

When exporting targets that are Core Foundation Bundles, properties are set twice

This project is a macOS Screensaver: https://github.com/saxbophone/Blank-Mack-Oss-Screensaver/tree/f2487de098cde50e4901b5259989889923dc5f06

If I understand correctly, macOS Screensavers are Core Foundation Bundles (plugin-style).

When exporting such an Xcode project to CMake, set_target_properties() is called twice on the Bundle target:

if (APPLE)
   set_target_properties( Blank-Mack-Oss-Screensaver PROPERTIES
BUNDLE TRUE
MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/Blank-Mack-Oss-Screensaver-Info.plist.in"
)
endif()

if (APPLE)
   set_target_properties( Blank-Mack-Oss-Screensaver PROPERTIES
MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/Blank-Mack-Oss-Screensaver-Info.plist.in"
)
endif()

Note that only the first of these has the property BUNDLE set to TRUE.

This isn't massively inconvenient and I confess to not know enough about Xcode project internals to know if it is something that can easily be addressed, but it does seem erroneous.

This issue is present in v0.7.1 and at least one other earlier version too.

[kudos] also runs on Linux using GNUstep :)

Just a little heads/thumbs-up/kudo : it wasn't very hard to get this application to build and run on Linux - and thus presumably on any other platform that has GNUstep and clang (just libgnustep-base and libobjc).

I could probably have made a CMake file by hand, but I just ran the app on its own xcodeproj file on Mac and edited it so it finds the required GNUstep dependencies: CMakeLists.txt.
Then it was a question of a few minor changes to the code: there's no [NSString constainsString:] (on Mac it's only available on 10.10 and later BTW), nor a NSDebugEnabled. Patches:
https://github.com/RJVB/lnxports/blob/master/devel/mulle-xcode-to-cmake/files/patch-containsString.diff
https://github.com/RJVB/lnxports/blob/master/devel/mulle-xcode-to-cmake/files/patch-gnustep.diff

Failed homebrew install

Seems like brew is broken, at least for me. (MacOS Sierra, XCode 9)

Transcript as follows. Snipped usual homebrew update cruft;-

Cloning into '/usr/local/Homebrew/Library/Taps/mulle-kybernetik/homebrew-software'...
remote: Counting objects: 31, done.
remote: Compressing objects: 100% (31/31), done.
remote: Total 31 (delta 18), reused 2 (delta 0), pack-reused 0
Unpacking objects: 100% (31/31), done.
Tapped 28 formulae (82 files, 59.3KB)
==> Installing mulle-xcode-to-cmake from mulle-kybernetik/software
==> Downloading https://github.com/mulle-nat/mulle-xcode-to-cmake/archive/0.6.5.tar.gz
==> Downloading from https://codeload.github.com/mulle-nat/mulle-xcode-to-cmake/tar.gz/0.6.5
######################################################################## 100.0%
==> xcodebuild install -target mulle-xcode-to-cmake DSTROOT=/ INSTALL_PATH=/usr/local/Cellar/mulle-xcode-to-cmake/0.6.5/bin
Last 15 lines from /Users/shayneoneill/Library/Logs/Homebrew/mulle-xcode-to-cmake/01.xcodebuild:
error: open /usr/local/include/NSString+LeadingDotExpansion.h: Operation not permitted

** INSTALL FAILED **


The following build commands failed:
	CpHeader src/PBXWriting/MullePBXArchiver.h /usr/local/include/MullePBXArchiver.h
	CpHeader src/PBXReading/MullePBXUnarchiver.h /usr/local/include/MullePBXUnarchiver.h
	CpHeader src/PBXReading/PBXObject.h /usr/local/include/PBXObject.h
	CpHeader src/PBXWriting/PBXObject+PBXEncoding.h /usr/local/include/PBXObject+PBXEncoding.h
	CpHeader src/PBXWriting/MulleSortedKeyDictionary.h /usr/local/include/MulleSortedKeyDictionary.h
	CpHeader src/PBXReading/NSObject+DecodeWithObjectStorage.h /usr/local/include/NSObject+DecodeWithObjectStorage.h
	CpHeader src/PBXReading/NSString+KeyFromSetterSelector.h /usr/local/include/NSString+KeyFromSetterSelector.h
	CpHeader src/PBXReading/NSString+LeadingDotExpansion.h /usr/local/include/NSString+LeadingDotExpansion.h
(8 failures)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.