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

[HOLD MERGE PLEASE] ThreadPool compile time template parameter; CMake + CI cross platform work #9

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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
124 changes: 124 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
S# Lineage: ruslo/hunter test scripts
# test

# OSX/Linux (https://github.com/travis-ci-tester/toolchain-table)

language:
- cpp

# Container-based infrastructure (Linux)
# * https://docs.travis-ci.com/user/migrating-from-legacy/#How-can-I-use-container-based-infrastructure%3F
sudo:
- false

# Install packages differs for container-based infrastructure
# * https://docs.travis-ci.com/user/migrating-from-legacy/#How-do-I-install-APT-sources-and-packages%3F
# * http://stackoverflow.com/a/30925448/2288008
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- python3

# python3-pip package is not available, use 'easy_install3':
# * https://github.com/travis-ci/apt-package-whitelist/issues/768
- python3-setuptools # easy_install3

# https://github.com/travis-ci-tester/travis-test-clang-cxx-11
- libstdc++-4.8-dev

# https://github.com/travis-ci-tester/travis-test-gcc-cxx-11
- g++-4.8

# For Qt
- libegl1-mesa-dev

# Packages for Android development: http://superuser.com/a/360398/252568
- libncurses5:i386
- libstdc++6:i386
- zlib1g:i386

matrix:
include:
# Linux {
- os: linux
env: CONFIG=Release TOOLCHAIN=gcc-4-8-pic-hid-sections HAS_CPP14=OFF
- os: linux
env: CONFIG=Debug TOOLCHAIN=gcc-4-8-pic-hid-sections HAS_CPP14=OFF
- os: linux
env: CONFIG=Release TOOLCHAIN=android-ndk-r10e-api-19-armeabi-v7a-neon-hid-sections HAS_CPP14=OFF
- os: linux
env: CONFIG=Debug TOOLCHAIN=android-ndk-r10e-api-19-armeabi-v7a-neon-hid-sections HAS_CPP14=OFF
# }

# OSX {
- os: osx
env: CONFIG=Release TOOLCHAIN=osx-10-11-hid-sections HAS_CPP14=OFF
- os: osx
env: CONFIG=Debug TOOLCHAIN=osx-10-11-hid-sections HAS_CPP14=OFF
- os: osx
env: CONFIG=Release TOOLCHAIN=ios-nocodesign-9-3-device-hid-sections HAS_CPP14=OFF
- os: osx
env: CONFIG=Debug TOOLCHAIN=ios-nocodesign-9-3-device-hid-sections HAS_CPP14=OFF
- os: osx
osx_image: xcode8.1
env: CONFIG=Release TOOLCHAIN=osx-10-12-sanitize-address-hid-sections HAS_CPP14=OFF
- os: osx
osx_image: xcode8.1
env: CONFIG=Debug TOOLCHAIN=osx-10-12-sanitize-address-hid-sections HAS_CPP14=OFF
- os: osx
env: CONFIG=Release TOOLCHAIN=android-ndk-r10e-api-19-armeabi-v7a-neon-hid-sections HAS_CPP14=OFF
- os: osx
env: CONFIG=Debug TOOLCHAIN=android-ndk-r10e-api-19-armeabi-v7a-neon-hid-sections HAS_CPP14=OFF
# }

# disable the default submodule logic to support local modification of .gitmodules paths
git:
submodules: false

install:
# Info about OS
- uname -a

# Install Python 3
- if [[ "`uname`" == "Darwin" ]]; then travis_retry brew install python3; fi

# Install Python package 'requests'
# 'easy_install3' is not installed by 'brew install python3' on OS X 10.9 Maverick
- if [[ "`uname`" == "Darwin" ]]; then pip3 install requests; fi
- if [[ "`uname`" == "Linux" ]]; then travis_retry easy_install3 --user requests==2.10.0; fi

# Install latest Polly toolchains and scripts
- wget https://github.com/ruslo/polly/archive/master.zip
- unzip master.zip
- POLLY_ROOT="`pwd`/polly-master"
- export PATH="${POLLY_ROOT}/bin:${PATH}"

# Install dependencies (CMake, Android NDK)
- install-ci-dependencies.py

# Tune locations
- export PATH="`pwd`/_ci/cmake/bin:${PATH}"

# Installed if toolchain is Android (otherwise directory doesn't exist)
- export ANDROID_NDK_r10e="`pwd`/_ci/android-ndk-r10e"

script:

