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

Added system installation configuration #124

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
139 changes: 90 additions & 49 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,75 +4,116 @@ enable_testing()

option(RC_ENABLE_TESTS "Build RapidCheck tests" OFF)
option(RC_ENABLE_EXAMPLES "Build RapidCheck examples" OFF)
option(RC_ENABLE_INSTALL "Install RadpidCheck and extras" OFF)


if(MSVC)
# /bigobj - some object files become very large so we need this
# /wd4503 - truncation of decorated name, not much we can do about it so
# disable it
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj /wd4503 /WX")
# /RTC* is incompatible with /O2 needed for Random.cpp to speed it up
string(REGEX REPLACE "/RTC(su|[1su])" ""
CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
# /bigobj - some object files become very large so we need this
# /wd4503 - truncation of decorated name, not much we can do about it so
# disable it
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj /wd4503 /WX")
# /RTC* is incompatible with /O2 needed for Random.cpp to speed it up
string(REGEX REPLACE "/RTC(su|[1su])" ""
CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -Wno-missing-braces -std=c++11")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -Wno-missing-braces -std=c++11")
endif()

add_library(rapidcheck
src/BeforeMinimalTestCase.cpp
src/Check.cpp
src/Classify.cpp
src/GenerationFailure.cpp
src/Log.cpp
src/Random.cpp
src/Show.cpp
src/detail/Any.cpp
src/detail/Assertions.cpp
src/detail/Base64.cpp
src/detail/Configuration.cpp
src/detail/DefaultTestListener.cpp
src/detail/FrequencyMap.cpp
src/detail/ImplicitParam.cpp
src/detail/LogTestListener.cpp
src/detail/MapParser.cpp
src/detail/MulticastTestListener.cpp
src/detail/ParseException.cpp
src/detail/Platform.cpp
src/detail/Property.cpp
src/detail/PropertyContext.cpp
src/detail/ReproduceListener.cpp
src/detail/Results.cpp
src/detail/Serialization.cpp
src/detail/StringSerialization.cpp
src/detail/TestMetadata.cpp
src/detail/TestParams.cpp
src/detail/Testing.cpp
src/gen/Numeric.cpp
src/gen/Text.cpp
src/gen/detail/ExecHandler.cpp
src/gen/detail/GenerationHandler.cpp
src/gen/detail/Recipe.cpp
src/gen/detail/ScaleInteger.cpp
)
src/BeforeMinimalTestCase.cpp
src/Check.cpp
src/Classify.cpp
src/GenerationFailure.cpp
src/Log.cpp
src/Random.cpp
src/Show.cpp
src/detail/Any.cpp
src/detail/Assertions.cpp
src/detail/Base64.cpp
src/detail/Configuration.cpp
src/detail/DefaultTestListener.cpp
src/detail/FrequencyMap.cpp
src/detail/ImplicitParam.cpp
src/detail/LogTestListener.cpp
src/detail/MapParser.cpp
src/detail/MulticastTestListener.cpp
src/detail/ParseException.cpp
src/detail/Platform.cpp
src/detail/Property.cpp
src/detail/PropertyContext.cpp
src/detail/ReproduceListener.cpp
src/detail/Results.cpp
src/detail/Serialization.cpp
src/detail/StringSerialization.cpp
src/detail/TestMetadata.cpp
src/detail/TestParams.cpp
src/detail/Testing.cpp
src/gen/Numeric.cpp
src/gen/Text.cpp
src/gen/detail/ExecHandler.cpp
src/gen/detail/GenerationHandler.cpp
src/gen/detail/Recipe.cpp
src/gen/detail/ScaleInteger.cpp
)

# Random is used a LOT so it should preferrably be really fast.
if(MSVC)
set_property(SOURCE src/Random.cpp
APPEND_STRING PROPERTY COMPILE_FLAGS " /O2")
set_property(SOURCE src/Random.cpp
APPEND_STRING PROPERTY COMPILE_FLAGS " /O2")
else()
set_property(SOURCE src/Random.cpp
APPEND_STRING PROPERTY COMPILE_FLAGS " -O3")
set_property(SOURCE src/Random.cpp
APPEND_STRING PROPERTY COMPILE_FLAGS " -O3")
endif()

target_include_directories(rapidcheck PUBLIC include)

add_subdirectory(ext)

if (RC_ENABLE_TESTS)
add_subdirectory(test)
add_subdirectory(test)
endif()

if (RC_ENABLE_EXAMPLES)
add_subdirectory(examples)
add_subdirectory(examples)
endif()

add_subdirectory(extras)

if(RC_ENABLE_INSTALL)

