diff --git a/CMakeLists.txt b/CMakeLists.txt index c9dc427..456c99b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,6 +12,11 @@ OPTION( ATOMIC_QUEUE_BUILD_EXAMPLES OFF ) +OPTION( ATOMIC_QUEUE_ENABLE_INSTALL + "If the install target should be enabled." + OFF +) + if ( PROJECT_IS_TOP_LEVEL ) set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD_REQUIRED) @@ -26,5 +31,3 @@ endif() if ( ATOMIC_QUEUE_BUILD_TESTS OR ATOMIC_QUEUE_BUILD_EXAMPLES) add_subdirectory( src ) endif() - -add_library(max0x7ba::atomic_queue ALIAS atomic_queue) \ No newline at end of file diff --git a/README.md b/README.md index b0a3a30..4d36964 100644 --- a/README.md +++ b/README.md @@ -70,11 +70,21 @@ git clone https://github.com/max0x7ba/atomic_queue.git ``` 2. Add `atomic_queue/include` directory (use full path) to the include paths of your build system. 3. `#include ` in your C++ source. +If you use CMake, these can be simplified as follows: +```cmake +add_subdirectory(atomic_queue) +target_link_libraries(main PRIVATE atomic_queue::atomic_queue) +``` ## Install using vcpkg ``` vcpkg install atomic-queue ``` +It provides CMake targets: +```cmake +find_package(atomic_queue CONFIG REQUIRED) +target_link_libraries(main PRIVATE atomic_queue::atomic_queue) +``` ## Install using conan Follow the official tutorial on [how to consume conan packages](https://docs.conan.io/2/tutorial/consuming_packages.html). diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt index 7ca376d..4d44523 100644 --- a/include/CMakeLists.txt +++ b/include/CMakeLists.txt @@ -1,17 +1,25 @@ CMAKE_MINIMUM_REQUIRED( VERSION 3.25 ) -add_library( - atomic_queue - INTERFACE - ${CMAKE_CURRENT_SOURCE_DIR}/atomic_queue/atomic_queue.h - ${CMAKE_CURRENT_SOURCE_DIR}/atomic_queue/atomic_queue_mutex.h - ${CMAKE_CURRENT_SOURCE_DIR}/atomic_queue/barrier.h - ${CMAKE_CURRENT_SOURCE_DIR}/atomic_queue/defs.h - ${CMAKE_CURRENT_SOURCE_DIR}/atomic_queue/spinlock.h +include(GNUInstallDirs) + +add_library(atomic_queue INTERFACE) +target_include_directories(atomic_queue INTERFACE + "$" + "$" ) -target_include_directories( - atomic_queue - INTERFACE - ${CMAKE_CURRENT_SOURCE_DIR} -) \ No newline at end of file +add_library(atomic_queue::atomic_queue ALIAS atomic_queue) + +if ( ATOMIC_QUEUE_ENABLE_INSTALL ) + install(TARGETS atomic_queue EXPORT atomic_queue) + install( + DIRECTORY "${CMAKE_CURRENT_LIST_DIR}/atomic_queue" + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" + ) + install( + EXPORT atomic_queue + FILE atomic_queue-config.cmake + DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/atomic_queue" + NAMESPACE atomic_queue:: + ) +endif ()