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