Skip to content
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ compile_commands.json
CTestTestfile.cmake

# layout
.scannerwork
doxyfile
*.tar
sonar-project.properties
Expand Down
54 changes: 54 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# autho: Herbert Koelman
# created on: 1/6/2019
os: linux

# use Ubuntu Xenial (version 16)
# This comes with cmake 3.11 which is required to build GoogleTest
dist: xenial
language: cpp
compiler: gcc

env:
CODECOV_TOKEN="73b7985a-7b2d-40fa-a025-65906959f9c2"

# Run travis on these branches only...
branches:
only:
- master
- develop

addons:
sonarcloud:
organization: "herbertkoelman-github"

apt:
packages:
- doxygen
- graphviz

matrix:
include:
- name: coverage jobs
env:
BUILD_DIRECTORY=cmake-gcov-build
CMAKE_COMMAND_LINE_ARGS="-DGCOV=yes"
MAKE_TARGETS="all test"
- name: sonar code quality checks
env:
BUILD_DIRECTORY=cmake-sonar-build
CMAKE_COMMAND_LINE_ARGS="-DSONAR=yes"
MAKE_TARGETS="all test code-quality"
- name: default
env:
BUILD_DIRECTORY=cmake-default-build
CMAKE_COMMAND_LINE_ARGS="-DCMAKE_BUILD_TYPE=Release"
MAKE_TARGETS="all doxygen package"

script:
- mkdir $BUILD_DIRECTORY && cd $BUILD_DIRECTORY && cmake $CMAKE_COMMAND_LINE_ARGS .. && make $MAKE_TARGETS

after_success:
# create gcov files
- find ./CMakeFiles/ -type f -name "*.gcno" -exec gcov {} -m \;
# upload data to codecav
- bash <(curl -s https://codecov.io/bash)
47 changes: 28 additions & 19 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,24 @@ project(
DESCRIPTION "Simple C++ wrapper to pthread functions (${GIT_LOG})")

option(BUILD_TESTS "enable/disable tests (default is enabled)" ON)
set(CMAKE_CXX_STANDARD 11)
option(GCOV "Activate GCOV options")

configure_file(src/config.h.in ${CMAKE_CURRENT_SOURCE_DIR}/src/config.h)
if ( GCOV )
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
message(STATUS "Setting GCOV compiler options")
add_compile_options(--coverage)
else()
message(SEND_ERROR "The GCOV option is only supported when using GNU...")
endif()
endif()

find_package(GTestExt PATHS cmake)

# this works because we've extended CMAKE_MODULE_PATH
# uncomment if you have a conanfile.txt and run 'conan install ...' include(conan_paths)
#find_package(Git CONFIG)
#find_package(Conan)
# This part MUST be executed before the loading of the CMake package
set(SONAR_PROPERTIES_FILE ${CMAKE_CURRENT_BINARY_DIR}/sonar-project.properties)
message(STATUS "Generating SONAR properties file ${SONAR_PROPERTIES_FILE}")
configure_file(${CMAKE_CURRENT_LIST_DIR}/sonar-project.properties.in ${SONAR_PROPERTIES_FILE})
find_package(SonarCloud PATHS cmake)

# main targets --------------------------------------------------
#
Expand All @@ -35,6 +45,8 @@ else()
endif()
endif()

configure_file(src/config.h.in ${CMAKE_CURRENT_SOURCE_DIR}/src/config.h)

# project's public headers
include_directories(include src)

Expand All @@ -48,6 +60,9 @@ set(PTHREAD_SOURCE_CODE
src/thread.cpp
src/mutex.cpp
)

set(CMAKE_CXX_STANDARD 11)

add_library(cpp-pthread-static STATIC ${PTHREAD_SOURCE_CODE})
target_link_libraries(cpp-pthread-static pthread)
set_target_properties(cpp-pthread-static PROPERTIES OUTPUT_NAME cpp-pthread)
Expand All @@ -60,23 +75,21 @@ set_target_properties(cpp-pthread-shared PROPERTIES OUTPUT_NAME cpp-pthread)
# Testing -------------------------------------------------------
#

# Load and compile GTest
# Aliases: GTest::GTest, GTest::gtest_main, GMock::GMock
find_package(GTest PATHS cmake)
if (GTest_FOUND)
if (GTestExt_FOUND AND BUILD_TESTS)
enable_testing()
message(STATUS "Adding project's unit tests (in ./tests)...")
add_subdirectory(tests)
endif()

# doxygen -------------------------------------------------------
#
find_package(Doxygen REQUIRED dot OPTIONAL_COMPONENTS mscgen dia)
if (Doxygen_FOUND)
# set(DOXYGEN_OUTPUT_DIRECTORY doxygen)
# set(DOXYGEN_GENERATE_MAN YES)
# set(DOXYGEN_GENERATE_HTML YES)

set(DOXYGEN_PROJECT_NUMBER ${CPP_PTHREAD_VERSION})
set(DOXYGEN_EXAMPLE_PATH tests)
set(DOXYGEN_PROJECT_BRIEF "Simple C++ wrapper to pthread functions.")
set(DOXYGEN_EXTRACT_ALL yes)
set(DOXYGEN_PROJECT_BRIEF ${PROJECT_DESCRIPTION})
set(DOXYGEN_USE_MDFILE_AS_MAINPAGE "${CMAKE_SOURCE_DIR}/README.md")
doxygen_add_docs(doxygen README.md src include COMMENT "generate on-line documentation")

Expand All @@ -86,7 +99,7 @@ endif()
#
install( TARGETS cpp-pthread-static cpp-pthread-shared DESTINATION lib )
install( DIRECTORY include DESTINATION include COMPONENT Devel)
# install( DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html DESTINATION share/doc)
install( DIRECTORY ${PROJECT_BINARY_DIR}/html/ DESTINATION doc/cpp-pthread COMPONENT Documentation)

# CPACK ---------------------------------------------------------
#
Expand All @@ -99,7 +112,3 @@ set(CPACK_PACKAGE_VENDOR "Urbix Software")
set(CPACK_PACKAGING_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX})

