2018-12-12 23:40:05 +08:00
|
|
|
if( CMAKE_COMPILER_IS_GNUCXX )
|
2016-12-15 00:53:10 +08:00
|
|
|
#Get compiler version.
|
2018-12-12 23:40:05 +08:00
|
|
|
execute_process( COMMAND ${CMAKE_CXX_COMPILER} -dumpversion
|
2016-12-15 00:53:10 +08:00
|
|
|
OUTPUT_VARIABLE GNUCXX_VERSION )
|
|
|
|
|
|
|
|
#-Werror=* was introduced -after- GCC 4.1.2
|
2018-12-12 23:40:05 +08:00
|
|
|
if( GNUCXX_VERSION VERSION_GREATER 4.1.2 )
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror=strict-aliasing")
|
|
|
|
endif()
|
|
|
|
endif( CMAKE_COMPILER_IS_GNUCXX )
|
2016-12-15 00:53:10 +08:00
|
|
|
|
2018-12-12 23:40:05 +08:00
|
|
|
include(CheckIncludeFileCXX)
|
|
|
|
include(CheckTypeSize)
|
|
|
|
include(CheckStructHasMember)
|
|
|
|
include(CheckCXXSymbolExists)
|
2016-11-07 17:46:18 +08:00
|
|
|
|
|
|
|
check_include_file_cxx(clocale HAVE_CLOCALE)
|
|
|
|
check_cxx_symbol_exists(localeconv clocale HAVE_LOCALECONV)
|
|
|
|
|
2018-12-12 23:40:05 +08:00
|
|
|
if(CMAKE_VERSION VERSION_LESS 3.0.0)
|
2016-12-15 00:53:10 +08:00
|
|
|
# The "LANGUAGE CXX" parameter is not supported in CMake versions below 3,
|
|
|
|
# so the C compiler and header has to be used.
|
|
|
|
check_include_file(locale.h HAVE_LOCALE_H)
|
2018-12-12 23:40:05 +08:00
|
|
|
set(CMAKE_EXTRA_INCLUDE_FILES locale.h)
|
2016-12-15 00:53:10 +08:00
|
|
|
check_type_size("struct lconv" LCONV_SIZE)
|
2018-12-12 23:40:05 +08:00
|
|
|
unset(CMAKE_EXTRA_INCLUDE_FILES)
|
2016-12-15 00:53:10 +08:00
|
|
|
check_struct_has_member("struct lconv" decimal_point locale.h HAVE_DECIMAL_POINT)
|
2018-12-12 23:40:05 +08:00
|
|
|
else()
|
|
|
|
set(CMAKE_EXTRA_INCLUDE_FILES clocale)
|
2016-12-15 00:53:10 +08:00
|
|
|
check_type_size(lconv LCONV_SIZE LANGUAGE CXX)
|
2018-12-12 23:40:05 +08:00
|
|
|
unset(CMAKE_EXTRA_INCLUDE_FILES)
|
2016-12-15 00:53:10 +08:00
|
|
|
check_struct_has_member(lconv decimal_point clocale HAVE_DECIMAL_POINT LANGUAGE CXX)
|
2018-12-12 23:40:05 +08:00
|
|
|
endif()
|
2016-12-15 00:53:10 +08:00
|
|
|
|
2018-12-12 23:40:05 +08:00
|
|
|
if(NOT (HAVE_CLOCALE AND HAVE_LCONV_SIZE AND HAVE_DECIMAL_POINT AND HAVE_LOCALECONV))
|
|
|
|
message(WARNING "Locale functionality is not supported")
|
|
|
|
add_definitions(-DJSONCPP_NO_LOCALE_SUPPORT)
|
|
|
|
endif()
|
2016-11-07 17:46:18 +08:00
|
|
|
|
2018-12-12 23:40:05 +08:00
|
|
|
set( JSONCPP_INCLUDE_DIR ../../include )
|
2013-05-09 04:21:11 +08:00
|
|
|
|
2018-12-12 23:40:05 +08:00
|
|
|
set( PUBLIC_HEADERS
|
2013-05-09 04:21:11 +08:00
|
|
|
${JSONCPP_INCLUDE_DIR}/json/config.h
|
|
|
|
${JSONCPP_INCLUDE_DIR}/json/forwards.h
|
|
|
|
${JSONCPP_INCLUDE_DIR}/json/features.h
|
|
|
|
${JSONCPP_INCLUDE_DIR}/json/value.h
|
|
|
|
${JSONCPP_INCLUDE_DIR}/json/reader.h
|
|
|
|
${JSONCPP_INCLUDE_DIR}/json/writer.h
|
|
|
|
${JSONCPP_INCLUDE_DIR}/json/assertions.h
|
|
|
|
${JSONCPP_INCLUDE_DIR}/json/version.h
|
|
|
|
)
|
|
|
|
|
2018-12-12 23:40:05 +08:00
|
|
|
source_group( "Public API" FILES ${PUBLIC_HEADERS} )
|
2013-05-09 04:21:11 +08:00
|
|
|
|
2018-12-12 23:40:05 +08:00
|
|
|
set(jsoncpp_sources
|
2015-01-28 04:01:42 +08:00
|
|
|
json_tool.h
|
|
|
|
json_reader.cpp
|
|
|
|
json_valueiterator.inl
|
|
|
|
json_value.cpp
|
|
|
|
json_writer.cpp
|
|
|
|
version.h.in)
|
|
|
|
|
2015-02-08 01:34:40 +08:00
|
|
|
# Install instructions for this target
|
2018-12-12 23:40:05 +08:00
|
|
|
if(JSONCPP_WITH_CMAKE_PACKAGE)
|
|
|
|
set(INSTALL_EXPORT EXPORT jsoncpp)
|
|
|
|
else(JSONCPP_WITH_CMAKE_PACKAGE)
|
|
|
|
set(INSTALL_EXPORT)
|
|
|
|
endif()
|
2015-02-08 01:34:40 +08:00
|
|
|
|
2018-12-12 23:40:05 +08:00
|
|
|
if(BUILD_SHARED_LIBS)
|
|
|
|
add_definitions( -DJSON_DLL_BUILD )
|
|
|
|
endif()
|
2016-09-23 13:05:13 +08:00
|
|
|
|
2015-01-28 04:01:42 +08:00
|
|
|
|
2018-12-12 23:40:05 +08:00
|
|
|
add_library(jsoncpp_lib ${PUBLIC_HEADERS} ${jsoncpp_sources})
|
|
|
|
set_target_properties( jsoncpp_lib PROPERTIES VERSION ${JSONCPP_VERSION} SOVERSION ${JSONCPP_SOVERSION})
|
|
|
|
set_target_properties( jsoncpp_lib PROPERTIES OUTPUT_NAME jsoncpp
|
2018-10-03 15:04:01 +08:00
|
|
|
DEBUG_OUTPUT_NAME jsoncpp${DEBUG_LIBNAME_SUFFIX} )
|
2018-12-12 23:40:05 +08:00
|
|
|
set_target_properties( jsoncpp_lib PROPERTIES POSITION_INDEPENDENT_CODE ON)
|
2013-05-09 04:21:11 +08:00
|
|
|
|
2018-10-03 15:04:01 +08:00
|
|
|
# Set library's runtime search path on OSX
|
2018-12-12 23:40:05 +08:00
|
|
|
if(APPLE)
|
|
|
|
set_target_properties( jsoncpp_lib PROPERTIES INSTALL_RPATH "@loader_path/." )
|
|
|
|
endif()
|
2015-01-28 04:01:42 +08:00
|
|
|
|
2018-12-12 23:40:05 +08:00
|
|
|
install( TARGETS jsoncpp_lib ${INSTALL_EXPORT}
|
2018-10-03 15:04:01 +08:00
|
|
|
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
|
|
|
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
|
|
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
2015-01-28 04:01:42 +08:00
|
|
|
|
2018-12-12 23:40:05 +08:00
|
|
|
if(NOT CMAKE_VERSION VERSION_LESS 2.8.11)
|
|
|
|
target_include_directories( jsoncpp_lib PUBLIC
|
2018-10-03 15:04:01 +08:00
|
|
|
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
|
|
|
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/${JSONCPP_INCLUDE_DIR}>)
|
2018-12-12 23:40:05 +08:00
|
|
|
endif()
|