diff --git a/CMakeLists.txt b/CMakeLists.txt index 65bfad1..8ac535d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,7 +34,16 @@ target_include_directories(valijson INTERFACE $ $) -install(DIRECTORY include/ DESTINATION include) +install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) + +install(TARGETS valijson + EXPORT valijsonConfig + DESTINATION ${CMAKE_INSTALL_LIBDIR} +) + +install(EXPORT valijsonConfig + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/valijson" +) if(NOT valijson_BUILD_TESTS AND NOT valijson_BUILD_EXAMPLES) return() diff --git a/README.md b/README.md index 0d7e5d3..49b23a8 100644 --- a/README.md +++ b/README.md @@ -147,7 +147,11 @@ The examples and test suite can be built using cmake: # Run test suite (from build directory) ./test_suite ``` -#### How to add this library to your cmake target #### +## How to add this library to your cmake target ## + +Valijson can be integrated either as git submodule or with find_package(). + +### Valijson as git submodule ### Download this repository into your project @@ -172,7 +176,24 @@ add_executable(your-executable ...) target_link_libraries(your-executable ValiJSON::valijson) ``` +### Install Valijson and import it ### +It is possible to install headers by running cmake's install command from the build tree. Once Valijson is installed, use it from other CMake projects using `find_package(Valijson)` in your CMakeLists.txt. +```bash + # Install Valijson + git clone --depth=1 git@github.com:tristanpenman/valijson.git + cd valijson + mkdir build + cd build + cmake .. + cmake --install . +``` +```cmake + # Import installed valijson and link it to your executable + find_package(valijson REQUIRED) + add_executable(executable main.cpp) + target_link_libraries(executable valijson) +``` ### Xcode ### An Xcode project has also been provided, in the 'xcode' directory. Note that in order to run the test suite, you may need to configure the working directory for the 'test\_suite' scheme. It is recommended that you use the 'xcode' directory as the working directory.