Skip to content

Commit 627fc6f

Browse files
authored
Support cmake install (#97)
CMake install added.
1 parent bce850f commit 627fc6f

3 files changed

Lines changed: 36 additions & 15 deletions

File tree

CMakeLists.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ OPTION( ATOMIC_QUEUE_BUILD_EXAMPLES
1212
OFF
1313
)
1414

15+
OPTION( ATOMIC_QUEUE_ENABLE_INSTALL
16+
"If the install target should be enabled."
17+
OFF
18+
)
19+
1520
if ( PROJECT_IS_TOP_LEVEL )
1621
set(CMAKE_CXX_STANDARD 14)
1722
set(CMAKE_CXX_STANDARD_REQUIRED)
@@ -26,5 +31,3 @@ endif()
2631
if ( ATOMIC_QUEUE_BUILD_TESTS OR ATOMIC_QUEUE_BUILD_EXAMPLES)
2732
add_subdirectory( src )
2833
endif()
29-
30-
add_library(max0x7ba::atomic_queue ALIAS atomic_queue)

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,21 @@ git clone https://github.com/max0x7ba/atomic_queue.git
7070
```
7171
2. Add `atomic_queue/include` directory (use full path) to the include paths of your build system.
7272
3. `#include <atomic_queue/atomic_queue.h>` in your C++ source.
73+
If you use CMake, these can be simplified as follows:
74+
```cmake
75+
add_subdirectory(atomic_queue)
76+
target_link_libraries(main PRIVATE atomic_queue::atomic_queue)
77+
```
7378

7479
## Install using vcpkg
7580
```
7681
vcpkg install atomic-queue
7782
```
83+
It provides CMake targets:
84+
```cmake
85+
find_package(atomic_queue CONFIG REQUIRED)
86+
target_link_libraries(main PRIVATE atomic_queue::atomic_queue)
87+
```
7888

7989
## Install using conan
8090
Follow the official tutorial on [how to consume conan packages](https://docs.conan.io/2/tutorial/consuming_packages.html).

include/CMakeLists.txt

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
11
CMAKE_MINIMUM_REQUIRED( VERSION 3.25 )
22

3-
add_library(
4-
atomic_queue
5-
INTERFACE
6-
${CMAKE_CURRENT_SOURCE_DIR}/atomic_queue/atomic_queue.h
7-
${CMAKE_CURRENT_SOURCE_DIR}/atomic_queue/atomic_queue_mutex.h
8-
${CMAKE_CURRENT_SOURCE_DIR}/atomic_queue/barrier.h
9-
${CMAKE_CURRENT_SOURCE_DIR}/atomic_queue/defs.h
10-
${CMAKE_CURRENT_SOURCE_DIR}/atomic_queue/spinlock.h
3+
include(GNUInstallDirs)
4+
5+
add_library(atomic_queue INTERFACE)
6+
target_include_directories(atomic_queue INTERFACE
7+
"$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}>"
8+
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
119
)
1210

13-
target_include_directories(
14-
atomic_queue
15-
INTERFACE
16-
${CMAKE_CURRENT_SOURCE_DIR}
17-
)
11+
add_library(atomic_queue::atomic_queue ALIAS atomic_queue)
12+
13+
if ( ATOMIC_QUEUE_ENABLE_INSTALL )
14+
install(TARGETS atomic_queue EXPORT atomic_queue)
15+
install(
16+
DIRECTORY "${CMAKE_CURRENT_LIST_DIR}/atomic_queue"
17+
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
18+
)
19+
install(
20+
EXPORT atomic_queue
21+
FILE atomic_queue-config.cmake
22+
DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/atomic_queue"
23+
NAMESPACE atomic_queue::
24+
)
25+
endif ()

0 commit comments

Comments
 (0)