Merge pull request #92 from arthurafarias/add-cmake-interface-library

Added interface target to CMakeLists.txt
This commit is contained in:
Tristan Penman 2020-07-10 11:06:56 +10:00 committed by GitHub
commit 105e345a73
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 0 deletions

View File

@ -10,6 +10,16 @@ option(valijson_EXCLUDE_BOOST "Exclude Boost when building test suite." FALSE)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
add_library(valijson INTERFACE)
# create alias, so that user could always write target_link_libraries(... ValiJSON::valijson)
# despite of valijson target is imported or not
add_library(ValiJSON::valijson ALIAS valijson)
include(GNUInstallDirs)
target_include_directories(valijson INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
if(valijson_INSTALL_HEADERS) if(valijson_INSTALL_HEADERS)
install(DIRECTORY include/ DESTINATION include) install(DIRECTORY include/ DESTINATION include)
endif() endif()

View File

@ -125,6 +125,32 @@ The examples and test suite can be built using cmake:
# Run test suite (from build directory) # Run test suite (from build directory)
./test_suite ./test_suite
#### How to add this library to your cmake target ####
Download this repository into your project
```bash
git clone https://github.com/tristanpenman/valijson <project-path>/third-party/valijson
```
If your project is a git repository
```bash
cd <project-path>
git submodule add https://github.com/tristanpenman/valijson third-party/valijson
```
Before the target add the module subdirectory in your CMakeLists.txt
```cmake
set(valijson_BUILD_TESTS OFF)
add_subdirectory(third-party/valijson)
add_executable(your-executable ...)
target_link_libraries(your-executable ValiJSON::valijson)
```
### Xcode ### ### 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. 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.