

Installing: cmake-install-example/build/linux/././include/testB.hpp Installing: cmake-install-example/build/linux/././include/testA.hpp Installing: cmake-install-example/build/linux/././lib/libTESTLIB.a Building C object CMakeFiles/TESTLIB.dir/src/dummy.c.o Building CXX object src/A/CMakeFiles/LIBA.dir/ Building CXX object src/B/CMakeFiles/LIBB.dir/ The C compiler identification is GNU 4.8.2 I made an example which I thought solved the problem (my way :)): Install(CODE "install_api_headers(workmodel_API_HDRS Trying the easy fix with a 'install(CODE. :/) is executed during CMake runtime and not during 'make install'. Install_api_headers(my_api_headers "MyProject/include")īut that obviously (well, I remembered when I ran it.
#Cmake copy file install
(Compare, for example, How can I install a hierarchy of files using cmake?) )' form with a 'PATTERN', but I don't think I can use that as that All the other suggestions I have found so far involce the 'install(DIRECTORY. )' CMake command as that strips away the relative paths. I have a simple list of my API headers:īut I cannot simply use the 'install(FILES. Set( CMAKE_INSTALL_PREFIX "path_to_my_project") Installing the library is easy with CMake: However, I want to maintain the relative paths of those headers! make install) I would like to move my build libmyproject.a to MyProject/lib and some headers, say A/a1.h and B/b1.h to the MyProject/include folder. In MyProject/src/CMakeLists.txt (which is the main CMakeLists file), I setup my project and compile everything into a library.ĭuring the install step (i.e. Here is the file structure that I have: MyProject If you want to see a complete example, check out my pico-dht11-lib project on Github.I would like to install a certain set of headers (which is not identical to all headers in a directory) to an include directory during make install of my project. In the remainder of this article, I will show a concise example for each type. During building, you will have one and only one C file with a main() method, and the result will be named file.out

During the compilation process, you will product library files, which are typically named lib.a. library config: Directories in which you just build a library, you will put a config file that includes the add_library directive.This file needs to set essential config options, and it will list all additional directories that will be included when you execute CMake. main config: The top-level directory includes the root CMake file.What appears confusing at first, but becomes clearer with experience, is that you need to place a file called CMakeLists.txt in your project root directory and in all subdirectories that contain source code.ĭepending on where you define them, these files have different roles, which I separate as follows: This is also done with the make command, and the Makefiles will include all the defined build options of your CMake configuration.
#Cmake copy file code
Building: You will also build executable files that link to your library code and/or external libraries.

