- #CMAKE INSTALL DIFFERENT DIRECTORY INSTALL#
- #CMAKE INSTALL DIFFERENT DIRECTORY CODE#
- #CMAKE INSTALL DIFFERENT DIRECTORY ZIP#
#CMAKE INSTALL DIFFERENT DIRECTORY INSTALL#
But when you install the library, then there is SomeLibrary folder inside include in the installation folder, so in that case you need to add SomeLibrary/ to #include statement. Why is that, why is it different from the way in was included in external project? Well, it is because that is how this header is placed in the library’s source include folder - there is no SomeLibrary folder nested there.
#CMAKE INSTALL DIFFERENT DIRECTORY CODE#
While the code here is the same as the one from external project, there is one notable difference - some.h is not prepended with SomeLibrary/ in the #include statement. Std ::cout << "base application message" << std ::endl #include #include int main( int argc, char *argv) Now let’s see how your users or yourself can link to the library.
#CMAKE INSTALL DIFFERENT DIRECTORY ZIP#
So there you have it! The library has been successfully built and nicely installed, so now you can just zip the install folder contents and distribute it to your users. Installing: /Users/YOURNAME/code/cpp/someLibrary/install/cmake/SomeLibrar圜onfig-release.cmake Up-to-date: /Users/YOURNAME/code/cpp/someLibrary/install/include/SomeLibrary/some.h Installing: /Users/YOURNAME/code/cpp/someLibrary/install/cmake/SomeLibrar圜onfig-debug.cmake
![cmake install different directory cmake install different directory](https://unixcop.com/wp-content/uploads/2021/07/CMake.png)
![cmake install different directory cmake install different directory](https://aws1.discourse-cdn.com/standard20/uploads/bioexcel1/optimized/1X/8a8e0c1ebe50b4145110482b5d02bc201e481a38_2_690x367.png)
Installing: /Users/YOURNAME/code/cpp/someLibrary/install/lib/libSomeLibraryd.a Linking CXX static library libSomeLibraryd.a This is because we ran configuration without specifying the build type - better to explicitly set it then, both Debug and Release: Note that SomeLibrar圜onfig-noconfig.cmake has this weird noconfig suffix. Installing: /Users/YOURNAME/code/cpp/someLibrary/install/cmake/SomeLibrar圜onfig-noconfig.cmake Installing: /Users/YOURNAME/code/cpp/someLibrary/install/cmake/SomeLibrar圜onfig.cmake Installing: /Users/YOURNAME/code/cpp/someLibrary/install/include/SomeLibrary/some.h Installing: /Users/YOURNAME/code/cpp/someLibrary/install/lib/libSomeLibrary.a Linking CXX static library libSomeLibrary.a Building CXX object CMakeFiles/SomeLibrary.dir/src/ Scanning dependencies of target SomeLibrary Build files have been written to: /Users/YOURNAME/code/cpp/someLibrary/build Will set it to /Users/YOURNAME/code/cpp/someLibrary/install Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ - skipped Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc - skipped The CXX compiler identification is AppleClang 12.0032 The C compiler identification is AppleClang 12.0032 Having it, if you now try to find your package in external project ( cmake-library-example/external-project/CMakeLists.txt) like this: The write_basic_package_version_file() function from above will create SomeLibrar圜onfigVersion.cmake file in the install folder. Knowing that, here’s how you can check if you are in the top-level project or not: This variable persists across all the nested projects, and so calling project command from nested projects will not change CMAKE_PROJECT_NAME, but will set another variable called PROJECT_NAME. It stores the top-level project name that you set with project command. In CMake projects there is a variable called CMAKE_PROJECT_NAME. So let’s gradually create a CMakeLists.txt for the library project.
![cmake install different directory cmake install different directory](https://forum.huawei.com/enterprise/en/data/attachment/forum/202008/26/133907eii3q02szrrh5c0c.jpg)
![cmake install different directory cmake install different directory](https://discuss.px4.io/uploads/default/original/2X/1/110f99182cf99dc9b44d581269859c2e21f11104.jpeg)
Making a library with CMake is not that different from making an application - instead of add_executable you call add_library. #include const std ::string someString = "some string"