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)