include(CPack)

# misc ------------------------------------------------------------
#
find_program(RM rm)
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
### What it does

[![Build Status](https://travis-ci.com/HerbertKoelman/cpp-pthread.svg?branch=master)](https://travis-ci.com/HerbertKoelman/cpp-pthread)

Some C/C++ compilers are not implementing all of C++11 and above standard, it's often lacking the concurrency features that the standard brings. These compilers will at some point be updated. I was therefore looking for a way to reduce the effort of switching from a specific implementation to the C++11 standard one.

This projetc is the resulting code.
Expand Down
46 changes: 0 additions & 46 deletions cmake/GTestConfig.cmake

This file was deleted.

56 changes: 56 additions & 0 deletions cmake/GTestExtConfig.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
set(BUILD_TESTS True CACHE BOOL "if set, then GoogleTest is download and built.")

if (BUILD_TESTS)
message(STATUS "Download and build Google Test (GTest)...")

set(__GTEST_DOWNLOAD ${CMAKE_BINARY_DIR}/googletest-download)
file(MAKE_DIRECTORY ${__GTEST_DOWNLOAD})
if (EXISTS ${__GTEST_DOWNLOAD})

option(INSTALL_GMOCK "Install Googletest's GMock?" OFF)
option(INSTALL_GTEST "Install Googletest's GTest?" OFF)

message(STATUS "Generating GoogleTest CMakeLists.txt")
configure_file(${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt.in ${__GTEST_DOWNLOAD}/CMakeLists.txt)

message(STATUS "Setup build for GoogleTest")
execute_process(COMMAND "${CMAKE_COMMAND}" -G "${CMAKE_GENERATOR}" .
WORKING_DIRECTORY "${__GTEST_DOWNLOAD}" )

message(STATUS "Building GoogleTest")
execute_process(COMMAND "${CMAKE_COMMAND}" --build .
WORKING_DIRECTORY "${__GTEST_DOWNLOAD}" )

# Prevent GoogleTest from overriding our compiler/linker options
# when building with Visual Studio
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)

# Add googletest directly to our build. This adds
# the following targets: gtest, gtest_main, gmock
# and gmock_main
add_subdirectory("${CMAKE_BINARY_DIR}/googletest-src"
"${CMAKE_BINARY_DIR}/googletest-build")

# The gtest/gmock targets carry header search path
# dependencies automatically when using CMake 2.8.11 or
# later. Otherwise we have to add them here ourselves.
if(CMAKE_VERSION VERSION_LESS 2.8.11)
message(STATUS "GoogleTest include directory ${gtest_SOURCE_DIR}/include ${gmock_SOURCE_DIR}/include)")
include_directories("${gtest_SOURCE_DIR}/include"
"${gmock_SOURCE_DIR}/include")
endif()

add_library(GTest::GTest ALIAS gtest)
add_library(GTest::gtest_main ALIAS gtest_main)

add_library(GMock::GMock ALIAS gmock)
add_library(GMock::gmock_main ALIAS gmock_main)

message(STATUS "Defined GoogleTest aliases: GTest::GTest, GTest::gtest_main, GMock::GMock")

else()
message(STATUS "Failed to create GoogleTest download directory. Make sure you have Internet access or use -DBUILD_TESTS=off")
endif()
else()
message(STATUS "Disabled unit testing (BUILD_TESTS is ${BUILD_TESTS})")
endif()
65 changes: 65 additions & 0 deletions cmake/SonarCloudConfig.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
message(STATUS "Loading SonarCloud module found here: ${CMAKE_CURRENT_LIST_DIR}")

option(SONAR "Generate sonar setup" ) # default is OFF

set(SONAR_CLOUD_HOME https://sonarcloud.io CACHE STRING "Sonar cloud home URL(default is https://sonarcloud.io)")
set(SONAR_PROJECT_KEY ${PROJECT_NAME} CACHE STRING "Sonar project key property (default is ${PROJECT_NAME})")
set(SONAR_ORGANIZATION CACHE STRING "Organization (default is empty)")
set(SONAR_ACCESS_TOKEN CACHE STRING "Access/login token (default is empty)")

set(SONAR_WRAPPER_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/bw-output CACHE STRING "Sonar C/C++ wrapper output directory (default is bw-output)")

set(SONAR_PROPERTIES_FILE ${SONAR_PROPERTIES_FILE} CACHE STRING "If file exists, it will used as is (default is empty)")

if ( SONAR )

find_program(SONAR_SCANNER sonar-scanner)

if ( SONAR_SCANNER )

if(NOT EXISTS ${SONAR_PROPERTIES_FILE} )
message(STATUS "Generating SONAR properties file (${CMAKE_CURRENT_BINARY_DIR}/sonar-project.properties)")
configure_file(${CMAKE_CURRENT_LIST_DIR}/sonar-project.properties.in sonar-project.properties)
set(SONAR_PROPERTIES_FILE ./sonar-project.properties)
else()
message(STATUS "Sonar scanner property file was provided (${SONAR_PROPERTIES_FILE})")
endif()

add_custom_target( code-quality
COMMAND ${SONAR_SCANNER} -Dproject.settings=${SONAR_PROPERTIES_FILE}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "run ${SONAR_SCANNER} -Dproject.settings=${SONAR_PROPERTIES_FILE} "
)
message(STATUS "Added custom target [code-quality]...")

find_program(SONAR_BUILD_WRAPPER build-wrapper-linux-x86-64)
if ( SONAR_BUILD_WRAPPER )
add_custom_target( build-wrapper
COMMAND ${SONAR_BUILD_WRAPPER} --out-dir ${SONAR_WRAPPER_OUTPUT_DIR} make clean all
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "run SONAR's ${SONAR_BUILD_WRAPPER}"
)
message(STATUS "Added custom target [build-wrapper]...")
add_dependencies(code-quality build-wrapper)
endif()

find_program(SONAR_GCOV gcov)
if(SONAR_GCOV)
add_custom_target( sonar-gcov-report
COMMAND find ./CMakeFiles/ -type f -name "*.gcno" -exec ${SONAR_GCOV} {} -m \; > /dev/null 2>&1
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Built sonar GCOV report (${SONAR_GCOV})"
VERBATIM
)
message(STATUS "Added custom target [sonar-gcov-report]...")
add_dependencies(code-quality sonar-gcov-report)
endif()

else()
message(SEND_ERROR "Failed to find the program [sonar_scanner], make sure sonar tools are installed.")
endif()

#else()
# message(WARNING "SONAR cloud build is turned off, use -DSONAR=yes to turn in ON")
endif()

12 changes: 12 additions & 0 deletions cmake/sonar-project.properties.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Project Configuration @PROJECT_NAME@ version @PROJECT_VERSION@
sonar.verbose=false
sonar.projectBaseDir=@CMAKE_SOURCE_DIR@
sonar.projectKey=@SONAR_PROJECT_KEY@
sonar.organization=@SONAR_ORGANIZATION@
sonar.links.homepage=@SONAR_PROJECT_HOME@
sonar.host.url=@SONAR_CLOUD_HOME@
sonar.login=@SONAR_ACCESS_TOKEN@
sonar.cfamily.build-wrapper-output=@SONAR_WRAPPER_OUTPUT_DIR@
sonar.projectName=@PROJECT_NAME@
sonar.projectVersion=@PROJECT_VERSION@
sonar.sources=src,include
Loading