set(cmake_config_files
"rapidcheck-config.cmake"
)

# install the targets and include directories
install(TARGETS rapidcheck
ARCHIVE DESTINATION "${CMAKE_INSTALL_PREFIX}/lib"
)

install(DIRECTORY "include/"
DESTINATION "${CMAKE_INSTALL_PREFIX}/include"
)

# setup the cmake config files
# the include directories to export in our cmake config file
set(CONFIG_INCLUDE_DIRS
"${CMAKE_INSTALL_PREFIX}/include"
)

# The libraries to export in our cmake config file
set(CONFIG_LIBRARIES "rapidcheck")

# generate the cmake config files
foreach(f ${cmake_config_files})
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/${f}.in"
"${PROJECT_BINARY_DIR}/${f}"
@ONLY
)

install(
FILES "${PROJECT_BINARY_DIR}/${f}"
DESTINATION "lib/cmake/rapidcheck"
)
endforeach()

endif()
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ RapidCheck uses CMake and is built like any other CMake project. If your own pro

This will give you both linking and include directories.

### System Installation
You can now install rapidcheck on your system. Simply add `-DRC_ENABLE_INSTALL=ON` when you run `cmake` to build the project. This will install all the include directories (include the extras - if they are enabled) and the static library that is built.

When using the system install version with another CMake project you won't need to use `find_package(rapidcheck_<extra>)`; just make sure that the extra was enabled when you were running cmake to build the project.

## Quick introduction ##
A common first example is testing a reversal function. For such a function, double reversal should always result in the original list. In this example we will use the standard C++ `std::reverse` function:

Expand Down
14 changes: 13 additions & 1 deletion extras/boost/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,16 @@ target_include_directories(rapidcheck_boost INTERFACE include)

if (RC_ENABLE_TESTS)
add_subdirectory(test)
endif()
endif()

install(DIRECTORY "include/"
DESTINATION "${CMAKE_INSTALL_PREFIX}/include"
)

if(RC_ENABLE_INSTALL)

install(DIRECTORY "include/"
DESTINATION "${CMAKE_INSTALL_PREFIX}/include"
)

endif()
12 changes: 12 additions & 0 deletions extras/boost_test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
add_library(rapidcheck_boost_test INTERFACE)
target_link_libraries(rapidcheck_boost_test INTERFACE rapidcheck)
target_include_directories(rapidcheck_boost_test INTERFACE include)

install(DIRECTORY "include/"
DESTINATION "${CMAKE_INSTALL_PREFIX}/include"
)

if(RC_ENABLE_INSTALL)

install(DIRECTORY "include/"
DESTINATION "${CMAKE_INSTALL_PREFIX}/include"
)

endif()
14 changes: 13 additions & 1 deletion extras/catch/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
add_library(rapidcheck_catch INTERFACE)
target_link_libraries(rapidcheck_catch INTERFACE rapidcheck)
target_include_directories(rapidcheck_catch INTERFACE include)
target_include_directories(rapidcheck_catch INTERFACE include)

install(DIRECTORY "include/"
DESTINATION "${CMAKE_INSTALL_PREFIX}/include"
)

if(RC_ENABLE_INSTALL)

install(DIRECTORY "include/"
DESTINATION "${CMAKE_INSTALL_PREFIX}/include"
)

endif()
10 changes: 9 additions & 1 deletion extras/gmock/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,12 @@ target_include_directories(rapidcheck_gmock INTERFACE include)

if (RC_ENABLE_TESTS)
add_subdirectory(test)
endif()
endif()

if(RC_ENABLE_INSTALL)

install(DIRECTORY "include/"
DESTINATION "${CMAKE_INSTALL_PREFIX}/include"
)

endif()
12 changes: 12 additions & 0 deletions extras/gtest/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
add_library(rapidcheck_gtest INTERFACE)
target_link_libraries(rapidcheck_gtest INTERFACE rapidcheck)
target_include_directories(rapidcheck_gtest INTERFACE include)

install(DIRECTORY "include/"
DESTINATION "${CMAKE_INSTALL_PREFIX}/include"
)

if(RC_ENABLE_INSTALL)

install(DIRECTORY "include/"
DESTINATION "${CMAKE_INSTALL_PREFIX}/include"
)

endif()
7 changes: 7 additions & 0 deletions rapidcheck-config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#When run this file will define the following CMake cached variables:
#
# rapidcheck_INCLUDE_DIRS
# rapidcheck_LIBRARIES
#
set(rapidcheck_INCLUDE_DIRS "@CONFIG_INCLUDE_DIRS@")
set(rapidcheck_LIBRARIES "@CONFIG_LIBRARIES@")