From e7170afb3101f56611fa97c76ec5983d5053f266 Mon Sep 17 00:00:00 2001 From: Kobi Cohen-Arazi Date: Thu, 18 Jul 2019 10:46:28 -0700 Subject: [PATCH 1/5] Added top level CMakeLists.txt and tests CMakeLists.txt First commit with CMakeLists.txt and tests CMakeLists.txt enabled --- CMakeLists.txt | 18 ++++++++++++++++++ tests/CMakeLists.txt | 11 +++++++++++ 2 files changed, 29 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 tests/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 00000000..a2aafd19 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,18 @@ +cmake_minimum_required(VERSION 3.14) +project(concurrentqueue CXX) + +set(CMAKE_C_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 .) +target_link_libraries(concurrentqueue INTERFACE Threads::Threads rt) + +add_subdirectory(tests) \ No newline at end of file diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 00000000..c7bbb3a5 --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,11 @@ +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) \ No newline at end of file From 1276a65b6d33cffd75c9d35426a4919ccd76cc55 Mon Sep 17 00:00:00 2001 From: Kobi Cohen-Arazi Date: Thu, 18 Jul 2019 11:03:47 -0700 Subject: [PATCH 2/5] tests/CMakeLists.txt added tests added tests to tests/CMakeLists.txt libtbb, benchmark, unittests and fuzztests --- tests/CMakeLists.txt | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index c7bbb3a5..1b662c81 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -4,8 +4,35 @@ set(UNITTESTS_SRC 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(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) -add_test(NAME unittests COMMAND unittests) \ No newline at end of file From a150265ff25a2153250354bee631cc83daebf5ec Mon Sep 17 00:00:00 2001 From: Kobi Cohen-Arazi Date: Thu, 18 Jul 2019 11:14:46 -0700 Subject: [PATCH 3/5] Added install cmake file to interface library taken from https://stackoverflow.com/questions/47718485/install-and-export-interface-only-library-cmake --- CMakeLists.txt | 33 ++++++++++++++++++++++++++-- cmake/concurrentqueueConfig.cmake.in | 4 ++++ 2 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 cmake/concurrentqueueConfig.cmake.in diff --git a/CMakeLists.txt b/CMakeLists.txt index a2aafd19..90f45e2c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.14) -project(concurrentqueue CXX) +project(concurrentqueue VERSION 0.1 LANGUAGES CXX) set(CMAKE_C_STANDARD 11) set(THREADS_PREFER_PTHREAD_FLAG ON) @@ -12,7 +12,36 @@ 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 .) +target_include_directories(concurrentqueue INTERFACE + $ + $ +) target_link_libraries(concurrentqueue INTERFACE Threads::Threads rt) +include(CMakePackageConfigHelpers) +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) \ No newline at end of file diff --git a/cmake/concurrentqueueConfig.cmake.in b/cmake/concurrentqueueConfig.cmake.in new file mode 100644 index 00000000..84f271f5 --- /dev/null +++ b/cmake/concurrentqueueConfig.cmake.in @@ -0,0 +1,4 @@ +@PACKAGE_INIT@ + +include("${CMAKE_INSTALL_PREFIX}/lib/cmake/concurrentqueue/concurrentqueueTargets.cmake") +check_required_components("@PROJECT_NAME@") \ No newline at end of file From 93be8ef23e3e88e014731b08a94acb1c5adc39b8 Mon Sep 17 00:00:00 2001 From: Kobi Cohen-Arazi Date: Thu, 18 Jul 2019 11:28:28 -0700 Subject: [PATCH 4/5] Move include to include/concurrentqueue and adapt makefiles Adapt makefiles, cpp to match new include/concurrentqueue include path --- CMakeLists.txt | 4 ++-- benchmarks/benchmarks.cpp | 2 +- build/makefile | 6 +++--- .../concurrentqueue/blockingconcurrentqueue.h | 0 .../concurrentqueue/concurrentqueue.h | 0 tests/CMakeLists.txt | 1 + tests/fuzztests/fuzztests.cpp | 2 +- tests/unittests/mallocmacro.cpp | 2 +- tests/unittests/unittests.cpp | 4 ++-- 9 files changed, 11 insertions(+), 10 deletions(-) rename blockingconcurrentqueue.h => include/concurrentqueue/blockingconcurrentqueue.h (100%) rename concurrentqueue.h => include/concurrentqueue/concurrentqueue.h (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 90f45e2c..90e44a79 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.13) project(concurrentqueue VERSION 0.1 LANGUAGES CXX) set(CMAKE_C_STANDARD 11) @@ -13,7 +13,7 @@ add_library(concurrentqueue INTERFACE) target_compile_options(concurrentqueue INTERFACE -Wall -pedantic-errors -Wpedantic -Wconversion -fno-elide-constructors) target_include_directories(concurrentqueue INTERFACE - $ + $ $ ) target_link_libraries(concurrentqueue INTERFACE Threads::Threads rt) diff --git a/benchmarks/benchmarks.cpp b/benchmarks/benchmarks.cpp index 69c08a4a..ca3b820c 100644 --- a/benchmarks/benchmarks.cpp +++ b/benchmarks/benchmarks.cpp @@ -22,7 +22,7 @@ #include #include -#include "../blockingconcurrentqueue.h" +#include "concurrentqueue/blockingconcurrentqueue.h" #include "lockbasedqueue.h" #include "simplelockfree.h" #include "boostqueue.h" diff --git a/build/makefile b/build/makefile index 8805eecc..66584133 100644 --- a/build/makefile +++ b/build/makefile @@ -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) + 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 diff --git a/blockingconcurrentqueue.h b/include/concurrentqueue/blockingconcurrentqueue.h similarity index 100% rename from blockingconcurrentqueue.h rename to include/concurrentqueue/blockingconcurrentqueue.h diff --git a/concurrentqueue.h b/include/concurrentqueue/concurrentqueue.h similarity index 100% rename from concurrentqueue.h rename to include/concurrentqueue/concurrentqueue.h diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 1b662c81..1983982d 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -25,6 +25,7 @@ set(LIBTBB_SRC ) 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 diff --git a/tests/fuzztests/fuzztests.cpp b/tests/fuzztests/fuzztests.cpp index 96ec3dd2..f3808d5a 100644 --- a/tests/fuzztests/fuzztests.cpp +++ b/tests/fuzztests/fuzztests.cpp @@ -29,7 +29,7 @@ #include #endif -#include "../../concurrentqueue.h" +#include "concurrentqueue/concurrentqueue.h" #include "../common/simplethread.h" #include "../common/systemtime.h" #include "../corealgos.h" diff --git a/tests/unittests/mallocmacro.cpp b/tests/unittests/mallocmacro.cpp index 350fae49..72fbc65a 100644 --- a/tests/unittests/mallocmacro.cpp +++ b/tests/unittests/mallocmacro.cpp @@ -1,4 +1,4 @@ #define malloc(x) malloc(x) #define free(x) free(x) -#include "../../blockingconcurrentqueue.h" +#include "concurrentqueue//blockingconcurrentqueue.h" diff --git a/tests/unittests/unittests.cpp b/tests/unittests/unittests.cpp index e3254b5e..393e6e1b 100644 --- a/tests/unittests/unittests.cpp +++ b/tests/unittests/unittests.cpp @@ -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 From 530660724487180ca4254238f1949bff561c8095 Mon Sep 17 00:00:00 2001 From: Kobi Cohen-Arazi Date: Thu, 18 Jul 2019 16:28:15 -0700 Subject: [PATCH 5/5] CMakeLists.txt: changed C11 to C++11 typo in CMake file --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 90e44a79..18973e74 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.13) project(concurrentqueue VERSION 0.1 LANGUAGES CXX) -set(CMAKE_C_STANDARD 11) +set(CMAKE_CXX_STANDARD 11) set(THREADS_PREFER_PTHREAD_FLAG ON) find_package(Threads REQUIRED) @@ -44,4 +44,4 @@ install(FILES "${PROJECT_BINARY_DIR}/concurrentqueueConfigVersion.cmake" DESTINATION lib/cmake/concurrentqueue) install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/ DESTINATION include) -add_subdirectory(tests) \ No newline at end of file +add_subdirectory(tests)