Skip to content
This repository has been archived by the owner on May 17, 2021. It is now read-only.

Setting public headers for Xcode framework target #66

Closed
novocodev opened this issue Feb 17, 2016 · 10 comments
Closed

Setting public headers for Xcode framework target #66

novocodev opened this issue Feb 17, 2016 · 10 comments

Comments

@novocodev
Copy link

I have built the 02-library example for Xcode with the following command:

build.py --clear --toolchain xcode --framework

This built a Framework, but it does not have any public headers in the framework Headers folder.

I added a public.h file to the example and added the following entry in the CMakeLists.txt

set_target_properties(
        foo PROPERTIES
        PUBLIC_HEADER public.h)

When building the public.h file is copied to '_install/xcode/lib/'

But the build fails with the error:

Expected only one lib in directory: .../_install/xcode/lib
But found: ['.../_install/xcode/lib/libfood.a', '.../_install/xcode/lib/public.h']

What is the correct way to configure the public headers for a framework build.

@ruslo
Copy link
Owner

ruslo commented Feb 17, 2016

Try to install headers to include directory. Explanation: this is workaround script which expect only one file in lib folder (which should be the *.a library) so when there are some other files script can't decide what file is a library.

Just for your information there are few fixes in latest CMake version that allow creating frameworks without hacks/workarounds (just using CMake). I haven't tried it yet, but if it works okay --framework option will be removed.

@novocodev
Copy link
Author

Still using make 3.3

cmake_minimum_required(VERSION 3.3)

I added the FRAMEWORK property

set_target_properties(
        foo PROPERTIES
        FRAMEWORK TRUE
        PUBLIC_HEADER public.h)

Then I built using the following command

./buildtools/polly/bin/build.py --clear --toolchain xcode

This created a Framework with 'public.h' in the Headers folder located at:

_builds/xcode/Debug/foo.framework

But this only appears to be a MAC OS X framework not a fat Framework, I ran the file command:

file _builds/xcode/Debug/foo.framework/foo

result was:

Mach-O 64-bit dynamically linked shared library x86_64

I also tried --toolchain ios-9-2 but the framework still appears to be created only for x86_64

@ruslo
Copy link
Owner

ruslo commented Feb 23, 2016

But this only appears to be a MAC OS X framework not a fat Framework

This is by design. Fat library created only for iOS.

I also tried --toolchain ios-9-2 but the framework still appears to be created only for x86_64

I will test latest CMake version with few improvements, may be will create an example.

@ruslo
Copy link
Owner

ruslo commented Feb 24, 2016

What is the correct way to configure the public headers for a framework build

Okay, I think I know what is the problem here. --framework option expect headers be located in directory <install-prefix>/include/<frameworkname>. I.e. if you have library libfoo.dylib installed, then headers should be located in <install-prefix>/include/foo and will be moved to foo.framework/Headers. The reason of this is that project which uses foo should do #include <foo/*.hpp> in both variants. I've added warning to build.py script, so you should see next message:

Warning: no headers found for framework (dir: /.../_install/ios-9-1-armv7/include/boo)

Which can be fixed by next CMake code:

install(FILES boo.hpp DESTINATION include/boo)

I also tried --toolchain ios-9-2 but the framework still appears to be created only for x86_64

Are you sure you're using patched CMake version?

@ruslo
Copy link
Owner

ruslo commented Feb 24, 2016

Example with framework and native Xcode project updated:

@novocodev
Copy link
Author

Great! I have successfully built and linked the ios-dynamic-framework project.

I did have to use patched CMake version, I tried with the latest 3.5.0-rc2 CMake but that failed to build the Fat framework bundle.

I'm going to try and replicate the project setup to my own library repo.

@ruslo
Copy link
Owner

ruslo commented Mar 2, 2016

but that failed to build the Fat framework bundle

With CMake 3.5+ you have to use CMAKE_IOS_INSTALL_COMBINED=YES and CMAKE_XCODE_ATTRIBUTE_ONLY_ACTIVE_ARCH=NO and run install (no need to use --framework, now it's --install). However dynamic framework will not be signed properly so the last time I've tried it I failed to run bundle on real device.

@novocodev
Copy link
Author

I have replicated the demo project setup on my own repo, I did not copy over the custom jenkins.py as I am just trying to build a dynamic library component, I am calling build.py directly with:

./buildtools/polly/bin/build.py --clear --toolchain ios-9-2 --framework --config Release

The build is successful and the lib binary now reports as a Fat lib and the public header is copied over to the framework/Headers folder.

I have noticed that if I build with --config Debug, that 'd' gets appended to the project name for all folders and files and it also causes the public header not to get copied to framework/Headers (unless I install it to an include/'d' folder.

Is there a way to prevent the 'd' suffix getting added and maybe create the framework under a debug or release folder depending on the --config value.

@ruslo
Copy link
Owner

ruslo commented Mar 3, 2016

Is there a way to prevent the 'd' suffix getting added

Set it in command line -DCMAKE_DEBUG_POSTFIX="", in terms of build.py script it will be --fwd CMAKE_DEBUG_POSTFIX=""

@novocodev
Copy link
Author

Both iOS and OSX framework builds are working, thanks.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants