diff --git a/CMakeLists.txt b/CMakeLists.txt index ef8e3182..f85ae79e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,63 +4,65 @@ 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) @@ -68,11 +70,50 @@ 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() diff --git a/README.md b/README.md index ac83875a..67c565a4 100644 --- a/README.md +++ b/README.md @@ -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_)`; 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: diff --git a/extras/boost/CMakeLists.txt b/extras/boost/CMakeLists.txt index b5fd8eec..462bf0cb 100644 --- a/extras/boost/CMakeLists.txt +++ b/extras/boost/CMakeLists.txt @@ -4,4 +4,16 @@ target_include_directories(rapidcheck_boost INTERFACE include) if (RC_ENABLE_TESTS) add_subdirectory(test) -endif() \ No newline at end of file +endif() + +install(DIRECTORY "include/" + DESTINATION "${CMAKE_INSTALL_PREFIX}/include" + ) + +if(RC_ENABLE_INSTALL) + + install(DIRECTORY "include/" + DESTINATION "${CMAKE_INSTALL_PREFIX}/include" + ) + +endif() diff --git a/extras/boost_test/CMakeLists.txt b/extras/boost_test/CMakeLists.txt index 1d95a3c6..e5628c2d 100644 --- a/extras/boost_test/CMakeLists.txt +++ b/extras/boost_test/CMakeLists.txt @@ -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() diff --git a/extras/catch/CMakeLists.txt b/extras/catch/CMakeLists.txt index 425b3b32..dc9280db 100644 --- a/extras/catch/CMakeLists.txt +++ b/extras/catch/CMakeLists.txt @@ -1,3 +1,15 @@ add_library(rapidcheck_catch INTERFACE) target_link_libraries(rapidcheck_catch INTERFACE rapidcheck) -target_include_directories(rapidcheck_catch INTERFACE include) \ No newline at end of file +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() diff --git a/extras/gmock/CMakeLists.txt b/extras/gmock/CMakeLists.txt index 9e620010..1f46e343 100644 --- a/extras/gmock/CMakeLists.txt +++ b/extras/gmock/CMakeLists.txt @@ -4,4 +4,12 @@ target_include_directories(rapidcheck_gmock INTERFACE include) if (RC_ENABLE_TESTS) add_subdirectory(test) -endif() \ No newline at end of file +endif() + +if(RC_ENABLE_INSTALL) + +install(DIRECTORY "include/" + DESTINATION "${CMAKE_INSTALL_PREFIX}/include" + ) + +endif() diff --git a/extras/gtest/CMakeLists.txt b/extras/gtest/CMakeLists.txt index ee7b3a3b..0b7550fc 100644 --- a/extras/gtest/CMakeLists.txt +++ b/extras/gtest/CMakeLists.txt @@ -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() diff --git a/rapidcheck-config.cmake.in b/rapidcheck-config.cmake.in new file mode 100644 index 00000000..0901d872 --- /dev/null +++ b/rapidcheck-config.cmake.in @@ -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@")