Make a compiled framework headers public - objective-c

How can I make a compiled framework's header files as public so I want to make use of it outside another framework?
i make it arm64 only with lipo but is there an option with lipo for this?

Related

Best way to build a cmake static library from a parent cmake dynamic/static library

I would like to add this cmake-based static library
https://github.com/google/highway
to my static or dynamic library
https://github.com/GrokImageCompression/grok
So, I would like to build static library first, then build the dynamic library
and link to the static library.
I have added the static library as a subfolder, and the .a file is being generated in my
cmake binary folder. But, I am not sure how to link to this library
target_link_libraries(${PARENT_LIBRARY_NAME} ${PARENT_BIN_DIR}/hwy)
doesn't work.
You need to use the name of the target in the call to target_link_libraries, i.e. target_link_libraries(${PARENT_LIBRARY_NAME} PUBLIC hwy) or target_link_libraries(${PARENT_LIBRARY_NAME} PRIVATE hwy) depending on whether you make use of hwys headers in public headers of the parent library (choose PUBLIC) or only in the implementation of the parent library (choose PRIVATE).

Qt5 mingw - How to add required dlls to run an app standalone?

I made an application with Qt5(mingw). To run this application out of qtcreator, I have to put some dlls like Qt5Widgets.dll, Qt5Core.dll, ... beside the executable file. I tried to add these libraries to project, but "Add Library" option doesn't accept dll! I can only add static library(*.lib).
I just want to add required dlls to my project and make a *.exe file in output, without any dependency and no any dll around the executable file.
You want to build your application with static linkage. For static linkage you need to compile your Qt with -static option.
How to build static Qt:
For linux: http://doc.qt.io/qt-5/linux-deployment.html
For Windows: I used this guide https://wiki.qt.io/Building_a_static_Qt_for_Windows_using_MinGW
Note: even with static linkage I provide msvcr110.dll and msvcr120.dll with my app, so I have .exe + 2 dlls. But maybe I do some things wrong, but at least I have 3 files instead of tons of it.

CMake: header-only library with generated files

