Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/add cmake support #161

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
cmake_minimum_required(VERSION 3.13)
project(concurrentqueue VERSION 0.1 LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 11)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)

enable_testing()

add_library(concurrentqueue INTERFACE)

# -Wall -pedantic-errors -Wpedantic -Wconversion -fno-elide-constructors
target_compile_options(concurrentqueue INTERFACE -Wall -pedantic-errors -Wpedantic -Wconversion -fno-elide-constructors)

target_include_directories(concurrentqueue INTERFACE
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
target_link_libraries(concurrentqueue INTERFACE Threads::Threads rt)

include(CMakePackageConfigHelpers)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line 21 to end of file is all about install and generate of .cmake for header only lib

write_basic_package_version_file(
"${PROJECT_BINARY_DIR}/concurrentqueueConfigVersion.cmake"
VERSION 0.1
COMPATIBILITY AnyNewerVersion
)
install(TARGETS concurrentqueue
EXPORT concurrentqueueTargets
LIBRARY DESTINATION lib COMPONENT Runtime
ARCHIVE DESTINATION lib COMPONENT Development
RUNTIME DESTINATION bin COMPONENT Runtime
PUBLIC_HEADER DESTINATION include COMPONENT Development
BUNDLE DESTINATION bin COMPONENT Runtime
)
include(CMakePackageConfigHelpers)
configure_package_config_file(
"${PROJECT_SOURCE_DIR}/cmake/concurrentqueueConfig.cmake.in"
"${PROJECT_BINARY_DIR}/concurrentqueueConfig.cmake"
INSTALL_DESTINATION lib/cmake/concurrentqueue
)
install(EXPORT concurrentqueueTargets DESTINATION lib/cmake/concurrentqueue)
install(FILES "${PROJECT_BINARY_DIR}/concurrentqueueConfigVersion.cmake"
"${PROJECT_BINARY_DIR}/concurrentqueueConfig.cmake"
DESTINATION lib/cmake/concurrentqueue)
install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/ DESTINATION include)

add_subdirectory(tests)
2 changes: 1 addition & 1 deletion benchmarks/benchmarks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include <algorithm>
#include <cctype>

#include "../blockingconcurrentqueue.h"
#include "concurrentqueue/blockingconcurrentqueue.h"
#include "lockbasedqueue.h"
#include "simplelockfree.h"
#include "boostqueue.h"
Expand Down
6 changes: 3 additions & 3 deletions build/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ benchmarks: bin/benchmarks$(EXT)

bin/unittests$(EXT): ../concurrentqueue.h ../blockingconcurrentqueue.h ../tests/unittests/unittests.cpp ../tests/unittests/mallocmacro.cpp ../tests/common/simplethread.h ../tests/common/simplethread.cpp ../tests/common/systemtime.h ../tests/common/systemtime.cpp ../tests/corealgos.h ../tests/unittests/minitest.h makefile
test -d bin || mkdir bin
g++ -std=c++11 -Wall -pedantic-errors -Wpedantic -Wconversion $(OPTS) -fno-elide-constructors ../tests/common/simplethread.cpp ../tests/common/systemtime.cpp ../tests/unittests/unittests.cpp -o bin/unittests$(EXT) $(LD_OPTS)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO - need to test gnu make with the new includes

g++ -std=c++11 -Wall -pedantic-errors -Wpedantic -Wconversion $(OPTS) -I../include -fno-elide-constructors ../tests/common/simplethread.cpp ../tests/common/systemtime.cpp ../tests/unittests/unittests.cpp -o bin/unittests$(EXT) $(LD_OPTS)

bin/fuzztests$(EXT): ../concurrentqueue.h ../tests/fuzztests/fuzztests.cpp ../tests/common/simplethread.h ../tests/common/simplethread.cpp ../tests/common/systemtime.h ../tests/common/systemtime.cpp ../tests/corealgos.h makefile
test -d bin || mkdir bin
g++ -std=c++11 -Wall -pedantic-errors -Wpedantic $(BENCH_OPTS) ../tests/common/simplethread.cpp ../tests/common/systemtime.cpp ../tests/fuzztests/fuzztests.cpp -o bin/fuzztests$(EXT) $(LD_OPTS)
g++ -std=c++11 -Wall -pedantic-errors -Wpedantic $(BENCH_OPTS) -I../include ../tests/common/simplethread.cpp ../tests/common/systemtime.cpp ../tests/fuzztests/fuzztests.cpp -o bin/fuzztests$(EXT) $(LD_OPTS)

