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