diff --git a/CMakeLists.txt b/CMakeLists.txt index 3cb48a9..dc2f878 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,11 +1,180 @@ cmake_minimum_required(VERSION 3.9) -project(readerwriterqueue VERSION 1.0.0) +set(CMAKE_CXX_STANDARD 11) # don't need to specify manually per target anymore. +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +project(readerwriterqueue) include(GNUInstallDirs) -add_library(${PROJECT_NAME} INTERFACE) +add_library(readerwriterqueue INTERFACE) + +# 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 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 + $ + $ + $ +) + +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) + + + -target_include_directories(readerwriterqueue INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}) +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 +) -install(FILES atomicops.h readerwriterqueue.h readerwritercircularbuffer.h LICENSE.md +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 +) + +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} +) + + +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_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 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} -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} /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} -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} /Od> + >) + + + target_compile_options(unittests + PRIVATE + ${MOODYCAMEL_EXTRA_CONFIG_COMPILE_FLAGS} + ) + + target_compile_definitions(unittests PRIVATE + $<$:-DNDEBUG> + $<$:-DNDEBUG> + ) + target_link_options(unittests + PRIVATE + $<$: -lrt -Wl,--no-as-needed> + $<$: -lrt -Wl,--no-as-needed> + ) + + + 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 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 + ${MOODYCAMEL_EXTRA_CONFIG_COMPILE_FLAGS} + ) + 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