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:
#Cmake install files install#
The write_basic_package_version_file() function from above will create SomeLibrar圜onfigVersion.cmake file in the install folder.
![cmake install files cmake install files](https://image.slidesharecdn.com/anintroductiontocmake-190214202158/95/an-introduction-to-cmake-24-638.jpg)
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 files cmake install files](https://mirtk.github.io/_images/CMakeGUIDefaultConfig.png)
![cmake install files cmake install files](https://blog.eldernode.com/wp-content/uploads/2021/01/ing.png)
Making a library with CMake is not that different from making an application - instead of add_executable you call add_library. In this case, remove the 'add_subdirectory(example_internal)' too.#include const std ::string someString = "some string" 'example_internal/' folder can be removed, it is the 'bar'Įxample. See cmake/SetEnv.cmake file for implementation details. If it is not set explicitally, project name in lowercase will be used. Set variables: LIBRARY_NAME and LIBRARY_FOLDER. Git clone project name in the top-level CMakeLists.txt.Īdd.
#Cmake install files how to#
How to create a library from this example?Ĭopy files in a new folder, or clone with git: # Propagate usage requirements from Foo linked library
#Cmake install files full#
For multi-config generator, CMAKE_CONFIGURATION_TYPES is setĪlways full RPATH (for shared libraries).ĬMake Registry: export package to CMake registry such that it can be easily found by CMake even if it has not been installed to a standard directory. Static library as default ( BUILD_SHARED_LIBS=OFF).Ĭmake-gui shows possible options for CMAKE_BUILD_TYPE (Release, Debug,Įtc.). See foo/foo.cpp#L7-L11.ĬMAKE_DEBUG_POSTFIX = 'd' (allowing Debug and Release to not collide). You only need to change the project name, and add the files that need toĪutogenetared library version file: #include įOO_DEBUG added on Debug. The main advantage of this example is that it is auto-generated. Update: now using modern cmake (version >= 3.9), since commit 46f0b93. CMake library example that can be found using find_package().