Problem
How can I distribute a c++ library as source code along with the source code of libcurl and let the consumer of the library handle building it as needed? I'm using FastBuild as a build system.
Context
I have a C++ library that I distribute as source and let the clients handle building it along with their code.
The repo includes the source for a dependency as well, tinyxml, which is built along with the library itself thus becoming completely transparent for the clients.
It has worked fine up to now but clearly does not scale well for more complex dependencies, such as libcurl.
Things I've considered as an alternative to bundling libcurl's source
have pre-compiled libraries of libcurl. But I don't know which platforms/flags the consumer is going to use
have libcurl installed on the build machine. It would require extra setup steps for the consumer, it won't be just pulling the code and using
Edit 1: Update with build system
You didn't mention which build system are you using.
If you are using cmake, you can make use of ExternalProject_Add to download/build/install the dependent library.
See examples:
https://cmake.org/cmake/help/git-stage/module/ExternalProject.html#examples
If I understand you correctly you need that any client who obtains source code of your library would be able to also obtain corresponding source code of libcurl and tinyxml libraries.
Personally I would use cmake for that purpose as #brokenfoot has already suggested. But instead of ExternalProject_Add it seems that in your case FetchContent would be enough and less complicated: https://cmake.org/cmake/help/latest/module/FetchContent.html
Related
I'm trying to create a Flutter plugin which wraps some C++ code. That code has multiple dependencies, so steps need to be taken to provide those dependencies to the C++ build system (currently based on cmake, building for windows desktop), particularly where to find headers and libraries. There are a number of ways to do this with CMake, and we happen to be using Conan to fetch and provided dependencies, but in any case, I need a way to do a pre-build step and/or provide arguments to Flutter's execution of cmake to help it locate these dependencies.
I have ascertained that Flutter doesn't support a lot of (or any) customizability of the build. There are the build and build_runner packages, but I don't believe they will have knowledge of the build output directory for my platform nor provide a way to inject arguments to the cmake invocation.
How can I feed dependencies to the native build of the Flutter plugin? These dependencies may be static or dynamic libraries.
The only possible official way to interop with C/C++ code is ffi library. There is not much info about it online, but there is the official documentation.
Keep in mind that C-interop is parent platform dependent.
To properly generate binding with the needed native code, you have ffigen library. I think it will also help you with your dependencies issue.
Hope it helps
How can I add an Emscripten compilation target for my program using biicode. I would like to do a "bii cpp:configure" or a build with params, that would build my C/C++ source code using the downloaded Emscripten SDK (emsdk) or the installed Emscripten (from a package manager).
So you want to #include a emscripten header in your code and get the library? I would suggest to write a block that acts as a proxy and manage to download and install the prebuilt packages, as they seem quite good. This can be done in a several ways:
Write block with a hook, which is a script in python. You have for example the OpenCV one here: http://www.biicode.com/diego/opencv . That will install it to a biicode predefined location, which can be accessed in the CMakeLists.txt via a cmake variable ${BIICODE_ENV_DIR} . You can use that variable to define and link libraries.
You should add the headers you want to include in your block, so you can actually #include things, and have biicode retrieve things. Do not forget to add the hook to the biicode.conf [hooks] section
Write a block with a cmake script. In CMake it is also possible to retrieve and install files. In this case you can just write and INCLUDE(youruser/yourblock/yourcmakescript) in the CMakeLists.txt of the block that wants to "consume" and use emscripten. That file will be handle exactly the same as C/C++ files, they will appear initially as unresolved in "bii deps" and can be resolved with "bii find" or adding the block to the [requirements] section.
I initially recommend this as the library seems a bit complex to build, it does not have standard CMakeLists.txt, but custom configures.
EDIT: Now I see with your comments that this is not what you actually want, but to use a custom compilation (cross compilation to js) toolchain. This can be actually done using custom toolchains: http://docs.biicode.com/c++/building.html#using-a-custom-tool-chain
This could require some mastery of both CMake and the emscripten toolchain. The integration of this toolchains is a little bit tricky now, it is being revamped and will be released in a few weeks.
Note that the rest of the answer is still valid, you can easily write a block with a hook that manages to install the emscripten tool from binaries.
I want build latest harfbuzz-ng library on Windows 7. But in build system by default I must go through long quest to gain: ragel, pkg-config, gtkdocize and other stuff. Even in the end if I get all what need for build system I get errors (sorry cannot say which concrete errors), last time I tried to build this library 2 month ago). Maybe on Linux system it is easy to get and build all this stuff but on Windows always something doesn't want to be compiled. Or the problem is that I don't find instructions which guide me on Windows, only Linux.
What I want to get is simple instructions how build only harfbuzz-ng with freetype dependency (and maybe add ICU) by MinGW compiler on Windows.
Thanks you very much.
For anyone reading this, have a look at harfbuzz.cc in the project which makes you able to use harfbuzz without any build system, just include it in one of your sources, no build system is required, define HB_NO_MT or even HB_TINY (which brings a minimal harfbuzz) if you don't use harfbuzz in multithread mode.
I don't know i this is the answer you are looking for. I am trying to work with Harfbuzz as well and did this through several attempts which did not work out for various reasons.
One (old) example you could use as a starter is: HarfBuzz static lib. The .lib-file generated works with UCDN and just needs this file plus a source for the Freetype-functions to provide the necessary FT_Face-parameter (i did this by compiling another .lib via the freetype-sourcecode (freetype.org/download.html).
But I am unsure if this will work out for the MinGW-compiler (you don't use VC++ as IDE do you??).
You may find of interest the MSYS2 build system. It is essentially a linux-style packaging system built on top of Windows(TM). You can download and install binary packages with simple commands (including automatic dependency solving). If you want to download a source package you can do that as well. http://msys2.github.io
I have written and tested a library in C++. The code even works in my Android application if I add the source files directly. While I do have experience compiling static and dynamic libraries for common operating systems, I have zero experience compiling for a mobile system like this. I've done some research, and I'm still a bit lost as to exactly how to approach this. For example, I am unsure of whether to build a makefile for use with ndk-build or to just invoke one of the Android's compilers directly.
I did see this question, but it does not quite match my situation. I just want to run build and have it spit out libfoo.a (I'd like to produce libfoo.so as well, but libfoo.a is of greater interest to me right now.) The example in that question's winning answer implied that it would build the library as one step/module for building the final application. I tried doing it that way just to see, but I had no luck.
Can anyone please guide me in this endeavor?
CLARIFICATION -- I do not want to build the library and immediately pipe it into an application. I want a .a or .so file that I can link against in multiple future Android applications.
Create a dummy java file with empty code and make sure there is a android_main function in your C++ code. Build using ndk-build. the resulting apk will make your library an application.
See the samples from the android-ndk-r5/samples directory, see the sample native-bitmap to get some idea.
If I understand it correctly that a shared library is not acceptable and you want to be static (but why is that so important?), probably the easiest way to do so is to simply supply source code that can be added to a project.
Ultimately there is nothing special about the ndk build system other than it knowing the right commands to issue to build the necessary files for the assortment of curent android architectures. If you really want to do something different, you can log the operation of the android build system in creating a shared library, and then write your own Makefile that performs the analogous steps to create a static library. HOWEVER, you will have to update your Makefile any time the underlying assumptions or target collections change in a new android version.
I'm in the middle of setting up an build environment for a c++ game project. Our main requirement is the ability to build not just our game code, but also its dependencies (Ogre3D, Cegui, boost, etc.). Furthermore we would like to be able build on Linux as well as on Windows as our development team consists of members using different operating systems.
Ogre3D uses CMake as its build tool. This is why we based our project on CMake too so far. We can compile perfectly fine once all dependencies are set up manually on each team members system as CMake is able to find the libraries.
The Question is if there is an feasible way to get the dependencies set up automatically. As a Java developer I know of Maven, but what tools do exist in the world of c++?
Update: Thanks for the nice answers and links. Over the next few days I will be trying out some of the tools to see what meets our requirements, starting with CMake. I've indeed had my share with autotools so far and as much as I like the documentation (the autobook is a very good read), I fear autotools are not meant to be used on Windows natively.
Some of you suggested to let some IDE handle the dependency management. We consist of individuals using all possible technologies to code from pure Vim to fully blown Eclipse CDT or Visual Studio. This is where CMake allows use some flexibility with its ability to generate native project files.
In the latest CMake 2.8 version there is the new ExternalProject module.
This allows to download/checkout code, configure and build it as part of your main build tree.
It should also allow to set dependencies.
At my work (medical image processing group) we use CMake to build all our own libraries and applications. We have an in-house tool to track all the dependencies between projects (defined in a XML database). Most of the third party libraries (like Boost, Qt, VTK, ITK etc..) are build once for each system we support (MSWin32, MSWin64, Linux32 etc..) and are commited as zip-files in the version control system. CMake will then extract and configure the correct zip file depending on which system the developer is working on.
I have been using GNU Autotools (Autoconf, Automake, Libtool) for the past couple of months in several projects that I have been involved in and I think it works beautifully. Truth be told it does take a little bit to get used to the syntax, but I have used it successfully on a project that requires the distribution of python scripts, C libraries, and a C++ application. I'll give you some links that helped me out when I first asked a similar question on here.
The GNU Autotools Page provides the best documentation on the system as a whole but it is quite verbose.
Wikipedia has a page which explains how everything works. Autoconf configures the project based upon the platform that you are about to compile on, Automake builds the Makefiles for your project, and Libtool handles libraries.
A Makefile.am example and a configure.ac example should help you get started.
Some more links:
http://www.lrde.epita.fr/~adl/autotools.html
http://www.developingprogrammers.com/index.php/2006/01/05/autotools-tutorial/
http://sources.redhat.com/autobook/
One thing that I am not certain on is any type of Windows wrapper for GNU Autotools. I know you are able to use it inside of Cygwin, but as for actually distributing files and dependencies on Windows platforms you are probably better off using a Windows MSI installer (or something that can package your project inside of Visual Studio).
If you want to distribute dependencies you can set them up under a different subdirectory, for example, libzip, with a specific Makefile.am entry which will build that library. When you perform a make install the library will be installed to the lib folder that the configure script determined it should use.
Good luck!
There are several interesting make replacements that automatically track implicit dependencies (from header files), are cross-platform and can cope with generated files (e.g. shader definitions). Two examples I used to work with are SCons and Jam/BJam.
I don't know of a cross-platform way of getting *make to automatically track dependencies.
The best you can do is use some script that scans source files (or has C++ compiler do that) and finds #includes (conditional compilation makes this tricky) and generates part of makefile.
But you'd need to call this script whenever something might have changed.
The Question is if there is an feasible way to get the dependencies set up automatically.
What do you mean set up?
As you said, CMake will compile everything once the dependencies are on the machines. Are you just looking for a way to package up the dependency source? Once all the source is there, CMake and a build tool (gcc, nmake, MSVS, etc.) is all you need.
Edit: Side note, CMake has the file command which can be used to download files if they are needed: file(DOWNLOAD url file [TIMEOUT timeout] [STATUS status] [LOG log])
Edit 2: CPack is another tool by the CMake guys that can be used to package up files and such for distribution on various platforms. It can create NSIS for Windows and .deb or .tgz files for *nix.
At my place of work (we build embedded systems for power protection) we used CMake to solve the problem. Our setup allows cmake to be run from various locations.
/
CMakeLists.txt "install precompiled dependencies and build project"
project/
CMakeLists.txt "build the project managing dependencies of subsystems"
subsystem1/
CMakeLists.txt "build subsystem 1 assume dependecies are already met"
subsystem2/
CMakeLists.txt "build subsystem 2 assume dependecies are already met"
The trick is to make sure that each CMakeLists.txt file can be called in isolation but that the top level file can still build everything correctly. Technically we don't need the sub CMakeLists.txt files but it makes the developers happy. It would be an absolute pain if we all had to edit one monolithic build file at the root of the project.
I did not set up the system (I helped but it is not my baby). The author said that the boost cmake build system had some really good stuff in it, that help him get the whole thing building smoothly.
On many *nix systems, some kind of package manager or build system is used for this. The most common one for source stuff is GNU Autotools, which I've heard is a source of extreme grief. However, with a few scripts and an online depository for your deps you can set up something similar like so:
In your project Makefile, create a target (optionally with subtargets) that covers your dependencies.
Within the target for each dependency, first check to see if the dep source is in the project (on *nix you can use touch for this, but you could be more thorough)
If the dep is not there, you can use curl, etc to download the dep
In all cases, have the dep targets make a recursive make call (make; make install; make clean; etc) to the Makefile (or other configure script/build file) of the dependency. If the dep is already built and installed, make will return fairly promptly.
There are going to be lots of corner cases that will cause this to break though, depending on the installers for each dep (perhaps the installer is interactive?), but this approach should cover the general idea.
Right now I'm working on a tool able to automatically install all dependencies of a C/C++ app with exact version requirement :
compiler
libs
tools (cmake, autotools)
Right now it works, for my app. (Installing UnitTest++, Boost, Wt, sqlite, cmake all in correct order)
The tool, named «C++ Version Manager» (inspired by the excellent ruby version manager), is coded in bash and hosted on github : https://github.com/Offirmo/cvm
Any advices and suggestions are welcomed.