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

Support for cmake config and exported targets files #97

Merged
merged 1 commit into from
Jul 1, 2019
Merged
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
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ before_script:

script:
- cmake -DQUANTUM_ENABLE_TESTS=ON -DQUANTUM_BOOST_USE_VALGRIND=ON -DCMAKE_INSTALL_PREFIX=tests -DGTEST_ROOT=googletest/install .
- make quantum_tests && ./tests/quantum_tests.Linux64
- make QuantumTests && ./tests/QuantumTests.Linux64
33 changes: 19 additions & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
cmake_minimum_required(VERSION 3.10.3)
project(quantum LANGUAGES CXX)
cmake_minimum_required(VERSION 3.12.4)
cmake_policy(SET CMP0074 NEW) #Prior to 3.12 this allows using '<Package>_ROOT' to point to an package location
project(Quantum LANGUAGES CXX)
set(PROJECT_TARGET_NAME quantum)

include(GNUInstallDirs)
include(CMakePackageConfigHelpers)

# CMake options
option(QUANTUM_BUILD_DOC "Build documentation" OFF)
Expand All @@ -15,7 +20,6 @@ option(QUANTUM_BOOST_USE_SEGMENTED_STACKS "Use Boost segmented stacks for corout
option(QUANTUM_BOOST_USE_PROTECTED_STACKS "Use Boost protected stacks for coroutines." OFF)
option(QUANTUM_BOOST_USE_FIXEDSIZE_STACKS "Use Boost fixed size stacks for coroutines." OFF)


set(QUANTUM_VERSION_MAJOR 2)
set(QUANTUM_VERSION_MINOR 0)
set(QUANTUM_VERSION_REVISION 1)
Expand All @@ -27,6 +31,9 @@ endif()
if (NOT QUANTUM_PKGCONFIG_DIR)
set(QUANTUM_PKGCONFIG_DIR share/pkgconfig)
endif()
if (NOT QUANTUM_CMAKE_CONFIG_DIR)
set(QUANTUM_CMAKE_CONFIG_DIR share/cmake/${PROJECT_NAME})
endif()

#Global options
set(MODE 64)
Expand All @@ -35,18 +42,16 @@ set(CMAKE_INCLUDE_DIRECTORIES_BEFORE ON)
set(CMAKE_BUILD_TYPE Debug)

#Set the compiler if the CXX environment variable is not set
if (NOT DEFINED ENV{CXX})
if (NOT CMAKE_CXX_COMPILER)
set(CMAKE_CXX_COMPILER g++)
endif()
#Set the compiler if the CXX_STANDARD environment variable is not set
if (NOT DEFINED ENV{CXXSTANDARD})
if (NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 14)
else()
set(CMAKE_CXX_STANDARD $ENV{CXXSTANDARD})
endif()
#Set compile flags if CXXFLAGS environment variable is not set
if (NOT DEFINED ENV{CXXFLAGS})
set(CMAKE_CXX_FLAGS "-Wall -Wextra -Werror -Wabi -O0 -m${MODE} -std=c++${CMAKE_CXX_STANDARD} -ftemplate-backtrace-limit=0")
if (NOT CMAKE_CXX_FLAGS)
set(CMAKE_CXX_FLAGS "-Wall -Wextra -O0 -m${MODE} -std=c++${CMAKE_CXX_STANDARD} -ftemplate-backtrace-limit=0")
endif()
if (QUANTUM_VERBOSE_MAKEFILE)
message(STATUS "CMAKE_CXX_FLAGS = ${CMAKE_CXX_FLAGS}")
Expand Down Expand Up @@ -83,9 +88,9 @@ if (QUANTUM_BUILD_DOC)
if(DOXYGEN_FOUND)
# Configure Doxygen parameters
set(DOXYGEN_PROJECT_NAME "Quantum Library")
set(DOXYGEN_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR})
set(DOXYGEN_INPUT ${PROJECT_SOURCE_DIR}/${PROJECT_NAME})
set(DOXYGEN_HTML_OUTPUT ${PROJECT_SOURCE_DIR}/docs)
set(DOXYGEN_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}")
set(DOXYGEN_INPUT "${PROJECT_SOURCE_DIR}/${PROJECT_TARGET_NAME}")
set(DOXYGEN_HTML_OUTPUT "${PROJECT_SOURCE_DIR}/docs")
set(DOXYGEN_CREATE_SUBDIRS YES)
if (DOXYGEN_DOT_FOUND AND QUANTUM_ENABLE_DOT)
set(DOXYGEN_HAVE_DOT YES)
Expand Down Expand Up @@ -134,12 +139,12 @@ else()
message(FATAL_ERROR "Boost not found, please define BOOST_ROOT.")
endif()

