Skip to content
Open
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
93 changes: 81 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,86 @@
cmake_minimum_required(VERSION 2.8)
cmake_minimum_required(VERSION 3.13)

project(anyoption)
project(anyoption VERSION 1.0.0 LANGUAGES CXX)

set(anyoption_SRCS
anyoption.cpp
)
set(CMAKE_CXX_STANDARD 17)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
include(catch2)

set(anyoption_HDRS
anyoption.h
)
option(WARNING_AS_ERRORS "Treat any warning as compile time error" OFF)
option(STATIC_ANALYZERS "Run static analyzers (clang-tidy, cppcheck) during compilation" ON)
option(CODE_COVERAGE "Enable code coverage reports; requires compilation with clamg/llvm" ON)

include_directories(
.
)
if(WARNING_AS_ERRORS)
set(COMPILE_WARNING_AS_ERROR "-Werror")
endif(WARNING_AS_ERRORS)

add_library(anyoption SHARED ${anyoption_SRCS} ${anyoption_HDRS})
if(STATIC_ANALYZERS)
find_program(CPPCHECK_COMMAND NAMES cppcheck)
set(CMAKE_CXX_CPPCHECK "${CPPCHECK_COMMAND};--quiet;--template=gcc;--suppress=*:*/*_autogen/*")
endif(STATIC_ANALYZERS)

add_library(${PROJECT_NAME})
add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME})

target_include_directories(${PROJECT_NAME}
PUBLIC
src/
)

target_compile_options(${PROJECT_NAME}
PRIVATE
${COMPILE_WARNING_AS_ERROR}
# -Wall
# -Wextra
# -Wshadow
# -Wnon-virtual-dtor
# -pedantic
# -Wold-style-cast
# -Wcast-align
# -Wunused
# -Woverloaded-virtual
# -Wpedantic
# -Wconversion
# -Wsign-conversion
# -Wnull-dereference
# -Wdouble-promotion
)

target_sources(${PROJECT_NAME}
PRIVATE
src/anyoption.cpp
src/anyoption.h
)

#-------------------------------------------------------------------------------------------
add_executable(${PROJECT_NAME}-test)

target_sources(${PROJECT_NAME}-test
PRIVATE
tests/test.cpp
)

target_link_libraries(${PROJECT_NAME}-test
PUBLIC
anyoption::anyoption
catch2::catch2
)

if( STATIC_ANALYZERS )
set_target_properties(${PROJECT_NAME}-test PROPERTIES CXX_CPPCHECK "")
endif(STATIC_ANALYZERS)

add_test(${PROJECT_NAME}-test ${PROJECT_NAME}-test)

#-------------------------------------------------------------------------------------------
add_executable(${PROJECT_NAME}-demo)

target_sources(${PROJECT_NAME}-demo
PRIVATE
demo/demo.cpp
)

target_link_libraries(${PROJECT_NAME}-demo
PUBLIC
anyoption::anyoption
)
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ platform: x64
build_script:
- curl -fsSL -o catch.hpp https://github.com/catchorg/Catch2/releases/download/v2.2.3/catch.hpp
- call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat"
- cmd: cl /EHsc /W4 test.cpp anyoption.cpp
- cmd: cl /EHsc /W4 tests\test.cpp anyoption.cpp
- cmd: test.exe
25 changes: 25 additions & 0 deletions cmake/catch2.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
cmake_minimum_required(VERSION 3.13)

include(ExternalProject)

set(repo_catch2 "https://github.com/catchorg/Catch2.git")
message(STATUS "Repository for catch2: ${repo_catch2}")

ExternalProject_add(extern-catch2
PREFIX ${CMAKE_BINARY_DIR}/catch2
GIT_REPOSITORY ${repo_catch2}
TIMEOUT 10
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
LOG_DOWNLOAD ON
BUILD_BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/catch2/lib/${CMAKE_STATIC_LIBRARY_PREFIX}catch2${CMAKE_STATIC_LIBRARY_SUFFIX}
)

ExternalProject_Get_Property(extern-catch2 source_dir)
add_library(catch INTERFACE)
add_library(catch2::catch2 ALIAS catch)

target_include_directories(catch INTERFACE ${source_dir}/single_include)

add_dependencies(catch extern-catch2)
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion test.cpp → tests/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*
*/
#include "anyoption.h"
#include "catch.hpp"
#include "catch2/catch.hpp"

#include <fstream>
#include <stdarg.h>
Expand Down
2 changes: 1 addition & 1 deletion test.sh → tests/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

cppcheck --error-exitcode=1 --enable=warning,performance,information,style *.cpp *.h
wget -q https://github.com/catchorg/Catch2/releases/download/v2.2.3/catch.hpp
g++ -g -o0 -coverage -std=c++11 -Wall -Wextra -Werror test.cpp anyoption.cpp -o test
g++ -g -o0 -coverage -std=c++11 -Wall -Wextra -Werror tests/test.cpp src/anyoption.cpp -o test
valgrind --error-exitcode=1 --leak-check=full --show-leak-kinds=all ./test
lcov --directory . --capture --output-file coverage.info
lcov --remove coverage.info 'catch.hpp' '/usr/*' --output-file coverage.info
Expand Down