bin/benchmarks$(EXT): bin/libtbb.a ../concurrentqueue.h ../benchmarks/benchmarks.cpp ../benchmarks/cpuid.h ../benchmarks/cpuid.cpp ../benchmarks/lockbasedqueue.h ../benchmarks/simplelockfree.h ../tests/common/simplethread.h ../tests/common/simplethread.cpp ../tests/common/systemtime.h ../tests/common/systemtime.cpp makefile
test -d bin || mkdir bin
g++ -std=c++11 -Wall -pedantic-errors -Wpedantic $(BENCH_OPTS) -I../benchmarks ../benchmarks/cpuid.cpp ../tests/common/simplethread.cpp ../tests/common/systemtime.cpp ../benchmarks/benchmarks.cpp -o bin/benchmarks$(EXT) -Lbin -ltbb $(LD_OPTS)
g++ -std=c++11 -Wall -pedantic-errors -Wpedantic $(BENCH_OPTS) -I../include -I../benchmarks ../benchmarks/cpuid.cpp ../tests/common/simplethread.cpp ../tests/common/systemtime.cpp ../benchmarks/benchmarks.cpp -o bin/benchmarks$(EXT) -Lbin -ltbb $(LD_OPTS)

bin/libtbb.a: makefile
test -d bin || mkdir bin
Expand Down
4 changes: 4 additions & 0 deletions cmake/concurrentqueueConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@PACKAGE_INIT@

include("${CMAKE_INSTALL_PREFIX}/lib/cmake/concurrentqueue/concurrentqueueTargets.cmake")
check_required_components("@PROJECT_NAME@")
File renamed without changes.
File renamed without changes.
39 changes: 39 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
set(UNITTESTS_SRC
unittests/unittests.cpp
unittests/mallocmacro.cpp
common/simplethread.cpp
common/systemtime.cpp
)
add_executable(unittests ${UNITTESTS_SRC})
target_link_libraries(unittests PRIVATE concurrentqueue)
add_test(NAME unittests COMMAND unittests)

set(FUZZTESTS_SRC
fuzztests/fuzztests.cpp
common/simplethread.cpp
common/systemtime.cpp
)
add_executable(fuzztests ${FUZZTESTS_SRC})
target_link_libraries(fuzztests PRIVATE concurrentqueue)
add_test(NAME fuzztests COMMAND fuzztests)

set(LIBTBB_SRC
${concurrentqueue_SOURCE_DIR}/benchmarks/tbb/cache_aligned_allocator.cpp
${concurrentqueue_SOURCE_DIR}/benchmarks/tbb/concurrent_queue.cpp
${concurrentqueue_SOURCE_DIR}/benchmarks/tbb/dynamic_link.cpp
${concurrentqueue_SOURCE_DIR}/benchmarks/tbb/tbb_misc.cpp
)
add_library(libtbb STATIC ${LIBTBB_SRC})
target_include_directories(libtbb PUBLIC ${concurrentqueue_SOURCE_DIR}/benchmarks/)
set_property(TARGET libtbb PROPERTY POSITION_INDEPENDENT_CODE ON)

set(BENCHMARKS_SRC
${concurrentqueue_SOURCE_DIR}/benchmarks/benchmarks.cpp
${concurrentqueue_SOURCE_DIR}/benchmarks/cpuid.cpp
common/simplethread.cpp
common/systemtime.cpp
)
add_executable(benchmarks ${BENCHMARKS_SRC})
target_link_libraries(benchmarks PRIVATE concurrentqueue libtbb)
add_test(NAME benchmarks COMMAND benchmarks)

2 changes: 1 addition & 1 deletion tests/fuzztests/fuzztests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include <windows.h>
#endif

#include "../../concurrentqueue.h"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these changes required to conform to the / syntax of other std libraries released for public and installed under //...

#include "concurrentqueue/concurrentqueue.h"
#include "../common/simplethread.h"
#include "../common/systemtime.h"
#include "../corealgos.h"
Expand Down
2 changes: 1 addition & 1 deletion tests/unittests/mallocmacro.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#define malloc(x) malloc(x)
#define free(x) free(x)

#include "../../blockingconcurrentqueue.h"
#include "concurrentqueue//blockingconcurrentqueue.h"
4 changes: 2 additions & 2 deletions tests/unittests/unittests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
#include "minitest.h"
#include "../common/simplethread.h"
#include "../common/systemtime.h"
#include "../../concurrentqueue.h"
#include "../../blockingconcurrentqueue.h"
#include "concurrentqueue/concurrentqueue.h"
#include "concurrentqueue/blockingconcurrentqueue.h"

namespace {
struct tracking_allocator
Expand Down