From a3346b3ad552c4fa324c0a673aa9fecc1dfc9658 Mon Sep 17 00:00:00 2001 From: Cazadorro Date: Sun, 14 Jan 2024 00:01:40 -0600 Subject: [PATCH 1/6] Modified CMakeList.txt to be installable, now accessible through moodycamel::readerwriterqueue in both subdirectory and installed cmake project (didn't change targets that were already avaible, though projectect previously didn't work as an installable cmake project) also added test targets disabled by default configurable with variable psuedo namespaced 'MOODYCAMEL_READERWRITERQUEUE_ENABLE_TESTS', test targets are unittests and stabtest, completely ignores msvc project files and make files, so no need for those going forward, and though better practice would be to change the includes to be more target friendly (not use bespoke relative includes), I decided not to change that, so the previous way to build and run the test will *also* still work. Added best pairing of MSVC equivalent compile commands I could find, and I verified all tests build and run correctly on Windows 11 with MSVC 14.38.33130 --- CMakeLists.txt | 140 ++++++++++++++++++++++++++++++++++++++++-- cmake/config.cmake.in | 5 ++ 2 files changed, 141 insertions(+), 4 deletions(-) create mode 100644 cmake/config.cmake.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 3cb48a9..54b6d6a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,11 +1,143 @@ cmake_minimum_required(VERSION 3.9) -project(readerwriterqueue VERSION 1.0.0) +set(CMAKE_CXX_STANDARD 11) # don't need to specifiy +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +project(readerwriterqueue) + +add_library(readerwriterqueue INTERFACE) + +# This needs to be updated everytime the library tag version updates. The version is not 1.0.0, it's 1.0.6 according to tags. +set_target_properties(readerwriterqueue PROPERTIES + SOVERSION 1 + VERSION 1.0.6) + +#see this talk for why these changes need to be made https://www.youtube.com/watch?v=m0DwB4OvDXk + +target_include_directories(readerwriterqueue INTERFACE + $ + $ + $ +) + +set_target_properties(readerwriterqueue PROPERTIES EXPORT_NAME readerwriterqueue) + +# This is here to ensure parity with the install interface, but won't hide the previous target name. +add_library(moodycamel::readerwriterqueue ALIAS readerwriterqueue) + + +include(CMakePackageConfigHelpers) include(GNUInstallDirs) -add_library(${PROJECT_NAME} INTERFACE) +install(TARGETS readerwriterqueue + EXPORT readerwriterqueue_Targets + COMPONENT readerwriterqueue_Development + INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + COMPONENT creaderwriterqueue_RunTime + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + COMPONENT readerwriterqueue_RunTIme + NAMELINK_COMPONENT readerwriterqueue_Development + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + COMPONENT readerwriterqueue_Development +) + +set(readerwriterqueue_INSTALL_CMAKEDIR + ${CMAKE_INSTALL_DATADIR}/readerwriterqueue + CACHE STRING "Path to readerwriterqueue cmake files" +) + +install(EXPORT readerwriterqueue_Targets + DESTINATION ${readerwriterqueue_INSTALL_CMAKEDIR} + NAMESPACE moodycamel:: + FILE readerwriterqueueTargets.cmake + COMPONENT readerwriterqueue_Development +) + +configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/config.cmake.in + "${CMAKE_CURRENT_BINARY_DIR}/readerwriterqueueConfig.cmake" + INSTALL_DESTINATION ${readerwriterqueue_INSTALL_CMAKEDIR} +) -target_include_directories(readerwriterqueue INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}) -install(FILES atomicops.h readerwriterqueue.h readerwritercircularbuffer.h LICENSE.md +get_target_property(readerwriterqueue_VERSION readerwriterqueue VERSION) + +write_basic_package_version_file(readerwriterqueueConfigVersion.cmake VERSION ${readerwriterqueue_VERSION} COMPATIBILITY SameMajorVersion) + +install(FILES + ${CMAKE_CURRENT_BINARY_DIR}/readerwriterqueueConfig.cmake + ${CMAKE_CURRENT_BINARY_DIR}/readerwriterqueueConfigVersion.cmake + DESTINATION ${readerwriterqueue_INSTALL_CMAKEDIR} +) + + +install(FILES + atomicops.h + readerwriterqueue.h + readerwritercircularbuffer.h + LICENSE.md DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}) + + +option(MOODYCAMEL_READERWRITERQUEUE_ENABLE_TESTS "Enables readerwriterqueue tests" OFF) + +if(${MOODYCAMEL_READERWRITERQUEUE_ENABLE_TESTS}) + + find_package(Threads REQUIRED) +# add_library(simple) + add_executable(unittests) + target_sources(unittests PRIVATE + tests/unittests/minitest.h + tests/unittests/unittests.cpp + tests/common/simplethread.h + tests/common/simplethread.cpp + ) + target_include_directories(unittests PRIVATE + tests/unittests/) +# static. + set_property(TARGET unittests PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") + # handles pthread and such. + target_link_libraries(unittests PRIVATE Threads::Threads) +# target_link_libraries(unittests PRIVATE readerwriterqueue) + target_compile_options(unittests + PRIVATE + $<$: -Wsign-conversion -Wpedantic -Wall -DNDEBUG -O3 -g> + $<$: -Wsign-conversion -Wpedantic -Wall -DNDEBUG -O3 -g> +# /W4 is similar to -Wall, next are similar to -sign-conversion, /permissive- is similar to -Wpedantic. + $<$: /W4 /w14287 /w14826 /permissive- /02 /DEBUG> + ) + target_link_options(unittests + PRIVATE + $<$: -lrt -Wl,--no-as-needed> + $<$: -lrt -Wl,--no-as-needed> + ) + + # add_library(simple) + add_executable(stabtest) + target_sources(stabtest PRIVATE + tests/stabtest/stabtest.cpp + tests/common/simplethread.h + tests/common/simplethread.cpp + ) + target_include_directories(stabtest PRIVATE + tests/stabtest/) + # static. + set_property(TARGET stabtest PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") + # handles pthread and such. + target_link_libraries(stabtest PRIVATE Threads::Threads) + # target_link_libraries(unittests PRIVATE readerwriterqueue) + target_compile_options(stabtest + PRIVATE + $<$: -Wsign-conversion -Wpedantic -Wall -DNDEBUG -O3 -g> + $<$: -Wsign-conversion -Wpedantic -Wall -DNDEBUG -O3 -g> + # /W4 is similar to -Wall, next are similar to -sign-conversion, /permissive- is similar to -Wpedantic. + $<$: /W4 /w14287 /w14826 /permissive- /02 /DEBUG> + ) + target_link_options(stabtest + PRIVATE + $<$: -lrt -Wl,--no-as-needed> + $<$: -lrt -Wl,--no-as-needed> + ) + + +endif() \ No newline at end of file diff --git a/cmake/config.cmake.in b/cmake/config.cmake.in new file mode 100644 index 0000000..bba0649 --- /dev/null +++ b/cmake/config.cmake.in @@ -0,0 +1,5 @@ +@PACKAGE_INIT@ + +include("${CMAKE_CURRENT_LIST_DIR}/readerwriterqueueTargets.cmake") +# normally find_dependency macro dependencies, but there are none here. +check_required_components(readerwriterqueue) \ No newline at end of file From febad5650c80fd1172cef09ecb749e39c3bea3fd Mon Sep 17 00:00:00 2001 From: Cazadorro Date: Sun, 14 Jan 2024 10:55:27 -0600 Subject: [PATCH 2/6] fixed include order for gnu install dirs --- CMakeLists.txt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 54b6d6a..5aad14b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,6 +2,8 @@ cmake_minimum_required(VERSION 3.9) set(CMAKE_CXX_STANDARD 11) # don't need to specifiy set(CMAKE_CXX_STANDARD_REQUIRED ON) +include(GNUInstallDirs) + project(readerwriterqueue) add_library(readerwriterqueue INTERFACE) @@ -25,9 +27,7 @@ set_target_properties(readerwriterqueue PROPERTIES EXPORT_NAME readerwriterqueue add_library(moodycamel::readerwriterqueue ALIAS readerwriterqueue) -include(CMakePackageConfigHelpers) -include(GNUInstallDirs) install(TARGETS readerwriterqueue EXPORT readerwriterqueue_Targets @@ -54,6 +54,7 @@ install(EXPORT readerwriterqueue_Targets COMPONENT readerwriterqueue_Development ) +include(CMakePackageConfigHelpers) configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/config.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/readerwriterqueueConfig.cmake" INSTALL_DESTINATION ${readerwriterqueue_INSTALL_CMAKEDIR} From 03600f4c82fc78b8719080dc9d54e8f5c4495458 Mon Sep 17 00:00:00 2001 From: Cazadorro Date: Sun, 14 Jan 2024 11:01:40 -0600 Subject: [PATCH 3/6] Fixed misleading comment --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5aad14b..dc75ee5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.9) -set(CMAKE_CXX_STANDARD 11) # don't need to specifiy +set(CMAKE_CXX_STANDARD 11) # don't need to specify manually per target anymore. set(CMAKE_CXX_STANDARD_REQUIRED ON) include(GNUInstallDirs) From 6f613d548dbee98b5322462f4dd39ac6b2ddf747 Mon Sep 17 00:00:00 2001 From: Cazadorro Date: Sun, 21 Jan 2024 21:05:26 -0600 Subject: [PATCH 4/6] made comments more informative, added configuration sets of compile arguments for release, debug and relwithdebinfo for tests, otherwise would force relwithdebinfo or fail to compile. --- CMakeLists.txt | 57 +++++++++++++++++++++++++++++++++++++------------- 1 file changed, 43 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index dc75ee5..1dbea57 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,12 +8,12 @@ project(readerwriterqueue) add_library(readerwriterqueue INTERFACE) -# This needs to be updated everytime the library tag version updates. The version is not 1.0.0, it's 1.0.6 according to tags. +# This needs to be updated everytime the library git tag version updates. The version is not 1.0.0, it's 1.0.6 according to tags. set_target_properties(readerwriterqueue PROPERTIES SOVERSION 1 VERSION 1.0.6) -#see this talk for why these changes need to be made https://www.youtube.com/watch?v=m0DwB4OvDXk +#see this talk by Craig Scott from cppcon for the rational behind the various install directives used https://www.youtube.com/watch?v=m0DwB4OvDXk target_include_directories(readerwriterqueue INTERFACE $ @@ -85,7 +85,7 @@ option(MOODYCAMEL_READERWRITERQUEUE_ENABLE_TESTS "Enables readerwriterqueue test if(${MOODYCAMEL_READERWRITERQUEUE_ENABLE_TESTS}) find_package(Threads REQUIRED) -# add_library(simple) + add_executable(unittests) target_sources(unittests PRIVATE tests/unittests/minitest.h @@ -95,17 +95,48 @@ if(${MOODYCAMEL_READERWRITERQUEUE_ENABLE_TESTS}) ) target_include_directories(unittests PRIVATE tests/unittests/) -# static. +# static msvc runtime always, configured to support debug or release. set_property(TARGET unittests PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") # handles pthread and such. target_link_libraries(unittests PRIVATE Threads::Threads) +# would normally use the target itself, but the test files are not currently set up to handle this because of relative include paths. # target_link_libraries(unittests PRIVATE readerwriterqueue) + + set(MOODYCAMEL_CLANG_EXTRA_COMPILE_FLAGS -Wsign-conversion -Wpedantic -Wall ) + set(MOODYCAMEL_GCC_EXTRA_COMPILE_FLAGS -Wsign-conversion -Wpedantic -Wall ) + set(MOODYCAMEL_MSVC_EXTRA_COMPILE_FLAGS /W4 /w14287 /w14826 /permissive- ) + set(MOODYCAMEL_EXTRA_CONFIG_COMPILE_FLAGS + + # RelWitHDebInfo was the only configuration supported initially. + $<$: + $<$: ${MOODYCAMEL_CLANG_EXTRA_COMPILE_FLAGS} -DNDEBUG -O3 -g> + $<$: ${MOODYCAMEL_GCC_EXTRA_COMPILE_FLAGS} -DNDEBUG -O3 -g> + # /W4 is similar to -Wall, next are similar to -sign-conversion, /permissive- is similar to -Wpedantic. + # /02 is optimize for speed, /DEBUG does the equivalent thing as -g + $<$:${MOODYCAMEL_MSVC_EXTRA_COMPILE_FLAGS} -DNDEBUG /O2 /DEBUG> + + + > + + $<$: + $<$: ${MOODYCAMEL_CLANG_EXTRA_COMPILE_FLAGS} -O3> + $<$: ${MOODYCAMEL_GCC_EXTRA_COMPILE_FLAGS} -O3> + # /W4 is similar to -Wall, next are similar to -sign-conversion, /permissive- is similar to -Wpedantic. + # /02 is optimize for speed, + $<$: ${MOODYCAMEL_MSVC_EXTRA_COMPILE_FLAGS} /O2> + > + + # RelWitHDebInfo was the only configuration supported initially. + $<$: + $<$: ${MOODYCAMEL_CLANG_EXTRA_COMPILE_FLAGS} -DNDEBUG -Og -g> + $<$: ${MOODYCAMEL_GCC_EXTRA_COMPILE_FLAGS} -DNDEBUG -Og -g> + # /W4 is similar to -Wall, next are similar to -sign-conversion, /permissive- is similar to -Wpedantic. + # /02 is optimize for speed, /DEBUG does the equivalent thing as -g + $<$: ${MOODYCAMEL_MSVC_EXTRA_COMPILE_FLAGS} -DNDEBUG /Od> + >) target_compile_options(unittests PRIVATE - $<$: -Wsign-conversion -Wpedantic -Wall -DNDEBUG -O3 -g> - $<$: -Wsign-conversion -Wpedantic -Wall -DNDEBUG -O3 -g> -# /W4 is similar to -Wall, next are similar to -sign-conversion, /permissive- is similar to -Wpedantic. - $<$: /W4 /w14287 /w14826 /permissive- /02 /DEBUG> + ${MOODYCAMEL_EXTRA_CONFIG_COMPILE_FLAGS} ) target_link_options(unittests PRIVATE @@ -113,7 +144,7 @@ if(${MOODYCAMEL_READERWRITERQUEUE_ENABLE_TESTS}) $<$: -lrt -Wl,--no-as-needed> ) - # add_library(simple) + add_executable(stabtest) target_sources(stabtest PRIVATE tests/stabtest/stabtest.cpp @@ -122,17 +153,15 @@ if(${MOODYCAMEL_READERWRITERQUEUE_ENABLE_TESTS}) ) target_include_directories(stabtest PRIVATE tests/stabtest/) - # static. + # static msvc runtime always, configured to support debug or release. set_property(TARGET stabtest PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") # handles pthread and such. target_link_libraries(stabtest PRIVATE Threads::Threads) + # would normally use the target itself, but the test files are not currently set up to handle this because of relative include paths. # target_link_libraries(unittests PRIVATE readerwriterqueue) target_compile_options(stabtest PRIVATE - $<$: -Wsign-conversion -Wpedantic -Wall -DNDEBUG -O3 -g> - $<$: -Wsign-conversion -Wpedantic -Wall -DNDEBUG -O3 -g> - # /W4 is similar to -Wall, next are similar to -sign-conversion, /permissive- is similar to -Wpedantic. - $<$: /W4 /w14287 /w14826 /permissive- /02 /DEBUG> + ${MOODYCAMEL_EXTRA_CONFIG_COMPILE_FLAGS} ) target_link_options(stabtest PRIVATE From 7a5935725ff42ac744358747e31bc96d97e499a6 Mon Sep 17 00:00:00 2001 From: Cazadorro Date: Sun, 21 Jan 2024 22:54:44 -0600 Subject: [PATCH 5/6] moved -DNDEBUG into target_compile_definitions where it belongs, probably not needed, believe configs add this anyway, but it doesn't hurt to add --- CMakeLists.txt | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1dbea57..b0cfe2d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -109,11 +109,11 @@ if(${MOODYCAMEL_READERWRITERQUEUE_ENABLE_TESTS}) # RelWitHDebInfo was the only configuration supported initially. $<$: - $<$: ${MOODYCAMEL_CLANG_EXTRA_COMPILE_FLAGS} -DNDEBUG -O3 -g> - $<$: ${MOODYCAMEL_GCC_EXTRA_COMPILE_FLAGS} -DNDEBUG -O3 -g> + $<$: ${MOODYCAMEL_CLANG_EXTRA_COMPILE_FLAGS} -O3 -g> + $<$: ${MOODYCAMEL_GCC_EXTRA_COMPILE_FLAGS} -O3 -g> # /W4 is similar to -Wall, next are similar to -sign-conversion, /permissive- is similar to -Wpedantic. # /02 is optimize for speed, /DEBUG does the equivalent thing as -g - $<$:${MOODYCAMEL_MSVC_EXTRA_COMPILE_FLAGS} -DNDEBUG /O2 /DEBUG> + $<$:${MOODYCAMEL_MSVC_EXTRA_COMPILE_FLAGS} /O2 /DEBUG> > @@ -128,16 +128,22 @@ if(${MOODYCAMEL_READERWRITERQUEUE_ENABLE_TESTS}) # RelWitHDebInfo was the only configuration supported initially. $<$: - $<$: ${MOODYCAMEL_CLANG_EXTRA_COMPILE_FLAGS} -DNDEBUG -Og -g> - $<$: ${MOODYCAMEL_GCC_EXTRA_COMPILE_FLAGS} -DNDEBUG -Og -g> + $<$: ${MOODYCAMEL_CLANG_EXTRA_COMPILE_FLAGS} -Og -g> + $<$: ${MOODYCAMEL_GCC_EXTRA_COMPILE_FLAGS} -Og -g> # /W4 is similar to -Wall, next are similar to -sign-conversion, /permissive- is similar to -Wpedantic. # /02 is optimize for speed, /DEBUG does the equivalent thing as -g - $<$: ${MOODYCAMEL_MSVC_EXTRA_COMPILE_FLAGS} -DNDEBUG /Od> + $<$: ${MOODYCAMEL_MSVC_EXTRA_COMPILE_FLAGS} /Od> >) + + target_compile_options(unittests PRIVATE ${MOODYCAMEL_EXTRA_CONFIG_COMPILE_FLAGS} ) + + target_compile_definitions(unittests PRIVATE + $<$, $>:-DNDEBUG> + ) target_link_options(unittests PRIVATE $<$: -lrt -Wl,--no-as-needed> From c2d35670ff67ddf89d88b910b2fb6001cd9eed22 Mon Sep 17 00:00:00 2001 From: Cazadorro Date: Sun, 21 Jan 2024 23:08:28 -0600 Subject: [PATCH 6/6] inverted the logic on target compile definitions, meant to do relaese and relaase with debuginfo *with out* assertions running, fixed generator statements, and moved include for GNUInstallDirs so it no longer complains about it's location --- CMakeLists.txt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b0cfe2d..dc2f878 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,10 +1,10 @@ cmake_minimum_required(VERSION 3.9) + set(CMAKE_CXX_STANDARD 11) # don't need to specify manually per target anymore. set(CMAKE_CXX_STANDARD_REQUIRED ON) -include(GNUInstallDirs) - project(readerwriterqueue) +include(GNUInstallDirs) add_library(readerwriterqueue INTERFACE) @@ -142,7 +142,8 @@ if(${MOODYCAMEL_READERWRITERQUEUE_ENABLE_TESTS}) ) target_compile_definitions(unittests PRIVATE - $<$, $>:-DNDEBUG> + $<$:-DNDEBUG> + $<$:-DNDEBUG> ) target_link_options(unittests PRIVATE