I have a library that needs to carry some constant data injected from the content of non-source files (in this case, OpenGL shader code). To achieve this, I'm using add_custom_command() to generate include files that I can then #include into my code to initialize const static variables.
This works perfectly with regular libraries (static or shared), but now I'd like to make my library header-only. The ability of C++ to let static methods return static data without running the risk of having that data duplicated in each translation unit ("magic statics") makes this possible.
The problem however is that CMake seems to assume that an INTERFACE library (which is the CMake feature that I'm using to create header-only libraries) does not need building - which, in this case, is wrong.
(I realize that there is no actual obligation for my library to be header-only. In this particular case, the reason I want this is that I would like the library, which is doing OpenGL, to remain independent of any specific binding library [such as GLEW or GLee or the newcomer glbinding]. By keeping my library header-only, I can leave that choice to the user - all he needs to do is #include the header of the binding library before mine.)
Does anyone see a way to have CMake trigger the header-generating custom commands, at the latest when the consumer project is being built?
EDIT: I just realized that I could have the "best of both worlds" as it were by keeping my library static but still keeping all my code except for the constant data in the header files. That way, there would still be no need to choose a specific OpenGL binding library.
However, there are still advantages to having a library be header-only - simplicity of use for one - so I'm leaving my question open.
EDIT #2: Here is the relevant part of my CMakeLists.txt file (I only stripped the library dependencies - all header-only - from the end):
set(SHADER_FILES "src/vertex.glsl" "src/fragment.glsl")
add_library(libGPCGUIGLRenderer INTERFACE)
target_sources(libGPCGUIGLRenderer INTERFACE ${SHADER_FILES})
target_include_directories(libGPCGUIGLRenderer BEFORE
INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
# Embed shader files
source_group("Shader files" FILES ${SHADER_FILES})
set(GENERATED "${CMAKE_CURRENT_BINARY_DIR}/generated")
target_include_directories(libGPCGUIGLRenderer INTERFACE ${GENERATED})
# Find the GPC Bin2C utility
find_package(GPCBin2C REQUIRED)
# Add a custom target and a dependency for each shader file
foreach(shader ${SHADER_FILES})
get_filename_component(name "${shader}" NAME)
set(shader_header "${GENERATED}/${name}.h")
add_custom_command(
OUTPUT ${shader_header}
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${shader}
COMMAND GPCBin2C --input=${CMAKE_CURRENT_SOURCE_DIR}/${shader} --output=${shader_header}
)
target_sources(libGPCGUIGLRenderer INTERFACE ${shader_header})
endforeach()
Creating a static library with headers as the only sources worked for me. It is, of course, only a work-around.
Creating a static library with only header files results in an empty library. Mine says !<arch> as the only content.
CMake will automatically get the dependencies correct across sub-directories.
Since all sources are headers, you need to tell CMake which linker language should be used.
Code:
set(OUTDIR "${CMAKE_CURRENT_BINARY_DIR}/generated_include")
add_custom_command(
OUTPUT "${OUTDIR}/outfile.h"
# Replace the next two lines with a proper generating script.
COMMAND mkdir -p ${OUTDIR}
COMMAND touch ${OUTDIR}/outfile.h
)
# Note, I am only adding header files to the library.
add_library(generated-headers STATIC
"${OUTDIR}/outfile.h"
)
set_target_properties(generated-headers
PROPERTIES LINKER_LANGUAGE CXX)
target_include_directories(generated-headers PUBLIC ${OUTDIR})
Use in other directories like this:
# In any other directory of the same CMake project:
add_executable(main main.cpp)
target_link_libraries(main generated-headers)
Tested on CMake 3.2, 3.8 and 3.9. Using Ninja and Make generators.
You can use target_sources in CMake 3.1 to tell consumers to compile interface files:
add_library(source_only INTERFACE)
target_sources(source_only INTERFACE foo.cpp)
http://www.cmake.org/cmake/help/v3.1/command/target_sources.html
I ran into comparable problems when trying to use glad: https://github.com/Dav1dde/glad
It uses a custom CMake command to build a binding, which means the files you need to include in the project which uses glad do not exist, so that CMake does not build glad (which would create those files)...
I did not get to try it yet, but example 3 of the following link seems to be a good solution and I believe it may work in your case:
https://samthursfield.wordpress.com/2015/11/21/cmake-dependencies-between-targets-and-files-and-custom-commands/

Use includes of adjacent subproject in cmake

I develop a project which consisting of several shared libraries and build it with CMake.
Each library is built via add_subdirectory().
What is the best way to add all the API headers of the fist library to the CMakeLists.txt of the second?
Encode the include directories in the target itself:
http://www.cmake.org/cmake/help/git-master/manual/cmake-buildsystem.7.html#include-directories-and-usage-requirements
That doc is new, but the target_include_directories command exists since CMake 2.8.11. Use it with the INTERFACE or PUBLIC option.
To make an answer of steveire complete:
for the library which exports API we should write
target_include_directories("target_with_api" INTERFACE "path_to_api_includes")
and for the library which uses this API we write
target_include_directories("api_client_target_name" PRIVATE
$<TARGET_PROPERTY:"target_with_api",INTERFACE_INCLUDE_DIRECTORIES>)
where $<TARGET_PROPERTY:"target_with_api",INTERFACE_INCLUDE_DIRECTORIES>) returns us target property assigned to the library with API

how to put compiler command line args in specific places using cmake

So I'm building a shared library, out of two static libraries.
This answer says the way to do it is to insert -Wl,--whole-archive before my static libs, the -Wl,--no-whole-archive after them.
So what I have in cmake at the moment for the shared library is:
add_library(wittyPlus SHARED empty.cpp)
target_link_libraries(wittyPlus
${wtdbosqlite}
${WT_LIBRARIES}
${DB_LIBRARIES}
${Boost_LIBRARIES}
app models
)
So what I need is for it to add the -Wl,--whole-archive before app and models, then -Wl,--no-whole-archive after them (so that the standard library imports don't get exported by the shared lib).
What's the easiest way to do this in CMake ?
Addition: So I'd like to use the standard cmake stuff as much as possible, that way I don't have to do any extra work for windows builds, as CMake kindly removes the compiler definitions that aren't supported on the platform being built.
OK, it was much easier than I thought.
So according to the cmake docs:
Item names starting with '-', but not '-l' or '-framework', are
treated as linker flags.
So the fix was just to:
add_library(wittyPlus SHARED empty.cpp)
target_link_libraries(wittyPlus
${wtdbosqlite}
${WT_LIBRARIES}
${DB_LIBRARIES}
${Boost_LIBRARIES}
"-Wl,--whole-archive"
app models
"-Wl,--no-whole-archive"
)
I don't know if it'll work on windows or not, I expect it will as cmake is super clever.
Looking at the result with objdump, it does seem to have a lot of boost stuff in the exports, so I might be doing something wrong.
objdump -C -t wittyPlus/libwittyPlus.so | grep -i boost
But it does have the stuff I need to link against it so, that's a step forward.
Any other answers still appreciated. Basically what I'm trying to do is the same as this question:
CMake: how create a single shared library from all static libraries of subprojects?
If you are building the static libraries yourself, you can use this approach: https://stackoverflow.com/a/29824424/4069571 namely building them as object libraries first, then linking them into the respective shared and static libs.