Skip to content

Commit

Permalink
Use the system version of RapidJSON if available.
Browse files Browse the repository at this point in the history
Since the Ubuntu package doesn't ship with a CMake find module, one is
included here.

Bug: #201
Bug: #178
  • Loading branch information
cameronwhite committed Nov 28, 2015
1 parent 6412f40 commit 047e7d5
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 3 deletions.
5 changes: 4 additions & 1 deletion CMakeLists.txt
@@ -1,7 +1,10 @@
cmake_minimum_required( VERSION 3.1 )
project( powertabeditor )

set( CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake )
set( CMAKE_MODULE_PATH
${CMAKE_SOURCE_DIR}/cmake
${CMAKE_SOURCE_DIR}/cmake/third_party/modules
)

include( PTE_Platform )
include( PTE_CompilerFlags )
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -64,7 +64,7 @@ If you've already cloned the repository, you can run `git submodule init && git
* For older Ubuntu systems (such as Ubuntu 12.04) - you may need to [add some PPAs](https://github.com/powertab/powertabeditor/blob/master/.travis/setup_linux.sh) to get updated versions of the dependencies.
* Install dependencies:
* `sudo apt-get update`
* `sudo apt-get install cmake qtbase5-dev libboost-dev libboost-date-time-dev libboost-iostreams-dev libboost-program-options-dev libboost-regex-dev libasound2-dev libiberty-dev binutils-dev`
* `sudo apt-get install cmake qtbase5-dev libboost-dev libboost-date-time-dev libboost-iostreams-dev libboost-program-options-dev libboost-regex-dev libasound2-dev libiberty-dev binutils-dev rapidjson-dev`
* `sudo apt-get install timidity` - timidity is not required for building, but is a good sequencer for MIDI playback.
* Optionally, use [Ninja](http://martine.github.io/ninja/) instead of `make` (`sudo apt-get install ninja-build`)
* Build:
Expand Down
97 changes: 97 additions & 0 deletions cmake/third_party/modules/Findrapidjson.cmake
@@ -0,0 +1,97 @@
# 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)

# -----------------------------------------------------------------------------------
#
# Finds the rapidjson library
#
# -----------------------------------------------------------------------------------
#
# Variables used by this module, they can change the default behaviour.
# Those variables need to be either set before calling find_package
# or exported as environment variables before running CMake:
#
# RAPIDJSON_INCLUDEDIR - Set custom include path, useful when rapidjson headers are
# outside system paths
# RAPIDJSON_USE_SSE2 - Configure rapidjson to take advantage of SSE2 capabilities
# RAPIDJSON_USE_SSE42 - Configure rapidjson to take advantage of SSE4.2 capabilities
#
# -----------------------------------------------------------------------------------
#
# Variables defined by this module:
#
# RAPIDJSON_FOUND - True if rapidjson was found
# RAPIDJSON_INCLUDE_DIRS - Path to rapidjson include directory
# RAPIDJSON_CXX_FLAGS - Extra C++ flags required for compilation with rapidjson
#
# -----------------------------------------------------------------------------------
#
# Example usage:
#
# set(RAPIDJSON_USE_SSE2 ON)
# set(RAPIDJSON_INCLUDEDIR "/opt/github.com/rjeczalik/rapidjson/include")
#
# find_package(rapidjson REQUIRED)
#
# include_directories("${RAPIDJSON_INCLUDE_DIRS}")
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${RAPIDJSON_CXX_FLAGS}")
# add_executable(foo foo.cc)
#
# -----------------------------------------------------------------------------------

foreach(opt RAPIDJSON_INCLUDEDIR RAPIDJSON_USE_SSE2 RAPIDJSON_USE_SSE42)
if(${opt} AND DEFINED ENV{${opt}} AND NOT ${opt} STREQUAL "$ENV{${opt}}")
message(WARNING "Conflicting ${opt} values: ignoring environment variable and using CMake cache entry.")
elseif(DEFINED ENV{${opt}} AND NOT ${opt})
set(${opt} "$ENV{${opt}}")
endif()
endforeach()

find_path(
RAPIDJSON_INCLUDE_DIRS
NAMES rapidjson/rapidjson.h
PATHS ${RAPIDJSON_INCLUDEDIR}
DOC "Include directory for the rapidjson library."
)

mark_as_advanced(RAPIDJSON_INCLUDE_DIRS)

if(RAPIDJSON_INCLUDE_DIRS)
set(RAPIDJSON_FOUND TRUE)
endif()

mark_as_advanced(RAPIDJSON_FOUND)

if(RAPIDJSON_USE_SSE42)
set(RAPIDJSON_CXX_FLAGS "-DRAPIDJSON_SSE42")
if(MSVC)
set(RAPIDJSON_CXX_FLAGS "${RAPIDJSON_CXX_FLAGS} /arch:SSE4.2")
else()
set(RAPIDJSON_CXX_FLAGS "${RAPIDJSON_CXX_FLAGS} -msse4.2")
endif()
else()
if(RAPIDJSON_USE_SSE2)
set(RAPIDJSON_CXX_FLAGS "-DRAPIDJSON_SSE2")
if(MSVC)
set(RAPIDJSON_CXX_FLAGS "${RAPIDJSON_CXX_FLAGS} /arch:SSE2")
else()
set(RAPIDJSON_CXX_FLAGS "${RAPIDJSON_CXX_FLAGS} -msse2")
endif()
endif()
endif()

mark_as_advanced(RAPIDJSON_CXX_FLAGS)

if(RAPIDJSON_FOUND)
if(NOT rapidjson_FIND_QUIETLY)
message(STATUS "Found rapidjson header files in ${RAPIDJSON_INCLUDE_DIRS}")
if(DEFINED RAPIDJSON_CXX_FLAGS)
message(STATUS "Found rapidjson C++ extra compilation flags: ${RAPIDJSON_CXX_FLAGS}")
endif()
endif()
elseif(rapidjson_FIND_REQUIRED)
message(FATAL_ERROR "Could not find rapidjson")
else()
message(STATUS "Optional package rapidjson was not found")
endif()
12 changes: 11 additions & 1 deletion cmake/third_party/rapidjson.cmake
@@ -1,6 +1,16 @@
find_package( rapidjson )
if ( RAPIDJSON_FOUND )
set( _rapidjson_includedirs ${RAPIDJSON_INCLUDE_DIRS} )
else ()
set( _rapidjson_includedirs ${PTE_EXTERNAL_DIR}/rapidjson/include )
message( STATUS "Using rapidjson headers from ${_rapidjson_includedirs}" )
endif ()

add_library( rapidjson INTERFACE IMPORTED )

set_target_properties(
rapidjson PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${PTE_EXTERNAL_DIR}/rapidjson/include
INTERFACE_INCLUDE_DIRECTORIES ${_rapidjson_includedirs}
)

unset( _rapidjson_includedirs )

0 comments on commit 047e7d5

Please sign in to comment.