- #Cmake install multiple destinations how to#
- #Cmake install multiple destinations archive#
- #Cmake install multiple destinations windows#
However, I get the following error: CMake Error: install(EXPORT "Halide_Targets".
#Cmake install multiple destinations archive#
So, knowing that each of RUNTIME, LIBRARY, and ARCHIVE can appear only once in a call to install(), I tried writing the code below, which involves two nearly identical calls to install(). The client can also leave out the REQUIRED part if it is, well, not required.Then a variable needs to be queried before safely referring to the targets.I want to make a multi configuration package using cpack -C and the Visual Studio multi-generator. We only need to install the following in order to use the library:the header files, the tool executable and the built library.This can be done in a very straightforward way with the install() command.It will simply copy the files into the $ is installed) and all exported targets made available allowing a simple target_link_libraries(client_target PUBLIC my_library).This will link to the library version of matching build type. The other CMakeLists.txt are simpler and I will not go over them here.Ĭlient code can now call add_subdirectory() of the library folder and call target_link_libraries(my_target PUBLIC my_library).This will also set up the include path, allowing #include directly.īut we want to install it and support find_package(). It also generates the config_impl.hpp that can be included inside the config.hpp in the current binary dir and defines the library with the given files.Its PUBLIC include directory is both the included/ subfolder and the current binary dir.The latter is needed to access the generated config_impl.hpp. Note that the header path has to be given for the headers, since they are in a different subdirectory.The source files can be named directly. This prevents users changing the value in the CMakeCache.txt.įirst we define a list of all headers and source files in variables.This will be useful later on. Note that the library version is set via FORCE.
It defines a few options that can be used via #cmakedefine01 or similar in the. The root CMakeLists.txt can look as follows: This allows a seperation of CMake’s config files and other, unrelated configuration macros etc. The configurations will be set in the file which will be preprocessed to config_impl.hpp and included by config.hpp. The root CMakeLists.txt defines configuration options and adds the subdirectories. The library, the examples and the tool each has their own CMakeLists.txt defining the target and related code in their subdirectory. I was looking for a build-time command/script that would copy dependencies to the build output directory so when I run a target the necessary dependency is there along with the executable. So we have a library consisting of various header and source files.It also comes with some examples, a tool and unit tests. Looking at that it looks to be used along with install which is then used with a separate install comment to install it to the system. The setupįor the scope of the tutorial, let’s say we have a library that has the following CMake structure: Throughout this post, I’ll be assuming a 3.x CMake version and an already existing CMake project.
#Cmake install multiple destinations how to#
Config-file packages are provided by upstream vendors as part of development packages, that is, they belong with the header files and any other files provided to assist downstreams in using the.īecause I’ve spent hours of trial and error to come up with it, I’ll document it here.In this post, I will show you how to install your library so that it can be used easily by other projects.In particular, the system will be able to handle multiple installed versions and multiple configurations.
The most simple way for a CMake user to tell cmake(1) to search in a non-standard prefix for a package is to set the CMAKEPREFIXPATH cache variable. This file may contain the entire build specification or use the addsubdirectory command to add subdirectories to the build. When CMake processes a project source tree, the entry point is a source file called CMakeLists.txt in the top-level source directory. It only has a simple main.cpp.Īs of version 0.5 my memory library now provides support for system-wide installation and CMake’s find_package(). We’ll start with a very small project: A typical hello world example.
#Cmake install multiple destinations windows#
I use MSYS2/MINGW64 on Windows and let CMake generate Makefiles, but the principle is the same for other environments and generators. In this post, I’ll lay out the very first step to approach a CMake-based project. The source code of the sample project used below is available on GitHub. Step by step, we will learn the basics of CMake as a build system, along with the CLion settings and actions for CMake projects. This tutorial will guide you through the process of creating and developing a simple CMake project.