Import targets from external CMakeLists.txt file, having already built the external source - cmake

I am trying to integrate the Refinitiv Real-Time SDK into my own application.
I have downloaded the source code and built the libraries.
Typically you would then expect there to be an INSTALL target, which would install the libraries and headers into some location, and then, if we're lucky, a find_package module which we can later use to import the library targets into our own project.
Unfortunately, neither of these are provided.
How then, to import the libraries and their header files into my project?
ExternalProject_Add
I do not want to use the standard ExternalProject_Add to download and build the source code every time I reconfigure my project. (In particular because our CI server will have to do this for every single build.) Rather I want to build it once (and make it part of the CI server's docker image), and then link against the libraries / include the header files directly from where I've copied the source.
add_library INTERFACE
I know that I can create a new INTERFACE library target
find_library(LIB_EMA ema ${REFINITIV_BINARY_DIR})
find_library(LIB_ETA eta ${REFINITIV_BINARY_DIR})
# etc.. for all the refinitiv libraries
add_library(refinitiv INTERFACE)
target_link_libraries(refinitiv INTERFACE
${LIB_EMA}
${LIB_ETA}
# etc...
)
target_include_directories(refinitiv INTERFACE
${REFINITIV_SOURCE_DIR/Ema/Include
${REFINITIV_SOURCE_DIR/Eta/Include
# etc...
)
This is, however, tedious and prone to breaking whenever Refinitiv releases a new SDK version and decides to change a path or link dependency etc
Question:
What I would to do is use their CMakeLists.txt file, but only to access the already-built targets, not to build them as part of my build.
Is this possible?

Related

How to not include source files in my conan package?

We are trying to manage our own C++ static libraries using JFrog Artifactory CE. In the near future, these libraries could be accessed by third parties so we don't want to put any .cpp files in the package, we just want to put .h files and compiled libraries in our conan packages hosted on Artifcatory.
I read through the conan official guide https://docs.conan.io/en/1.3/creating_packages.html
https://docs.conan.io/en/1.3/creating_packages/package_repo.html
but I cannot find any description of how to exclude source files from the recipe.
If I don't specify exports_sources or exports in my conanfile.py I cannot build static libraries but if I specify those parameters, conan puts source files under export/conan_sources.tgz automatically when I execute conan create.
How can I create a conan package without including source files in the recipe?
There are 2 different ways to do this, instead of using the exports_... functionality:
Use the source() method, to retrieve whatever tarball, git-clone, or what is necessary to fetch the sources. This might require some authentication, which can be provided through env-vars. It is typical to use the conandata.yml to put the data there, and let the source() method to read the self.conan_data. Check this docs. The recipes in the conan-center-index repo, that serves to build ConanCenter, uses this approach.
Use the scm component if the recipe lives in the same repo as the source code, to capture the URL and commit of the sources, but without capturing the sources. If the scm code is behind auth, only authorized devs will be able to see the sources or build from sources. Check this section of the docs about SCM
In both cases, if the access to the source is restricted, non-privileged users that try to build packages from sources with --build will fail.

With Kotlin Native, building a windows exe, can I bundle libraries ( dlls ) into the exe?

Let's say I want to build a simple windows exe that does HTTP requests with curl.
( See example: https://github.com/JetBrains/kotlin-native/tree/master/samples/curl ).
The example above works, but in order for the exe to run, it needs to find libcurl-4.dll, either in the local dir, or e.g. in the installation dir ( e.g. C:\msys64\mingw64\lib ).
I would like to ship just the exe file, without having to provide the dll files separately. Is it possible to build the exe file with all the things it uses from the library (and transitive dependencies...) bundled into the exe file?
(This question is about if I can do this with a Kotlin 1.3.61 Native project, and how.)
I'm studying Kotlin too and it took many hours until I realize how to handle def file, includes and static library.
I made an example of how to use static library (curl with gzip and SSL support compiled with mingw) on kotlin-native. This way you dont need to dll files to be supplied with your app
https://github.com/carlosrafp/Libcurl-Kotlin-Native-standalone
On libcurl.def file you can see:
headers = curl/curl.h // path to curl header
libraryPaths = src/nativeInterop/cinterop // path to your static library
staticLibraries = libcurl.a // the static library
linkerOpts.mingw = -lws2_32 -lwldap32 // linking dependences
I based on the nice post of jonnyzzz:
https://jonnyzzz.com/blog/2018/10/29/kn-libcurl-windows/
You need to build the static libraries using mingw (libcurl, gzip) and msys2/mingw(openssl) to use with kotlin-native compiler
You can definitely do this for a static library(see this), but not for the .dll. About the shared library bundling, I would just recommend you to see this question. It's about the same but a bit generalized.

Install files using symbolic links with CMAKE

I have converted my project to use cmake. During development I'd like to be able to install the product not the normal way, but let (notably) the installed data files be symbolic links to the source tree.
The project is SWI-Prolog which provides functionality to directly navigate and edit source files. If I use this to extend and fix the system libraries however I'm editing the installed copy that I then need to copy back to the sources before I can commit.
I know I can override functions in cmake, but in this case we are dealing with cmake code that is generated.

cmake third party step dependency

We are using a vendor code as third party project in our source code. This party project is hosted on different server.
Our application needs to include header file from third party project. So far, application cmake has dependecy on external project, untill external project install is done, application will not start building up.
Logically Application can start building once third party project is downloaded and header files are available.
To Achieve the same, I can have a step which depends on configure/download
ExternalProject_Add_Step(CopyHeaderFileStep DEPENDS configure)
However since it is just a step, not target, I am not able to specify dependecy of CopyHeaderFileStep in my application CMake.
I looked upon cmake third party documentation throughtly but no help. Is there any way out here ?
However since it is just a step, not target, I am not able to specify dependecy of CopyHeaderFileStep in my application CMake.
Exactly for that purpose there is a function ExternalProject_Add_StepTargets, which creates normal CMake targets for the steps of the ExternalProject. From documentation:
ExternalProject_Add_StepTargets() function generates targets for the steps listed. The name of each created target will be of the form <name>-<step>.
Example:
# Create targets for steps
ExternalProject_Add_StepTargets(extProject # External project name
CopyHeaderFileStep # List of steps, for which targets will be created
)
# Depend on these targets in outer code
add_dependencies(myApp extProject-CopyHeaderFileStep)

How to load cmake script with more than one project with Qt Creator

I have a CMake project, and until now, I was using Visual C++ for developing.
Using CMake-gui to generate a solution for VC++, it generates more than one project in the same solution.
But when the script is loaded in qt-creator, only one project is defined, with all the code and folder tree inside, so I can not compile it (or I don't know how to do it).
How can I load the cmake file to load all the projects?
More info:
The first CMakeList.txt has some common configuration. Then, with 'add_subdirectory' function, I add a project to make a library, and another project to make a sample application to use this library.
You should add multiple projects to the root cmake file with help of "add_subdirectory()". Then in Qt Creator you should open the root cmake file. After that you could choose which project to run in the select a kit for running (3) or debugging (4) application pane (check the link).
It sad that you can't (or I don't know how) build only one project. You have to build all projects are added to the root cmake file and then choose which one of them you want to run.
I use Qt Creator 4.0 .
Here is the offical doc http://qt-project.org/doc/qtcreator-2.8/creator-project-cmake.html
My project have a similar structure, just open the top-most CMakeLists.txt file of the project, and qtcreator will import your project.