Skip to content

Commit

Permalink
Merge pull request #192 from jollyroger/cmake
Browse files Browse the repository at this point in the history
CMake support
  • Loading branch information
miloyip committed Feb 11, 2015
2 parents 94480ec + d2b235e commit 09118fa
Show file tree
Hide file tree
Showing 21 changed files with 325 additions and 230 deletions.
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
39 changes: 19 additions & 20 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
98 changes: 98 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
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")

# 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)

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")
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()

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()

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)
22 changes: 22 additions & 0 deletions CMakeModules/FindGTestSrc.cmake
Original file line number Diff line number Diff line change
@@ -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)
4 changes: 4 additions & 0 deletions RapidJSON.pc.in
Original file line number Diff line number Diff line change
@@ -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}
3 changes: 3 additions & 0 deletions RapidJSONConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -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}")
10 changes: 10 additions & 0 deletions RapidJSONConfigVersion.cmake.in
Original file line number Diff line number Diff line change
@@ -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)
5 changes: 0 additions & 5 deletions build/premake.bat

This file was deleted.

5 changes: 0 additions & 5 deletions build/premake.sh

This file was deleted.

161 changes: 0 additions & 161 deletions build/premake4.lua

This file was deleted.

Loading

0 comments on commit 09118fa

Please sign in to comment.