add_subdirectory(${PROJECT_NAME})
add_subdirectory(${PROJECT_TARGET_NAME})

if (QUANTUM_ENABLE_TESTS)
find_package(GTest REQUIRED)
if (GTEST_FOUND)
message(STATUS "Adding target 'quantum_tests' to build output")
message(STATUS "Adding target '${PROJECT_TARGET_NAME}_tests' to build output")
enable_testing()
add_subdirectory(tests)
else()
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
**Quantum** is a full-featured and powerful C++ framework build on top of the [Boost coroutine](https://www.boost.org/doc/libs/1_65_0/libs/coroutine2/doc/html/index.html) library. The framework allows users to dispatch units of work (a.k.a. _tasks_) as coroutines and execute them concurrently using the 'reactor' pattern.

### Features

* **NEW** Added support for simpler V2 coroutine API which returns computed values [directly](https://github.com/bloomberg/quantum/wiki/4.-Quick-reference-guide).
* Header-only library and interface-based design.
* Full integration with Boost asymmetric coroutine library.
* Highly parallelized coroutine framework for CPU-bound workloads.
Expand All @@ -22,7 +24,6 @@
* Parallel `forEach` and `mapReduce` functions.
* Various stats API.
* `Sequencer` class allowing strict FIFO ordering of tasks based on sequence ids.
* **NEW** Added support for simpler V2 coroutine API which returns computed values [directly](https://github.com/bloomberg/quantum/wiki/4.-Quick-reference-guide).

### Sample code
**Quantum** is very simple and easy to use:
Expand Down Expand Up @@ -117,6 +118,7 @@ Various **CMake** options can be used to configure the output:
Default is `/usr/local/include` for Linux or `c:/Program Files` for Windows.
* `QUANTUM_PKGCONFIG_DIR` : Specify custom install path for .pc file. Default is `${QUANTUM_INSTALL_ROOT}/share/pkgconfig`.
To specify a relative path from `QUANTUM_INSTALL_ROOT`, omit leading `/`.
* `QUANTUM_CMAKE_CONFIG_DIR` : Specify a different install directory for the project's config file. Default is `${QUANTUM_INSTALL_ROOT}/share/cmake`.
* `BOOST_ROOT` : Specify a different Boost install directory.
* `GTEST_ROOT` : Specify a different GTest install directory.

Expand Down
17 changes: 17 additions & 0 deletions cmake/QuantumConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
@PACKAGE_INIT@

include(CMakeFindDependencyMacro)

# Find Boost::context
find_dependency(Boost 1.61 REQUIRED COMPONENTS context)

# Export 'Quantum_ROOT'
set_and_check(@PROJECT_NAME@_ROOT "@PACKAGE_CMAKE_INSTALL_PREFIX@")

# Export 'Quantum_INSTALL_INCLUDE_DIR'
set_and_check(@PROJECT_NAME@_INSTALL_INCLUDE_DIR "@PACKAGE_CMAKE_INSTALL_INCLUDEDIR@")

include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake")

# Validate installed components
check_required_components("@PROJECT_NAME@")
File renamed without changes.
File renamed without changes.
81 changes: 52 additions & 29 deletions quantum/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ function(make_quantum_header)
"*.h"
"interface/*.h"
"util/*.h")
SET(PROJECT_INCLUDE_HEADERS "${INCLUDE_HEADERS}" CACHE INTERNAL "Quantum include headers")
list(SORT INCLUDE_HEADERS)
foreach(header ${INCLUDE_HEADERS})
if (NOT ${header} MATCHES "quantum.h")
Expand All @@ -13,50 +14,72 @@ function(make_quantum_header)
endforeach()

#create file from template
configure_file(${PROJECT_SOURCE_DIR}/quantum.h.in ${QUANTUM_HEADER} @ONLY)
configure_file(${PROJECT_SOURCE_DIR}/cmake/quantum.h.in ${QUANTUM_HEADER} @ONLY)
endfunction()

# Run file generation function
make_quantum_header()

# Generate package configuration file
set(PKG_CONFIG ${PROJECT_SOURCE_DIR}/package/quantum.pc)
configure_file(${PROJECT_SOURCE_DIR}/quantum.pc.in ${PKG_CONFIG} @ONLY)
set(PKG_DIR "${CMAKE_BINARY_DIR}/package")
set(PKGCONFIG_FILE "${PKG_DIR}/${PROJECT_TARGET_NAME}.pc")
set(TARGET_CONFIG_FILE "${PKG_DIR}/${PROJECT_NAME}Config.cmake")
set(TARGET_VERSION_FILE "${PKG_DIR}/${PROJECT_NAME}ConfigVersion.cmake")
set(TARGET_EXPORT_NAME ${PROJECT_NAME}Targets)
set(NAMESPACE "${PROJECT_NAME}::")

# Install headers including the auto-generated quantum.h
file(GLOB INCLUDE_FILES "*.h")
file(GLOB IMPL_INCLUDE_FILES "impl/*.h")
file(GLOB INTERFACE_INCLUDE_FILES "interface/*.h")
file(GLOB UTIL_INCLUDE_FILES "util/*.h")
file(GLOB UTIL_IMPL_INCLUDE_FILES "util/impl/*.h")
add_library(${PROJECT_TARGET_NAME} INTERFACE)
set(QUANTUM_DEPENDENCIES Boost::context pthread)
set_target_properties(${PROJECT_TARGET_NAME} PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES $<INSTALL_INTERFACE:include>
INTERFACE_LINK_LIBRARIES "${QUANTUM_DEPENDENCIES}"
INTERFACE_POSITION_INDEPENDENT_CODE ON
INTERFACE_SOURCES ${CMAKE_INSTALL_PREFIX}/include/quantum.h
)

# Install target
install(
FILES ${INCLUDE_FILES}
DESTINATION include/quantum
TARGETS ${PROJECT_TARGET_NAME}
EXPORT ${TARGET_EXPORT_NAME}
COMPONENT headers
)

# Install headers
install(FILES ${PROJECT_INCLUDE_HEADERS}
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")

# Install the exported file
install(
FILES ${IMPL_INCLUDE_FILES}
DESTINATION include/quantum/impl/
COMPONENT headers
EXPORT ${TARGET_EXPORT_NAME}
NAMESPACE "${NAMESPACE}"
DESTINATION "${QUANTUM_CMAKE_CONFIG_DIR}"
)

# Generate package configuration file
configure_file(${PROJECT_SOURCE_DIR}/cmake/quantum.pc.in ${PKGCONFIG_FILE} @ONLY)

# Install the pkgconfig file
install(
FILES ${INTERFACE_INCLUDE_FILES}
DESTINATION include/quantum/interface/
COMPONENT headers
FILES ${PKGCONFIG_FILE}
DESTINATION ${QUANTUM_PKGCONFIG_DIR}
COMPONENT pkgconfig
)
install(
FILES ${UTIL_INCLUDE_FILES}
DESTINATION include/quantum/util/
COMPONENT headers

# Generate CMAKE configuration file and exported targets
configure_package_config_file(
"${PROJECT_SOURCE_DIR}/cmake/${PROJECT_NAME}Config.cmake.in"
"${TARGET_CONFIG_FILE}"
INSTALL_DESTINATION "${QUANTUM_CMAKE_CONFIG_DIR}"
PATH_VARS CMAKE_INSTALL_PREFIX CMAKE_INSTALL_INCLUDEDIR
)
install(
FILES ${UTIL_IMPL_INCLUDE_FILES}
DESTINATION include/quantum/util/impl
COMPONENT headers

# Generate version file
write_basic_package_version_file(
"${TARGET_VERSION_FILE}"
VERSION ${QUANTUM_VERSION}
COMPATIBILITY AnyNewerVersion
)

install(
FILES ${PKG_CONFIG}
DESTINATION ${QUANTUM_PKGCONFIG_DIR}
COMPONENT pkgconfig
FILES "${TARGET_CONFIG_FILE}" "${TARGET_VERSION_FILE}"
DESTINATION "${QUANTUM_CMAKE_CONFIG_DIR}"
)
9 changes: 4 additions & 5 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
include(GoogleTest)
set(TEST_TARGET quantum_tests)
set(TEST_TARGET ${PROJECT_NAME}Tests)
file(GLOB SOURCE_FILES *.cpp)
include_directories(AFTER
${PROJECT_SOURCE_DIR}
Expand All @@ -15,7 +15,7 @@ add_executable(${TEST_TARGET} ${SOURCE_FILES})
gtest_discover_tests(${TEST_TARGET}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
target_link_libraries(${TEST_TARGET}
${Boost_LIBRARIES}
Boost::context
GTest::GTest
GTest::Main
pthread
Expand All @@ -32,6 +32,5 @@ if (QUANTUM_VERBOSE_MAKEFILE)
message(STATUS "INCLUDE_DIRECTORIES = ${inc_dirs}")
message(STATUS "LINK_DIRECTORIES = ${link_dirs}")
endif()
add_custom_target(tests)
add_dependencies(tests ${TEST_TARGET})
add_test(${PROJECT_NAME} ${TEST_TARGET})
add_test(NAME ${TEST_TARGET}
COMMAND ${TEST_TARGET})