From 8ae1c971ea833fed0640dd87abdeb3374ce890e7 Mon Sep 17 00:00:00 2001 From: Andriy Senkovych Date: Tue, 4 Nov 2014 00:36:24 +0200 Subject: [PATCH 01/10] Add initial CMake support * Support for both in-source and out-of-source builds * Set library version to 0.12 to map Debian package * Add separate options to build tests, examples and documentation * Add pkgconfig lookup support (if installed with `make install`) * Add CMake lookup support (if isntalled with `make install`) * Add Google Test Source lookup * Add CTest support for running tests (use `make test` or `ctest -V`) --- CMakeLists.txt | 85 +++++++++++++++++++++++++++++++ CMakeModules/FindGTestSrc.cmake | 22 ++++++++ RapidJSON.pc.in | 4 ++ RapidJSONConfig.cmake.in | 3 ++ RapidJSONConfigVersion.cmake.in | 10 ++++ doc/CMakeLists.txt | 23 +++++++++ build/Doxyfile => doc/Doxyfile.in | 2 +- example/CMakeLists.txt | 19 +++++++ test/CMakeLists.txt | 17 +++++++ test/perftest/CMakeLists.txt | 11 ++++ test/unittest/CMakeLists.txt | 17 +++++++ 11 files changed, 212 insertions(+), 1 deletion(-) create mode 100644 CMakeLists.txt create mode 100644 CMakeModules/FindGTestSrc.cmake create mode 100644 RapidJSON.pc.in create mode 100644 RapidJSONConfig.cmake.in create mode 100644 RapidJSONConfigVersion.cmake.in create mode 100644 doc/CMakeLists.txt rename build/Doxyfile => doc/Doxyfile.in (99%) create mode 100644 example/CMakeLists.txt create mode 100644 test/CMakeLists.txt create mode 100644 test/perftest/CMakeLists.txt create mode 100644 test/unittest/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 000000000..b7a4961b8 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,85 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.8.11) +SET(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/CMakeModules) + +PROJECT(RapidJSON CXX) + +set(LIB_MAJOR_VERSION "0") +set(LIB_MINOR_VERSION "12") +set(LIB_PATCH_VERSION "0") +set(LIB_VERSION_STRING "${LIB_MAJOR_VERSION}.${LIB_MINOR_VERSION}.${LIB_PATCH_VERSION}") + +# compile in release with debug info mode by default +SET(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Build Type") + +option(RAPIDJSON_BUILD_DOC "Build rapidjson documentation." ON) +option(RAPIDJSON_BUILD_EXAMPLES "Build rapidjson examples." ON) +option(RAPIDJSON_BUILD_TESTS "Build rapidjson perftests and unittests." ON) + +#add extra search paths for libraries and includes +SET(INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/include" CACHE PATH "The directory the headers are installed in") +SET(LIB_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/lib" CACHE STRING "Directory where lib will install") +SET(DOC_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/share/doc/${PROJECT_NAME}" CACHE PATH "Path to the documentation") + +IF(UNIX OR CYGWIN) + SET(_CMAKE_INSTALL_DIR "${LIB_INSTALL_DIR}/cmake/${PROJECT_NAME}") +ELSEIF(WIN32) + SET(_CMAKE_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/cmake") +ENDIF() +SET(CMAKE_INSTALL_DIR "${_CMAKE_INSTALL_DIR}" CACHE PATH "The directory cmake fiels are installed in") + + +include_directories(${CMAKE_SOURCE_DIR}/include) +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${RAPIDJSON_CXX_FLAGS}") + +if(RAPIDJSON_BUILD_DOC) + add_subdirectory(doc) +endif() + +if(RAPIDJSON_BUILD_EXAMPLES) + add_subdirectory(example) +endif() + +if(RAPIDJSON_BUILD_TESTS) + add_subdirectory(test) + include(CTest) +endif() + +# pkg-config +IF (UNIX OR CYGWIN) + CONFIGURE_FILE (${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.pc.in + ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc + @ONLY) + INSTALL (FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc + DESTINATION "${LIB_INSTALL_DIR}/pkgconfig" + COMPONENT pkgconfig) +ENDIF() + +install(FILES readme.md + DESTINATION "${DOC_INSTALL_DIR}" + COMPONENT doc) + +install(DIRECTORY include/rapidjson + DESTINATION "${INCLUDE_INSTALL_DIR}" + COMPONENT dev) + +install(DIRECTORY example/ + DESTINATION "${DOC_INSTALL_DIR}/examples" + COMPONENT examples) + +# Provide config and version files to be used by other applications +# =============================== + +export(PACKAGE ${PROJECT_NAME}) + +# cmake-modules +CONFIGURE_FILE(${PROJECT_NAME}Config.cmake.in + ${PROJECT_NAME}Config.cmake + @ONLY) +CONFIGURE_FILE(${PROJECT_NAME}ConfigVersion.cmake.in + ${PROJECT_NAME}ConfigVersion.cmake + @ONLY) +INSTALL(FILES + ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake + ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake + DESTINATION "${CMAKE_INSTALL_DIR}" + COMPONENT dev) diff --git a/CMakeModules/FindGTestSrc.cmake b/CMakeModules/FindGTestSrc.cmake new file mode 100644 index 000000000..89f132e5a --- /dev/null +++ b/CMakeModules/FindGTestSrc.cmake @@ -0,0 +1,22 @@ +SET(GTEST_SEARCH_PATH + "${GTEST_SOURCE_DIR}" + "${CMAKE_SOURCE_DIR}/thirdparty/gtest") + +IF(UNIX) + LIST(INSERT GTEST_SEARCH_PATH 1 "/usr/src/gtest") +ENDIF() + +FIND_PATH(GTEST_SOURCE_DIR + NAMES CMakeLists.txt src/gtest_main.cc + PATHS ${GTEST_SEARCH_PATH}) + +# Debian installs gtest include directory in /usr/include, thus need to look +# for include directory separately from source directory. +FIND_PATH(GTEST_INCLUDE_DIR + NAMES gtest/gtest.h + PATH_SUFFIXES include + PATHS ${GTEST_SEARCH_PATH}) + +find_package_handle_standard_args(GTestSrc DEFAULT_MSG + GTEST_SOURCE_DIR + GTEST_INCLUDE_DIR) diff --git a/RapidJSON.pc.in b/RapidJSON.pc.in new file mode 100644 index 000000000..be4f7887a --- /dev/null +++ b/RapidJSON.pc.in @@ -0,0 +1,4 @@ +Name: @PROJECT_NAME@ +Description: RapidJSON is a JSON parser and generator for C++ inspired by RapidXml. +Version: @LIB_VERSION_STRING@ +Cflags: -I${includedir} diff --git a/RapidJSONConfig.cmake.in b/RapidJSONConfig.cmake.in new file mode 100644 index 000000000..9fa12186a --- /dev/null +++ b/RapidJSONConfig.cmake.in @@ -0,0 +1,3 @@ +get_filename_component(RAPIDJSON_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) +set(RAPIDJSON_INCLUDE_DIRS "@INCLUDE_INSTALL_DIR@") +message(STATUS "RapidJSON found. Headers: ${RAPIDJSON_INCLUDE_DIRS}") diff --git a/RapidJSONConfigVersion.cmake.in b/RapidJSONConfigVersion.cmake.in new file mode 100644 index 000000000..25741fc09 --- /dev/null +++ b/RapidJSONConfigVersion.cmake.in @@ -0,0 +1,10 @@ +SET(PACKAGE_VERSION "@LIB_VERSION_STRING@") + +IF (PACKAGE_FIND_VERSION VERSION_EQUAL PACKAGE_VERSION) + SET(PACKAGE_VERSION_EXACT "true") +ENDIF (PACKAGE_FIND_VERSION VERSION_EQUAL PACKAGE_VERSION) +IF (NOT PACKAGE_FIND_VERSION VERSION_GREATER PACKAGE_VERSION) + SET(PACKAGE_VERSION_COMPATIBLE "true") +ELSE (NOT PACKAGE_FIND_VERSION VERSION_GREATER PACKAGE_VERSION) + SET(PACKAGE_VERSION_UNSUITABLE "true") +ENDIF (NOT PACKAGE_FIND_VERSION VERSION_GREATER PACKAGE_VERSION) diff --git a/doc/CMakeLists.txt b/doc/CMakeLists.txt new file mode 100644 index 000000000..685a00e82 --- /dev/null +++ b/doc/CMakeLists.txt @@ -0,0 +1,23 @@ +find_package(Doxygen) + +IF(NOT DOXYGEN_FOUND) + MESSAGE(STATUS "No Doxygen found. Documentation won't be built") +ELSE() + file(GLOB SOURCES ${CMAKE_SOURCE_DIR}/include/*) + file(GLOB MARKDOWN_DOC ${CMAKE_SOURCE_DIR}/doc/*.md) + list(APPEND MARKDOWN_DOC ${CMAKE_SOURCE_DIR}/readme.md) + + CONFIGURE_FILE(Doxyfile.in Doxyfile @ONLY) + + add_custom_command(OUTPUT html + COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile + COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/html + DEPENDS ${MARKDOWN_DOC} ${SOURCES} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + ) + + add_custom_target(doc ALL DEPENDS html) + install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html + DESTINATION ${DOC_INSTALL_DIR} + COMPONENT doc) +ENDIF() diff --git a/build/Doxyfile b/doc/Doxyfile.in similarity index 99% rename from build/Doxyfile rename to doc/Doxyfile.in index d2a03bedd..d11a02fca 100644 --- a/build/Doxyfile +++ b/doc/Doxyfile.in @@ -58,7 +58,7 @@ PROJECT_LOGO = # entered, it will be relative to the location where doxygen was started. If # left blank the current directory will be used. -OUTPUT_DIRECTORY = ./doc +OUTPUT_DIRECTORY = @CMAKE_CURRENT_BINARY_DIR@ # If the CREATE_SUBDIRS tag is set to YES, then doxygen will create 4096 sub- # directories (in 2 levels) under the output directory of each output format and diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt new file mode 100644 index 000000000..cd355b424 --- /dev/null +++ b/example/CMakeLists.txt @@ -0,0 +1,19 @@ +# Copyright (c) 2011 Milo Yip (miloyip@gmail.com) +# Copyright (c) 2013 Rafal Jeczalik (rjeczalik@gmail.com) +# Distributed under the MIT License (see license.txt file) + +set(EXAMPLES + capitalize + condense + messagereader + pretty + prettyauto + serialize + simpledom + simplereader + simplewriter + tutorial) + +foreach (example ${EXAMPLES}) + add_executable(${example}_ ${example}/${example}.cpp) +endforeach() diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 000000000..92d43094b --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,17 @@ +find_package(GTestSrc) + +IF(GTESTSRC_FOUND) + enable_testing() + + if (WIN32 AND (NOT CYGWIN) AND (NOT MINGW)) + set(gtest_disable_pthreads ON) + endif() + + add_subdirectory(${GTEST_SOURCE_DIR} ${CMAKE_BINARY_DIR}/googletest) + include_directories(${GTEST_INCLUDE_DIR}) + + set(TEST_LIBRARIES gtest gtest_main) + + add_subdirectory(perftest) + add_subdirectory(unittest) +ENDIF(GTESTSRC_FOUND) diff --git a/test/perftest/CMakeLists.txt b/test/perftest/CMakeLists.txt new file mode 100644 index 000000000..35895670e --- /dev/null +++ b/test/perftest/CMakeLists.txt @@ -0,0 +1,11 @@ +set(PERFTEST_SOURCES + misctest.cpp + perftest.cpp + platformtest.cpp + rapidjsontest.cpp) + +add_executable(perftest ${PERFTEST_SOURCES}) +target_link_libraries(perftest ${TEST_LIBRARIES}) +add_test(NAME perftest + COMMAND ${CMAKE_CURRENT_BINARY_DIR}/perftest + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/bin) diff --git a/test/unittest/CMakeLists.txt b/test/unittest/CMakeLists.txt new file mode 100644 index 000000000..fa687e768 --- /dev/null +++ b/test/unittest/CMakeLists.txt @@ -0,0 +1,17 @@ +set(UNITTEST_SOURCES + documenttest.cpp + encodedstreamtest.cpp + encodingstest.cpp + filestreamtest.cpp + jsoncheckertest.cpp + readertest.cpp + unittest.cpp + unittest.h + valuetest.cpp + writertest.cpp) + +add_executable(unittest ${UNITTEST_SOURCES}) +target_link_libraries(unittest ${TEST_LIBRARIES}) +add_test(NAME unittest + COMMAND ${CMAKE_CURRENT_BINARY_DIR}/unittest + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/bin) From 5cceb9e37aecda8f8d703cd44cafd94f035b5ff3 Mon Sep 17 00:00:00 2001 From: Andriy Senkovych Date: Tue, 4 Nov 2014 01:17:43 +0200 Subject: [PATCH 02/10] Fix broken references in documentation --- doc/Doxyfile.in | 26 +++++++++++++------------- doc/dom.md | 4 ++-- doc/faq.md | 2 +- doc/tutorial.md | 4 ++-- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/doc/Doxyfile.in b/doc/Doxyfile.in index d11a02fca..69201431a 100644 --- a/doc/Doxyfile.in +++ b/doc/Doxyfile.in @@ -764,18 +764,18 @@ WARN_LOGFILE = # spaces. # Note: If this tag is empty the current directory is searched. -INPUT = ./include/rapidjson/rapidjson.h \ - ./include/ \ - ./readme.md \ - ./doc/features.md \ - ./doc/tutorial.md \ - ./doc/stream.md \ - ./doc/encoding.md \ - ./doc/dom.md \ - ./doc/sax.md \ - ./doc/performance.md \ - ./doc/internals.md \ - ./doc/faq.md +INPUT = readme.md \ + include/rapidjson/rapidjson.h \ + include/ \ + doc/features.md \ + doc/tutorial.md \ + doc/stream.md \ + doc/encoding.md \ + doc/dom.md \ + doc/sax.md \ + doc/performance.md \ + doc/internals.md \ + doc/faq.md # This tag can be used to specify the character encoding of the source files # that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses @@ -920,7 +920,7 @@ FILTER_SOURCE_PATTERNS = # (index.html). This can be useful if you have a project on for instance GitHub # and want to reuse the introduction page also for the doxygen output. -USE_MDFILE_AS_MAINPAGE = ./readme.md +USE_MDFILE_AS_MAINPAGE = readme.md #--------------------------------------------------------------------------- # Configuration options related to source browsing diff --git a/doc/dom.md b/doc/dom.md index d2274de20..f83159208 100644 --- a/doc/dom.md +++ b/doc/dom.md @@ -31,7 +31,7 @@ User can customize these template parameters. ## Encoding {#Encoding} -The `Encoding` parameter specifies the encoding of JSON String value in memory. Possible options are `UTF8`, `UTF16`, `UTF32`. Note that, these 3 types are also template class. `UTF8<>` is `UTF8`, which means using char to store the characters. You may refer to [Encoding](encoding.md) for details. +The `Encoding` parameter specifies the encoding of JSON String value in memory. Possible options are `UTF8`, `UTF16`, `UTF32`. Note that, these 3 types are also template class. `UTF8<>` is `UTF8`, which means using char to store the characters. You may refer to [Encoding](doc/encoding.md) for details. Suppose a Windows application would query localization strings stored in JSON files. Unicode-enabled functions in Windows use UTF-16 (wide character) encoding. No matter what encoding was used in JSON files, we can store the strings in UTF-16 in memory. @@ -106,7 +106,7 @@ GenericDocument& GenericDocument::Parse(const Ch* str); GenericDocument& GenericDocument::Parse(const Ch* str); ~~~~~~~~~~ -The examples of [tutorial](tutorial.md) uses (9) for normal parsing of string. The examples of [stream](stream.md) uses the first three. *In situ* parsing will be described soon. +The examples of [tutorial](doc/tutorial.md) uses (9) for normal parsing of string. The examples of [stream](doc/stream.md) uses the first three. *In situ* parsing will be described soon. The `parseFlags` are combination of the following bit-flags: diff --git a/doc/faq.md b/doc/faq.md index 46eb967e9..22c4cf739 100644 --- a/doc/faq.md +++ b/doc/faq.md @@ -4,7 +4,7 @@ 1. What is RapidJSON? - RapidJSON is a C++ library for parsing and generating JSON. You may check all [features](features.md) of it. + RapidJSON is a C++ library for parsing and generating JSON. You may check all [features](doc/features.md) of it. 2. Why is it named so? diff --git a/doc/tutorial.md b/doc/tutorial.md index 40e061ca4..72e267043 100644 --- a/doc/tutorial.md +++ b/doc/tutorial.md @@ -2,7 +2,7 @@ This tutorial introduces the basics of the Document Object Model(DOM) API. -As shown in [Usage at a glance](readme.md), a JSON can be parsed into DOM, and then the DOM can be queried and modified easily, and finally be converted back to JSON. +As shown in [Usage at a glance](@ref index), a JSON can be parsed into DOM, and then the DOM can be queried and modified easily, and finally be converted back to JSON. [TOC] @@ -512,4 +512,4 @@ This tutorial shows the basics of DOM tree query and manipulation. There are sev 5. [Performance](doc/performance.md) shows some in-house and third-party benchmarks. 6. [Internals](doc/internals.md) describes some internal designs and techniques of RapidJSON. -You may also refer to the [FAQ](faq.md), API documentation, examples and unit tests. +You may also refer to the [FAQ](doc/faq.md), API documentation, examples and unit tests. From d69991fa11cac8dea91f60f5e7a75970873262c7 Mon Sep 17 00:00:00 2001 From: Andriy Senkovych Date: Tue, 11 Nov 2014 17:16:51 +0200 Subject: [PATCH 03/10] Set separate directory to place binaries --- CMakeLists.txt | 3 +++ example/CMakeLists.txt | 2 +- test/perftest/CMakeLists.txt | 2 +- test/unittest/CMakeLists.txt | 2 +- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b7a4961b8..36e7d1d59 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,6 +11,9 @@ set(LIB_VERSION_STRING "${LIB_MAJOR_VERSION}.${LIB_MINOR_VERSION}.${LIB_PATCH_VE # compile in release with debug info mode by default SET(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Build Type") +# Build all binaries in a separate directory +SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) + option(RAPIDJSON_BUILD_DOC "Build rapidjson documentation." ON) option(RAPIDJSON_BUILD_EXAMPLES "Build rapidjson examples." ON) option(RAPIDJSON_BUILD_TESTS "Build rapidjson perftests and unittests." ON) diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index cd355b424..1523c6385 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -15,5 +15,5 @@ set(EXAMPLES tutorial) foreach (example ${EXAMPLES}) - add_executable(${example}_ ${example}/${example}.cpp) + add_executable(${example} ${example}/${example}.cpp) endforeach() diff --git a/test/perftest/CMakeLists.txt b/test/perftest/CMakeLists.txt index 35895670e..8d5d4e373 100644 --- a/test/perftest/CMakeLists.txt +++ b/test/perftest/CMakeLists.txt @@ -7,5 +7,5 @@ set(PERFTEST_SOURCES add_executable(perftest ${PERFTEST_SOURCES}) target_link_libraries(perftest ${TEST_LIBRARIES}) add_test(NAME perftest - COMMAND ${CMAKE_CURRENT_BINARY_DIR}/perftest + COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/perftest WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/bin) diff --git a/test/unittest/CMakeLists.txt b/test/unittest/CMakeLists.txt index fa687e768..2e8c05f3c 100644 --- a/test/unittest/CMakeLists.txt +++ b/test/unittest/CMakeLists.txt @@ -13,5 +13,5 @@ set(UNITTEST_SOURCES add_executable(unittest ${UNITTEST_SOURCES}) target_link_libraries(unittest ${TEST_LIBRARIES}) add_test(NAME unittest - COMMAND ${CMAKE_CURRENT_BINARY_DIR}/unittest + COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/unittest WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/bin) From 1f1aab1061006250801aaf5d1cd30c0fd1ced9cf Mon Sep 17 00:00:00 2001 From: Andriy Senkovych Date: Wed, 5 Nov 2014 04:00:05 +0200 Subject: [PATCH 04/10] Ignore files generated by CMake --- .gitignore | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/.gitignore b/.gitignore index 304456ff7..8ea8f0056 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,17 @@ /doc/doxygen_*.db /thirdparty/lib /intermediate + +# Temporary files created during CMake build +CMakeCache.txt +CMakeFiles +cmake_install.cmake +CTestTestfile.cmake +Makefile +RapidJSON*.cmake +RapidJSON.pc +Testing +/googletest +install_manifest.txt +Doxyfile +DartConfiguration.tcl From 6f7789ef6d8a681ecc0fb3244b8c431556f0b7eb Mon Sep 17 00:00:00 2001 From: Andriy Senkovych Date: Tue, 11 Nov 2014 17:17:23 +0200 Subject: [PATCH 05/10] Update readme with changes to CMake build process --- readme.md | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/readme.md b/readme.md index 3c53cc2bb..c695a1644 100644 --- a/readme.md +++ b/readme.md @@ -41,21 +41,28 @@ Users can build and run the unit tests on their platform/compiler. RapidJSON is a header-only C++ library. Just copy the `include/rapidjson` folder to system or project's include path. -To build the tests and examples: +RapidJSON uses following software as its dependencies: +* [CMake](http://www.cmake.org) as a general build tool +* (optional)[Doxygen](http://www.goxygen.org) to build documentation +* (optional)[googletest](https://code.google.com/p/googletest/) for unit and performance testing +To generate user documentation and run tests please proceed with the steps below: 1. Execute `git submodule update --init` to get the files of thirdparty submodules (google test). -2. Obtain [premake4](http://industriousone.com/premake/download). -3. Copy premake4 executable to `rapidjson/build` (or system path). -4. Change directory to `rapidjson/build/`, run `premake.bat` on Windows, `premake.sh` on Linux or other platforms. -5. On Windows, build the solution at `rapidjson/build/vs2008/` or `/vs2010/`. -6. On other platforms, run GNU `make` at `rapidjson/build/gmake/` (e.g., `make -f test.make config=release32`; `make -f example.make config=debug32`). -7. On success, the executables are generated at `rapidjson/bin`. - -To build the [Doxygen](http://doxygen.org) documentation: - -1. Obtain and install [Doxygen](http://doxygen.org/download.html). -2. In the top-level directory, run `doxygen build/Doxyfile`. -3. Browse the generated documentation in `doc/html`. +2. Create directory called `build` nearby rapidjson source directory. +3. Change to `build` directory and run `cmake ../rapidjson` command to configure your build. Windows users can do the same with cmake-gui application. +4. On Windows, build the solution found in the build directory. On Linux, run `make` from the build directory. + +On successfull build you will find compiled test and example binaries in `bin` +directory. The generated documentation will be available in `doc/html` +directory of the build tree. To run tests after finished build please run `make +test` or `ctest` from your build tree. You can get detailed output using `ctest +-V` command. + +It is possible to install library system-wide by running `make install` command +from the build tree with administrative privileges. This will install all files +according to system preferences. Once RapidJSON is installed, it is possible +to use it from other CMake projects by adding `find_package(RapidJSON)` line to +your CMakeLists.txt. ## Usage at a glance From 8f3f0ea16784b4bce3f4c3d9ec36a0325aca7162 Mon Sep 17 00:00:00 2001 From: Andriy Senkovych Date: Tue, 11 Nov 2014 17:50:32 +0200 Subject: [PATCH 06/10] Add separate targets for examples and tests --- example/CMakeLists.txt | 2 ++ test/CMakeLists.txt | 2 ++ test/perftest/CMakeLists.txt | 3 +++ test/unittest/CMakeLists.txt | 3 +++ 4 files changed, 10 insertions(+) diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 1523c6385..ae498345d 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -17,3 +17,5 @@ set(EXAMPLES foreach (example ${EXAMPLES}) add_executable(${example} ${example}/${example}.cpp) endforeach() + +add_custom_target(examples ALL DEPENDS ${EXAMPLES}) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 92d43094b..af09c62ae 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -12,6 +12,8 @@ IF(GTESTSRC_FOUND) set(TEST_LIBRARIES gtest gtest_main) + add_custom_target(tests ALL) add_subdirectory(perftest) add_subdirectory(unittest) + ENDIF(GTESTSRC_FOUND) diff --git a/test/perftest/CMakeLists.txt b/test/perftest/CMakeLists.txt index 8d5d4e373..4185f12ad 100644 --- a/test/perftest/CMakeLists.txt +++ b/test/perftest/CMakeLists.txt @@ -6,6 +6,9 @@ set(PERFTEST_SOURCES add_executable(perftest ${PERFTEST_SOURCES}) target_link_libraries(perftest ${TEST_LIBRARIES}) + +add_dependencies(tests perftest) + add_test(NAME perftest COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/perftest WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/bin) diff --git a/test/unittest/CMakeLists.txt b/test/unittest/CMakeLists.txt index 2e8c05f3c..720c06320 100644 --- a/test/unittest/CMakeLists.txt +++ b/test/unittest/CMakeLists.txt @@ -12,6 +12,9 @@ set(UNITTEST_SOURCES add_executable(unittest ${UNITTEST_SOURCES}) target_link_libraries(unittest ${TEST_LIBRARIES}) + +add_dependencies(tests unittest) + add_test(NAME unittest COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/unittest WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/bin) From 40648f164b7a925d31aae8daa5ecbdeaa5bf2a3c Mon Sep 17 00:00:00 2001 From: Andriy Senkovych Date: Tue, 11 Nov 2014 18:10:55 +0200 Subject: [PATCH 07/10] Add namespacetest to the unit tests --- test/unittest/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/test/unittest/CMakeLists.txt b/test/unittest/CMakeLists.txt index 720c06320..fb7287810 100644 --- a/test/unittest/CMakeLists.txt +++ b/test/unittest/CMakeLists.txt @@ -4,6 +4,7 @@ set(UNITTEST_SOURCES encodingstest.cpp filestreamtest.cpp jsoncheckertest.cpp + namespacetest.cpp readertest.cpp unittest.cpp unittest.h From bff9625e866376e21ef7aafbfbb123d5e7523826 Mon Sep 17 00:00:00 2001 From: Andriy Senkovych Date: Wed, 12 Nov 2014 01:57:00 +0200 Subject: [PATCH 08/10] Add travis tests to be run from CTest --- test/perftest/CMakeLists.txt | 2 ++ test/unittest/CMakeLists.txt | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/test/perftest/CMakeLists.txt b/test/perftest/CMakeLists.txt index 4185f12ad..4121bf9fa 100644 --- a/test/perftest/CMakeLists.txt +++ b/test/perftest/CMakeLists.txt @@ -9,6 +9,8 @@ target_link_libraries(perftest ${TEST_LIBRARIES}) add_dependencies(tests perftest) +IF(NOT (CMAKE_BUILD_TYPE STREQUAL "Debug")) add_test(NAME perftest COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/perftest WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/bin) +ENDIF() diff --git a/test/unittest/CMakeLists.txt b/test/unittest/CMakeLists.txt index fb7287810..41e56952e 100644 --- a/test/unittest/CMakeLists.txt +++ b/test/unittest/CMakeLists.txt @@ -4,18 +4,29 @@ set(UNITTEST_SOURCES encodingstest.cpp filestreamtest.cpp jsoncheckertest.cpp - namespacetest.cpp readertest.cpp unittest.cpp unittest.h valuetest.cpp writertest.cpp) +add_library(namespacetest STATIC namespacetest.cpp) + add_executable(unittest ${UNITTEST_SOURCES}) -target_link_libraries(unittest ${TEST_LIBRARIES}) +target_link_libraries(unittest ${TEST_LIBRARIES} namespacetest) add_dependencies(tests unittest) add_test(NAME unittest COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/unittest WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/bin) + +add_test(NAME valgrind_unittest + COMMAND valgrind --leak-check=full --error-exitcode=1 ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/unittest + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/bin) + +IF((NOT MSVC) AND (CMAKE_BUILD_TYPE STREQUAL "Debug")) +add_test(NAME symbol_check + COMMAND sh -c "objdump -t -C libnamespacetest.a | grep rapidjson ; test $? -ne 0" + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +ENDIF() From 40c03114e3b4a0751faa134e2ef917fcaf6fee63 Mon Sep 17 00:00:00 2001 From: Andriy Senkovych Date: Wed, 12 Nov 2014 01:57:25 +0200 Subject: [PATCH 09/10] Try new travis configuration --- .travis.yml | 39 +++-- CMakeLists.txt | 12 +- build/premake.bat | 5 - build/premake.sh | 5 - build/premake4.lua | 161 ------------------- readme.md | 4 +- build/travis-doxygen.sh => travis-doxygen.sh | 10 +- 7 files changed, 37 insertions(+), 199 deletions(-) delete mode 100644 build/premake.bat delete mode 100755 build/premake.sh delete mode 100644 build/premake4.lua rename build/travis-doxygen.sh => travis-doxygen.sh (94%) diff --git a/.travis.yml b/.travis.yml index 986ca0e0e..cbc5c0f6b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,36 +6,35 @@ compiler: env: matrix: - - CONF=debug BITS=64 - - CONF=release BITS=64 - - CONF=debug BITS=32 - - CONF=release BITS=32 + - CONF=debug ARCH=x86_64 ARCH_FLAGS="" + - CONF=release ARCH=x86_64 ARCH_FLAGS="" + - CONF=debug ARCH=x86 ARCH_FLAGS="-m32" + - CONF=release ARCH=x86 ARCH_FLAGS="-m32" global: - GITHUB_REPO='miloyip/rapidjson' - - DEFINES='-DRAPIDJSON_HAS_STDSTRING' - secure: "HrsaCb+N66EG1HR+LWH1u51SjaJyRwJEDzqJGYMB7LJ/bfqb9mWKF1fLvZGk46W5t7TVaXRDD5KHFx9DPWvKn4gRUVkwTHEy262ah5ORh8M6n/6VVVajeV/AYt2C0sswdkDBDO4Xq+xy5gdw3G8s1A4Inbm73pUh+6vx+7ltBbk=" before_install: - - sudo add-apt-repository -y ppa:codegear/release - - sudo apt-get update -qq - - sudo apt-get install -qq premake4 valgrind - - if [ "$BITS" = 32 ]; then sudo apt-get install -qq g++-multilib libc6-dbg:i386; fi + - sudo apt-get install -qq cmake doxygen valgrind + - if [ "$ARCH" = "x86" ]; then sudo apt-get install -qq g++-multilib libc6-dbg:i386; fi install: true before_script: - - (cd build && premake4 'gmake') + - mkdir build + - > + (cd build && cmake + -DRAPIDJSON_HAS_STDSTRING=ON + -DCMAKE_VERBOSE_MAKEFILE=ON + -DCMAKE_BUILD_TYPE=$CONF + -DCMAKE_C_FLAGS="$ARCH_FLAGS" ..) # hack to avoid Valgrind bug (https://bugs.kde.org/show_bug.cgi?id=326469), # exposed by merging PR#163 (using -march=native) - - (cd build/gmake && sed -i 's/march=native/msse4.2/' *.make) +# - (cd build/gmake && sed -i 's/march=native/msse4.2/' *.make) script: - - make -C build/gmake -f test.make config=${CONF}${BITS} - - make -C build/gmake -f example.make config=${CONF}${BITS} - - if [ "$CONF" = "debug" ] && ( objdump -t -C intermediate/${CONF}/gmake/unittest/x${BITS}/namespacetest.o | grep rapidjson ) ; then echo "Symbol check failed!" ; false; fi - - pushd bin - - ./unittest_${CONF}_x${BITS}_gmake - - valgrind --leak-check=full --error-exitcode=1 ./unittest_${CONF}_x${BITS}_gmake - - if [ "$CONF" = "release" ]; then ./perftest_${CONF}_x${BITS}_gmake; fi - - popd - - ./build/travis-doxygen.sh; + - cd build + - make tests + - make examples + - ctest -V + - make travis_doc diff --git a/CMakeLists.txt b/CMakeLists.txt index 36e7d1d59..8ed65c89a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -CMAKE_MINIMUM_REQUIRED(VERSION 2.8.11) +CMAKE_MINIMUM_REQUIRED(VERSION 2.8) SET(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/CMakeModules) PROJECT(RapidJSON CXX) @@ -18,6 +18,12 @@ option(RAPIDJSON_BUILD_DOC "Build rapidjson documentation." ON) option(RAPIDJSON_BUILD_EXAMPLES "Build rapidjson examples." ON) option(RAPIDJSON_BUILD_TESTS "Build rapidjson perftests and unittests." ON) +option(RAPIDJSON_HAS_STDSTRING "" OFF) +if(RAPIDJSON_HAS_STDSTRING) + add_definitions(-DRAPIDJSON_HAS_STDSTRING) +endif() + + #add extra search paths for libraries and includes SET(INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/include" CACHE PATH "The directory the headers are installed in") SET(LIB_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/lib" CACHE STRING "Directory where lib will install") @@ -38,6 +44,10 @@ if(RAPIDJSON_BUILD_DOC) add_subdirectory(doc) endif() +add_custom_target(travis_doc) +add_custom_command(TARGET travis_doc + COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/travis-doxygen.sh) + if(RAPIDJSON_BUILD_EXAMPLES) add_subdirectory(example) endif() diff --git a/build/premake.bat b/build/premake.bat deleted file mode 100644 index fe1941a2c..000000000 --- a/build/premake.bat +++ /dev/null @@ -1,5 +0,0 @@ -@echo off -premake4 vs2005 -premake4 vs2008 -premake4 vs2010 -premake4 gmake \ No newline at end of file diff --git a/build/premake.sh b/build/premake.sh deleted file mode 100755 index eaefce829..000000000 --- a/build/premake.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh -premake4 vs2005 -premake4 vs2008 -premake4 vs2010 -premake4 gmake diff --git a/build/premake4.lua b/build/premake4.lua deleted file mode 100644 index cabc2e7be..000000000 --- a/build/premake4.lua +++ /dev/null @@ -1,161 +0,0 @@ -function setTargetObjDir(outDir) - for _, cfg in ipairs(configurations()) do - for _, plat in ipairs(platforms()) do - local action = _ACTION or "" - - local prj = project() - - --"_debug_win32_vs2008" - local suffix = "_" .. cfg .. "_" .. plat .. "_" .. action - - targetPath = outDir - - suffix = string.lower(suffix) - - local obj_path = "../intermediate/" .. cfg .. "/" .. action .. "/" .. prj.name - - obj_path = string.lower(obj_path) - - configuration {cfg, plat} - targetdir(targetPath) - objdir(obj_path) - targetsuffix(suffix) - end - end -end - -function linkLib(libBaseName) - for _, cfg in ipairs(configurations()) do - for _, plat in ipairs(platforms()) do - local action = _ACTION or "" - - local prj = project() - - local cfgName = cfg - - --"_debug_win32_vs2008" - local suffix = "_" .. cfgName .. "_" .. plat .. "_" .. action - - libFullName = libBaseName .. string.lower(suffix) - - configuration {cfg, plat} - links(libFullName) - end - end -end - -solution "test" - configurations { "debug", "release" } - platforms { "x32", "x64" } - - location ("./" .. (_ACTION or "")) - language "C++" - flags { "ExtraWarnings" } - - configuration "debug" - defines { "DEBUG" } - flags { "Symbols" } - - configuration "release" - defines { "NDEBUG" } - flags { "Optimize" } - - configuration "vs*" - defines { "_CRT_SECURE_NO_WARNINGS" } - - configuration "gmake" - buildoptions "-march=native -Wall -Wextra" - - project "gtest" - kind "StaticLib" - - defines { "GTEST_HAS_PTHREAD=0" } - - files { - "../thirdparty/gtest/src/gtest-all.cc", - "../thirdparty/gtest/src/**.h", - } - - includedirs { - "../thirdparty/gtest/", - "../thirdparty/gtest/include", - } - - setTargetObjDir("../thirdparty/lib") - - project "unittest" - kind "ConsoleApp" - - if _ACTION == "gmake" then - buildoptions "-Werror -Weffc++ -Wswitch-default" - end - - files { - "../include/**.h", - "../test/unittest/**.cpp", - "../test/unittest/**.h", - } - - includedirs { - "../include/", - "../thirdparty/gtest/include/", - } - - libdirs "../thirdparty/lib" - - setTargetObjDir("../bin") - - linkLib "gtest" - links "gtest" - - project "perftest" - kind "ConsoleApp" - - files { - "../include/**.h", - "../test/perftest/**.cpp", - "../test/perftest/**.h", - } - - includedirs { - "../include/", - "../thirdparty/gtest/include/", - "../thirdparty/", - } - - libdirs "../thirdparty/lib" - - setTargetObjDir("../bin") - - linkLib "gtest" - links "gtest" - -solution "example" - configurations { "debug", "release" } - platforms { "x32", "x64" } - location ("./" .. (_ACTION or "")) - language "C++" - flags { "ExtraWarnings" } - includedirs "../include/" - - configuration "debug" - defines { "DEBUG" } - flags { "Symbols" } - - configuration "release" - defines { "NDEBUG" } - flags { "Optimize", "EnableSSE2" } - - configuration "vs*" - defines { "_CRT_SECURE_NO_WARNINGS" } - - configuration "gmake" - buildoptions "-Werror -Wall -Wextra -Weffc++ -Wswitch-default" - - local examplepaths = os.matchdirs("../example/*") - for _, examplepath in ipairs(examplepaths) do - project(path.getname(examplepath)) - kind "ConsoleApp" - files(examplepath .. "/*") - setTargetObjDir("../bin") - end diff --git a/readme.md b/readme.md index c695a1644..81f481108 100644 --- a/readme.md +++ b/readme.md @@ -48,8 +48,8 @@ RapidJSON uses following software as its dependencies: To generate user documentation and run tests please proceed with the steps below: 1. Execute `git submodule update --init` to get the files of thirdparty submodules (google test). -2. Create directory called `build` nearby rapidjson source directory. -3. Change to `build` directory and run `cmake ../rapidjson` command to configure your build. Windows users can do the same with cmake-gui application. +2. Create directory called `build` in rapidjson source directory. +3. Change to `build` directory and run `cmake ..` command to configure your build. Windows users can do the same with cmake-gui application. 4. On Windows, build the solution found in the build directory. On Linux, run `make` from the build directory. On successfull build you will find compiled test and example binaries in `bin` diff --git a/build/travis-doxygen.sh b/travis-doxygen.sh similarity index 94% rename from build/travis-doxygen.sh rename to travis-doxygen.sh index 5c4d4a1d2..a7586297f 100755 --- a/build/travis-doxygen.sh +++ b/travis-doxygen.sh @@ -57,13 +57,13 @@ doxygen_install() doxygen_run() { - cd "${TRAVIS_BUILD_DIR}"; - doxygen build/Doxyfile; + cd "${TRAVIS_BUILD_DIR}/build/doc"; + doxygen Doxyfile; } gh_pages_prepare() { - cd "${TRAVIS_BUILD_DIR}/doc"; + cd "${TRAVIS_BUILD_DIR}/build/doc"; [ ! -d "html" ] || \ abort "Doxygen target directory already exists." git --version @@ -78,7 +78,7 @@ gh_pages_prepare() } gh_pages_commit() { - cd "${TRAVIS_BUILD_DIR}/doc/html"; + cd "${TRAVIS_BUILD_DIR}/build/doc/html"; git add --all; git diff-index --quiet HEAD || git commit -m "Automatic doxygen build"; } @@ -102,7 +102,7 @@ gh_pages_push() { [ "${#GH_TOKEN}" -eq 40 ] || \ abort "GitHub token invalid: found ${#GH_TOKEN} characters, expected 40." - cd "${TRAVIS_BUILD_DIR}/doc/html"; + cd "${TRAVIS_BUILD_DIR}/build/doc/html"; # setup credentials (hide in "set -x" mode) git remote set-url --push origin "${GITHUB_URL}" git config credential.helper 'store' From d2b235edbf1187fb061a3da66a32eb78309d3d92 Mon Sep 17 00:00:00 2001 From: Andriy Senkovych Date: Wed, 19 Nov 2014 02:45:09 +0200 Subject: [PATCH 10/10] Modify PATH variable instead of using sudo --- travis-doxygen.sh | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/travis-doxygen.sh b/travis-doxygen.sh index a7586297f..0e715a79e 100755 --- a/travis-doxygen.sh +++ b/travis-doxygen.sh @@ -4,7 +4,6 @@ set -e -SUDO=sudo DOXYGEN_VER=doxygen-1.8.7 DOXYGEN_TAR=${DOXYGEN_VER}.linux.bin.tar.gz DOXYGEN_URL="http://ftp.stack.nl/pub/users/dimitri/${DOXYGEN_TAR}" @@ -51,14 +50,13 @@ doxygen_install() { wget -O - "${DOXYGEN_URL}" | \ tar xz -C ${TMPDIR-/tmp} ${DOXYGEN_VER}/bin/doxygen - $SUDO install -m 755 ${TMPDIR-/tmp}/${DOXYGEN_VER}/bin/doxygen \ - ${DOXYGEN_BIN}; + export PATH="${TMPDIR-/tmp}/${DOXYGEN_VER}/bin:$PATH" } doxygen_run() { - cd "${TRAVIS_BUILD_DIR}/build/doc"; - doxygen Doxyfile; + cd "${TRAVIS_BUILD_DIR}"; + doxygen ${TRAVIS_BUILD_DIR}/build/doc/Doxyfile; } gh_pages_prepare()