| 1 |
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.1.2) |
| 2 |
#-Werror=* was introduced -after- GCC 4.1.2 |
| 3 |
add_compile_options("-Werror=strict-aliasing") |
| 4 |
endif() |
| 5 |
|
| 6 |
include(CheckIncludeFileCXX) |
| 7 |
include(CheckTypeSize) |
| 8 |
include(CheckStructHasMember) |
| 9 |
include(CheckCXXSymbolExists) |
| 10 |
include(CheckCXXSourceCompiles) |
| 11 |
|
| 12 |
check_include_file_cxx(clocale HAVE_CLOCALE) |
| 13 |
check_cxx_symbol_exists(localeconv clocale HAVE_LOCALECONV) |
| 14 |
|
| 15 |
set(CMAKE_EXTRA_INCLUDE_FILES clocale) |
| 16 |
check_type_size(lconv LCONV_SIZE LANGUAGE CXX) |
| 17 |
unset(CMAKE_EXTRA_INCLUDE_FILES) |
| 18 |
check_struct_has_member(lconv decimal_point clocale HAVE_DECIMAL_POINT LANGUAGE CXX) |
| 19 |
|
| 20 |
if(NOT (HAVE_CLOCALE AND HAVE_LCONV_SIZE AND HAVE_DECIMAL_POINT AND HAVE_LOCALECONV)) |
| 21 |
message(WARNING "Locale functionality is not supported") |
| 22 |
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.12.0) |
| 23 |
add_compile_definitions(JSONCPP_NO_LOCALE_SUPPORT) |
| 24 |
else() |
| 25 |
add_definitions(-DJSONCPP_NO_LOCALE_SUPPORT) |
| 26 |
endif() |
| 27 |
endif() |
| 28 |
|
| 29 |
check_cxx_source_compiles( |
| 30 |
"#include <string_view> |
| 31 |
int main() { std::string_view sv; return 0; }" |
| 32 |
JSONCPP_HAS_STRING_VIEW) |
| 33 |
|
| 34 |
set(JSONCPP_INCLUDE_DIR ../../include) |
| 35 |
|
| 36 |
set(PUBLIC_HEADERS |
| 37 |
${JSONCPP_INCLUDE_DIR}/json/config.h |
| 38 |
${JSONCPP_INCLUDE_DIR}/json/forwards.h |
| 39 |
${JSONCPP_INCLUDE_DIR}/json/json_features.h |
| 40 |
${JSONCPP_INCLUDE_DIR}/json/value.h |
| 41 |
${JSONCPP_INCLUDE_DIR}/json/reader.h |
| 42 |
${JSONCPP_INCLUDE_DIR}/json/version.h |
| 43 |
${JSONCPP_INCLUDE_DIR}/json/writer.h |
| 44 |
${JSONCPP_INCLUDE_DIR}/json/assertions.h |
| 45 |
) |
| 46 |
|
| 47 |
source_group("Public API" FILES ${PUBLIC_HEADERS}) |
| 48 |
|
| 49 |
set(JSONCPP_SOURCES |
| 50 |
json_tool.h |
| 51 |
json_reader.cpp |
| 52 |
json_valueiterator.inl |
| 53 |
json_value.cpp |
| 54 |
json_writer.cpp |
| 55 |
) |
| 56 |
|
| 57 |
# Install instructions for this target |
| 58 |
if(JSONCPP_WITH_CMAKE_PACKAGE) |
| 59 |
set(INSTALL_EXPORT EXPORT jsoncpp) |
| 60 |
else() |
| 61 |
set(INSTALL_EXPORT) |
| 62 |
endif() |
| 63 |
|
| 64 |
# Specify compiler features required when compiling a given target. |
| 65 |
# See https://cmake.org/cmake/help/v3.1/prop_gbl/CMAKE_CXX_KNOWN_FEATURES.html#prop_gbl:CMAKE_CXX_KNOWN_FEATURES |
| 66 |
# for complete list of features available |
| 67 |
list(APPEND REQUIRED_FEATURES |
| 68 |
cxx_std_11 # Compiler mode is aware of C++ 11. |
| 69 |
#MSVC 1900 cxx_alignas # Alignment control alignas, as defined in N2341. |
| 70 |
#MSVC 1900 cxx_alignof # Alignment control alignof, as defined in N2341. |
| 71 |
#MSVC 1900 cxx_attributes # Generic attributes, as defined in N2761. |
| 72 |
cxx_auto_type # Automatic type deduction, as defined in N1984. |
| 73 |
#MSVC 1900 cxx_constexpr # Constant expressions, as defined in N2235. |
| 74 |
cxx_decltype # Decltype, as defined in N2343. |
| 75 |
cxx_default_function_template_args # Default template arguments for function templates, as defined in DR226 |
| 76 |
cxx_defaulted_functions # Defaulted functions, as defined in N2346. |
| 77 |
#MSVC 1900 cxx_defaulted_move_initializers # Defaulted move initializers, as defined in N3053. |
| 78 |
cxx_delegating_constructors # Delegating constructors, as defined in N1986. |
| 79 |
#MSVC 1900 cxx_deleted_functions # Deleted functions, as defined in N2346. |
| 80 |
cxx_enum_forward_declarations # Enum forward declarations, as defined in N2764. |
| 81 |
cxx_explicit_conversions # Explicit conversion operators, as defined in N2437. |
| 82 |
cxx_extended_friend_declarations # Extended friend declarations, as defined in N1791. |
| 83 |
cxx_extern_templates # Extern templates, as defined in N1987. |
| 84 |
cxx_final # Override control final keyword, as defined in N2928, N3206 and N3272. |
| 85 |
#MSVC 1900 cxx_func_identifier # Predefined __func__ identifier, as defined in N2340. |
| 86 |
#MSVC 1900 cxx_generalized_initializers # Initializer lists, as defined in N2672. |
| 87 |
#MSVC 1900 cxx_inheriting_constructors # Inheriting constructors, as defined in N2540. |
| 88 |
#MSVC 1900 cxx_inline_namespaces # Inline namespaces, as defined in N2535. |
| 89 |
cxx_lambdas # Lambda functions, as defined in N2927. |
| 90 |
#MSVC 1900 cxx_local_type_template_args # Local and unnamed types as template arguments, as defined in N2657. |
| 91 |
cxx_long_long_type # long long type, as defined in N1811. |
| 92 |
#MSVC 1900 cxx_noexcept # Exception specifications, as defined in N3050. |
| 93 |
#MSVC 1900 cxx_nonstatic_member_init # Non-static data member initialization, as defined in N2756. |
| 94 |
cxx_nullptr # Null pointer, as defined in N2431. |
| 95 |
cxx_override # Override control override keyword, as defined in N2928, N3206 and N3272. |
| 96 |
cxx_range_for # Range-based for, as defined in N2930. |
| 97 |
cxx_raw_string_literals # Raw string literals, as defined in N2442. |
| 98 |
#MSVC 1900 cxx_reference_qualified_functions # Reference qualified functions, as defined in N2439. |
| 99 |
cxx_right_angle_brackets # Right angle bracket parsing, as defined in N1757. |
| 100 |
cxx_rvalue_references # R-value references, as defined in N2118. |
| 101 |
#MSVC 1900 cxx_sizeof_member # Size of non-static data members, as defined in N2253. |
| 102 |
cxx_static_assert # Static assert, as defined in N1720. |
| 103 |
cxx_strong_enums # Strongly typed enums, as defined in N2347. |
| 104 |
#MSVC 1900 cxx_thread_local # Thread-local variables, as defined in N2659. |
| 105 |
cxx_trailing_return_types # Automatic function return type, as defined in N2541. |
| 106 |
#MSVC 1900 cxx_unicode_literals # Unicode string literals, as defined in N2442. |
| 107 |
cxx_uniform_initialization # Uniform initialization, as defined in N2640. |
| 108 |
#MSVC 1900 cxx_unrestricted_unions # Unrestricted unions, as defined in N2544. |
| 109 |
#MSVC 1900 cxx_user_literals # User-defined literals, as defined in N2765. |
| 110 |
cxx_variadic_macros # Variadic macros, as defined in N1653. |
| 111 |
cxx_variadic_templates # Variadic templates, as defined in N2242. |
| 112 |
) |
| 113 |
|
| 114 |
|
| 115 |
if(BUILD_SHARED_LIBS) |
| 116 |
set(SHARED_LIB ${PROJECT_NAME}_lib) |
| 117 |
add_library(${SHARED_LIB} SHARED ${PUBLIC_HEADERS} ${JSONCPP_SOURCES}) |
| 118 |
set_target_properties(${SHARED_LIB} PROPERTIES |
| 119 |
OUTPUT_NAME jsoncpp |
| 120 |
VERSION ${PROJECT_VERSION} |
| 121 |
SOVERSION ${PROJECT_SOVERSION} |
| 122 |
POSITION_INDEPENDENT_CODE ${BUILD_SHARED_LIBS} |
| 123 |
) |
| 124 |
|
| 125 |
target_compile_definitions(${SHARED_LIB} PRIVATE JSON_DLL_BUILD) |
| 126 |
|
| 127 |
# Set library's runtime search path on OSX |
| 128 |
if(APPLE) |
| 129 |
set_target_properties(${SHARED_LIB} PROPERTIES INSTALL_RPATH "@loader_path/.") |
| 130 |
endif() |
| 131 |
|
| 132 |
target_compile_features(${SHARED_LIB} PUBLIC ${REQUIRED_FEATURES}) |
| 133 |
|
| 134 |
|
| 135 |
target_include_directories(${SHARED_LIB} PUBLIC |
| 136 |
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> |
| 137 |
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/${JSONCPP_INCLUDE_DIR}> |
| 138 |
) |
| 139 |
|
| 140 |
list(APPEND CMAKE_TARGETS ${SHARED_LIB}) |
| 141 |
endif() |
| 142 |
|
| 143 |
if(BUILD_STATIC_LIBS) |
| 144 |
set(STATIC_LIB ${PROJECT_NAME}_static) |
| 145 |
add_library(${STATIC_LIB} STATIC ${PUBLIC_HEADERS} ${JSONCPP_SOURCES}) |
| 146 |
|
| 147 |
# avoid name clashes on windows as the shared import lib is also named jsoncpp.lib |
| 148 |
if(NOT DEFINED STATIC_SUFFIX AND BUILD_SHARED_LIBS) |
| 149 |
if (MSVC OR ("${CMAKE_C_SIMULATE_ID}" STREQUAL "MSVC")) |
| 150 |
set(STATIC_SUFFIX "_static") |
| 151 |
else() |
| 152 |
set(STATIC_SUFFIX "") |
| 153 |
endif() |
| 154 |
endif() |
| 155 |
|
| 156 |
set_target_properties(${STATIC_LIB} PROPERTIES |
| 157 |
OUTPUT_NAME jsoncpp${STATIC_SUFFIX} |
| 158 |
VERSION ${PROJECT_VERSION} |
| 159 |
) |
| 160 |
|
| 161 |
# Set library's runtime search path on OSX |
| 162 |
if(APPLE) |
| 163 |
set_target_properties(${STATIC_LIB} PROPERTIES INSTALL_RPATH "@loader_path/.") |
| 164 |
endif() |
| 165 |
|
| 166 |
target_compile_features(${STATIC_LIB} PUBLIC ${REQUIRED_FEATURES}) |
| 167 |
|
| 168 |
|
| 169 |
target_include_directories(${STATIC_LIB} PUBLIC |
| 170 |
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> |
| 171 |
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/${JSONCPP_INCLUDE_DIR}> |
| 172 |
) |
| 173 |
|
| 174 |
list(APPEND CMAKE_TARGETS ${STATIC_LIB}) |
| 175 |
endif() |
| 176 |
|
| 177 |
if(BUILD_OBJECT_LIBS) |
| 178 |
set(OBJECT_LIB ${PROJECT_NAME}_object) |
| 179 |
add_library(${OBJECT_LIB} OBJECT ${PUBLIC_HEADERS} ${JSONCPP_SOURCES}) |
| 180 |
|
| 181 |
set_target_properties(${OBJECT_LIB} PROPERTIES |
| 182 |
OUTPUT_NAME jsoncpp |
| 183 |
VERSION ${PROJECT_VERSION} |
| 184 |
SOVERSION ${PROJECT_SOVERSION} |
| 185 |
POSITION_INDEPENDENT_CODE ${BUILD_SHARED_LIBS} |
| 186 |
) |
| 187 |
|
| 188 |
# Set library's runtime search path on OSX |
| 189 |
if(APPLE) |
| 190 |
set_target_properties(${OBJECT_LIB} PROPERTIES INSTALL_RPATH "@loader_path/.") |
| 191 |
endif() |
| 192 |
|
| 193 |
target_compile_features(${OBJECT_LIB} PUBLIC ${REQUIRED_FEATURES}) |
| 194 |
|
| 195 |
|
| 196 |
target_include_directories(${OBJECT_LIB} PUBLIC |
| 197 |
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> |
| 198 |
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/${JSONCPP_INCLUDE_DIR}> |
| 199 |
) |
| 200 |
|
| 201 |
list(APPEND CMAKE_TARGETS ${OBJECT_LIB}) |
| 202 |
endif() |
| 203 |
|
| 204 |
if (JSONCPP_WITH_INSTALL) |
| 205 |
|
| 206 |
install(TARGETS ${CMAKE_TARGETS} ${INSTALL_EXPORT} |
| 207 |
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} |
| 208 |
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 209 |
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 210 |
OBJECTS DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 211 |
) |
| 212 |
|
| 213 |
endif() |