# '--ios-{multiarch,combined}' do nothing for non-iOS builds
- >
polly.py
--toolchain ${TOOLCHAIN}
--config ${CONFIG}
--verbose
--ios-multiarch --ios-combined
--fwd
THREAD_POOL_CPP_BUILD_TESTS=ON
THREAD_POOL_CPP_HAS_CPP14=${HAS_CPP14}
--test
--jobs 2

branches:
except:
- /^pr\..*/
118 changes: 103 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,23 +1,111 @@
cmake_minimum_required(VERSION 3.0)
cmake_minimum_required(VERSION 3.3) # support visibility settings

list(APPEND CMAKE_MODULE_PATH
"${CMAKE_CURRENT_SOURCE_DIR}/cmake"
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake/Modules")

project(thread-pool-cpp)
add_definitions(-std=c++14 -Wall -Werror -O3)
project(thread-pool-cpp VERSION 1.1.0)

option(THREAD_POOL_CPP_BUILD_TESTS "Build tests." OFF)
option(THREAD_POOL_CPP_BUILD_BENCHMARKS "Build benchmarks." OFF)

# Get all include files
if(THREAD_POOL_CPP_BUILD_TESTS)
include(CTest)
endif()

# Variable used in: benchmark, tests
set(THREAD_POOL_CPP_INC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include/")
include_directories("${THREAD_POOL_CPP_INC_DIR}")
file(GLOB_RECURSE INSTALL_FILES_LIST "${THREAD_POOL_CPP_INC_DIR}/*")

add_subdirectory(tests)
add_subdirectory(benchmark)
# If true C++11 thread_local support exists, we will use it:
include(thread_pool_has_thread_local_storage)
thread_pool_has_thread_local_storage(THREAD_POOL_HAS_THREAD_LOCAL_STORAGE)
message("THREAD_POOL_HAS_THREAD_LOCAL_STORAGE: ${THREAD_POOL_HAS_THREAD_LOCAL_STORAGE}")

if(NOT THREAD_POOL_HAS_THREAD_LOCAL_STORAGE)
# Else, we will check for backups
include(thread_pool_has_thread_storage)
thread_pool_has_thread_storage(THREAD_POOL_HAS_THREAD_STORAGE)
message("THREAD_POOL_HAS_THREAD_STORAGE: ${THREAD_POOL_HAS_THREAD_STORAGE}")
if(NOT THREAD_POOL_HAS_THREAD_STORAGE)
message(FATAL_ERROR "Compiler does not support: thread_local, __thread, or declspec(thread)")
endif()
endif()

# http://stackoverflow.com/a/11583676
add_library(thread-pool-cpp INTERFACE)

option(THREAD_POOL_CPP_HAS_CPP14 "Has true C++14 support." ON)

if(NOT MSVC)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could this work to avoid the explicit branching? https://cmake.org/cmake/help/v3.1/prop_tgt/CXX_STANDARD.html

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure. I will take a look.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could this work to avoid the explicit branching

It looks like this isn't supported for interface libraries: http://stackoverflow.com/q/29687331

"Indeed, it is a deliberate design choice not to support a INTERFACE_CXX_STANDARD target property. See also the CMAKE_CXX_STANDARD variable. "

But the target_compile_features() are.... That may not necessarily help too much.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think something like this might work (and is a little cleaner):

if(THREAD_POOL_HAS_CPP14)
  set(CMAKE_CXX_STANDARD 14)
else()
  set(CMAKE_CXX_STANDARD 11)
endif()

target_compile_features(
  thread-pool-cpp
  INTERFACE
  cxx_auto_type
  cxx_nullptr
  cxx_lambdas
  cxx_lambda_init_captures
  )

if(THREAD_POOL_CPP_HAS_CPP14)
target_compile_definitions(thread-pool-cpp INTERFACE -std=c++14 -Wall -Werror -O3)
else()
target_compile_definitions(thread-pool-cpp INTERFACE -std=c++1y -Wall -Werror -O3)
endif()
else()
if(THREAD_POOL_CPP_HAS_CPP14)
target_compile_definitions(thread-pool-cpp INTERFACE /std:c++14)
else()
target_compile_definitions(thread-pool-cpp INTERFACE /std:c++1y)
endif()
endif()

if(THREAD_POOL_CPP_BUILD_TESTS)
add_subdirectory(tests)
endif()

if(THREAD_POOL_CPP_BUILD_BENCHMARKS)
add_subdirectory(benchmark)
endif()

#### install

set(TARGET_NAME thread-pool-cpp)

set(config_install_dir "lib/cmake/${TARGET_NAME}")
set(include_install_dir "include")

set(generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated")

# Configuration
set(version_config "${generated_dir}/${TARGET_NAME}ConfigVersion.cmake")
set(project_config "${generated_dir}/${TARGET_NAME}Config.cmake")
set(targets_export_name "${TARGET_NAME}Targets")
set(namespace "${TARGET_NAME}::")

include(CMakePackageConfigHelpers)

write_basic_package_version_file(
"${version_config}" COMPATIBILITY SameMajorVersion
)

configure_package_config_file(
"cmake/Config.cmake.in"
"${project_config}"
INSTALL_DESTINATION "${config_install_dir}"
)

install(
TARGETS thread-pool-cpp
EXPORT "${targets_export_name}"
LIBRARY DESTINATION "lib"
ARCHIVE DESTINATION "lib"
RUNTIME DESTINATION "bin"
INCLUDES DESTINATION "${include_install_dir}"
)

install(
DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/thread_pool
DESTINATION "${include_install_dir}"
FILES_MATCHING PATTERN "*.h" PATTERN "*.hpp"
)

install(
FILES "${project_config}" "${version_config}"
DESTINATION "${config_install_dir}"
)

# Install as header-only library
set_source_files_properties(${INSTALL_FILES_LIST} PROPERTIES HEADER_FILE_ONLY 1)
add_library(HEADER_ONLY_TARGET STATIC ${INSTALL_FILES_LIST})
set_target_properties(HEADER_ONLY_TARGET PROPERTIES LINKER_LANGUAGE CXX)
install(DIRECTORY ${THREAD_POOL_CPP_INC_DIR} DESTINATION "include")
install(
EXPORT "${targets_export_name}"
NAMESPACE "${namespace}"
DESTINATION "${config_install_dir}"
)
63 changes: 63 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Lineage: ruslo/hunter tests scripts
# test

os: Visual Studio 2015

environment:

matrix:

- TOOLCHAIN: "vs-14-2015-sdk-8-1"
CONFIG: Release
HAS_CPP14: OFF

- TOOLCHAIN: "vs-14-2015-sdk-8-1"
CONFIG: Debug
HAS_CPP14: OFF

- TOOLCHAIN: "vs-14-2015-win64-sdk-8-1"
CONFIG: Release
HAS_CPP14: OFF

- TOOLCHAIN: "vs-14-2015-win64-sdk-8-1"
CONFIG: Debug
HAS_CPP14: OFF

install:
# Python 3
- cmd: set PATH=C:\Python34-x64;C:\Python34-x64\Scripts;%PATH%

# Install Python package 'requests'
- cmd: pip install requests

# Install latest Polly toolchains and scripts
- cmd: appveyor DownloadFile https://github.com/ruslo/polly/archive/master.zip
- cmd: 7z x master.zip
- cmd: set POLLY_ROOT=%cd%\polly-master

# Install dependencies (CMake, Ninja)
- cmd: python %POLLY_ROOT%\bin\install-ci-dependencies.py

# Tune locations
- cmd: set PATH=%cd%\_ci\cmake\bin;%PATH%
- cmd: set PATH=%cd%\_ci\ninja;%PATH%

# Remove entry with sh.exe from PATH to fix error with MinGW toolchain
# (For MinGW make to work correctly sh.exe must NOT be in your path)
# * http://stackoverflow.com/a/3870338/2288008
- cmd: set PATH=%PATH:C:\Program Files\Git\usr\bin;=%

# Use MinGW from Qt tools because version is higher
# * http://www.appveyor.com/docs/installed-software#qt
- cmd: set MINGW_PATH=C:\Qt\Tools\mingw492_32\bin

# MSYS2 location
- cmd: set MSYS_PATH=C:\msys64\usr\bin

build_script:

- cmd: bin\build-appveyor.cmd "%CONFIG%" "%TOOLCHAIN%" "%HAS_CPP14%"

branches:
except:
- /^pr\..*/
7 changes: 0 additions & 7 deletions benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
#benchmark

include_directories("${THREAD_POOL_CPP_INC_DIR}")

find_package(Boost REQUIRED COMPONENTS system)

include_directories(${CMAKE_CURRENT_SOURCE_DIR})
include_directories(${Boost_INCLUDE_DIR})
add_executable(benchmark benchmark.cpp)
target_link_libraries(benchmark ${Boost_LIBRARIES} pthread)

Loading