@@ -50,7 +50,7 @@ set(PUBLIC_HEADERS
50
50
51
51
source_group ("Public API" FILES ${PUBLIC_HEADERS} )
52
52
53
- set (jsoncpp_sources
53
+ set (JSONCPP_SOURCES
54
54
json_tool.h
55
55
json_reader.cpp
56
56
json_valueiterator.inl
@@ -65,93 +65,161 @@ else()
65
65
set (INSTALL_EXPORT )
66
66
endif ()
67
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
71
+ function (COMPILE_FEATURES ARG1 )
72
+ if (CMAKE_CXX_STANDARD EQUAL "11" )
73
+ target_compile_features (${ARG1} PUBLIC
74
+ cxx_std_11 # Compiler mode is aware of C++ 11.
75
+ #MSVC 1900 cxx_alignas # Alignment control alignas, as defined in N2341.
76
+ #MSVC 1900 cxx_alignof # Alignment control alignof, as defined in N2341.
77
+ #MSVC 1900 cxx_attributes # Generic attributes, as defined in N2761.
78
+ cxx_auto_type # Automatic type deduction, as defined in N1984.
79
+ #MSVC 1900 cxx_constexpr # Constant expressions, as defined in N2235.
80
+ cxx_decltype # Decltype, as defined in N2343.
81
+ cxx_default_function_template_args # Default template arguments for function templates, as defined in DR226
82
+ cxx_defaulted_functions # Defaulted functions, as defined in N2346.
83
+ #MSVC 1900 cxx_defaulted_move_initializers # Defaulted move initializers, as defined in N3053.
84
+ cxx_delegating_constructors # Delegating constructors, as defined in N1986.
85
+ #MSVC 1900 cxx_deleted_functions # Deleted functions, as defined in N2346.
86
+ cxx_enum_forward_declarations # Enum forward declarations, as defined in N2764.
87
+ cxx_explicit_conversions # Explicit conversion operators, as defined in N2437.
88
+ cxx_extended_friend_declarations # Extended friend declarations, as defined in N1791.
89
+ cxx_extern_templates # Extern templates, as defined in N1987.
90
+ cxx_final # Override control final keyword, as defined in N2928, N3206 and N3272.
91
+ #MSVC 1900 cxx_func_identifier # Predefined __func__ identifier, as defined in N2340.
92
+ #MSVC 1900 cxx_generalized_initializers # Initializer lists, as defined in N2672.
93
+ #MSVC 1900 cxx_inheriting_constructors # Inheriting constructors, as defined in N2540.
94
+ #MSVC 1900 cxx_inline_namespaces # Inline namespaces, as defined in N2535.
95
+ cxx_lambdas # Lambda functions, as defined in N2927.
96
+ #MSVC 1900 cxx_local_type_template_args # Local and unnamed types as template arguments, as defined in N2657.
97
+ cxx_long_long_type # long long type, as defined in N1811.
98
+ #MSVC 1900 cxx_noexcept # Exception specifications, as defined in N3050.
99
+ #MSVC 1900 cxx_nonstatic_member_init # Non-static data member initialization, as defined in N2756.
100
+ cxx_nullptr # Null pointer, as defined in N2431.
101
+ cxx_override # Override control override keyword, as defined in N2928, N3206 and N3272.
102
+ cxx_range_for # Range-based for, as defined in N2930.
103
+ cxx_raw_string_literals # Raw string literals, as defined in N2442.
104
+ #MSVC 1900 cxx_reference_qualified_functions # Reference qualified functions, as defined in N2439.
105
+ cxx_right_angle_brackets # Right angle bracket parsing, as defined in N1757.
106
+ cxx_rvalue_references # R-value references, as defined in N2118.
107
+ #MSVC 1900 cxx_sizeof_member # Size of non-static data members, as defined in N2253.
108
+ cxx_static_assert # Static assert, as defined in N1720.
109
+ cxx_strong_enums # Strongly typed enums, as defined in N2347.
110
+ #MSVC 1900 cxx_thread_local # Thread-local variables, as defined in N2659.
111
+ cxx_trailing_return_types # Automatic function return type, as defined in N2541.
112
+ #MSVC 1900 cxx_unicode_literals # Unicode string literals, as defined in N2442.
113
+ cxx_uniform_initialization # Uniform initialization, as defined in N2640.
114
+ #MSVC 1900 cxx_unrestricted_unions # Unrestricted unions, as defined in N2544.
115
+ #MSVC 1900 cxx_user_literals # User-defined literals, as defined in N2765.
116
+ cxx_variadic_macros # Variadic macros, as defined in N1653.
117
+ cxx_variadic_templates # Variadic templates, as defined in N2242.
118
+ )
119
+ else ()
120
+ set (CMAKE_CXX_STANDARD 98 )
121
+ target_compile_features (${ARG1} PUBLIC )
122
+ endif ()
123
+ endfunction ()
68
124
69
125
if (BUILD_SHARED_LIBS )
70
126
if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.12.0 )
71
127
add_compile_definitions (JSON_DLL_BUILD )
72
128
else ()
73
129
add_definitions (-DJSON_DLL_BUILD )
74
130
endif ()
131
+
132
+ set (SHARED_LIB ${PROJECT_NAME} _lib )
133
+ add_library (${SHARED_LIB} SHARED ${PUBLIC_HEADERS} ${JSONCPP_SOURCES} )
134
+ set_target_properties ( ${SHARED_LIB} PROPERTIES
135
+ OUTPUT_NAME jsoncpp
136
+ VERSION ${JSONCPP_VERSION}
137
+ SOVERSION ${JSONCPP_SOVERSION}
138
+ POSITION_INDEPENDENT_CODE ON
139
+ )
140
+
141
+ # Set library's runtime search path on OSX
142
+ if (APPLE )
143
+ set_target_properties (${SHARED_LIB} PROPERTIES INSTALL_RPATH "@loader_path/." )
144
+ endif ()
145
+
146
+ COMPILE_FEATURES (${SHARED_LIB} )
147
+
148
+ if (NOT CMAKE_VERSION VERSION_LESS 2.8.11 )
149
+ target_include_directories (${SHARED_LIB} PUBLIC
150
+ $< INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR} >
151
+ $< BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR} /${JSONCPP_INCLUDE_DIR} >
152
+ $< BUILD_INTERFACE:${PROJECT_BINARY_DIR} /include/json>
153
+ )
154
+ endif ()
155
+
156
+ list (APPEND CMAKE_TARGETS ${SHARED_LIB} )
75
157
endif ()
76
158
77
- add_library (jsoncpp_lib ${PUBLIC_HEADERS} ${jsoncpp_sources} )
78
- set_target_properties ( jsoncpp_lib PROPERTIES
79
- OUTPUT_NAME jsoncpp
80
- VERSION ${JSONCPP_VERSION}
81
- SOVERSION ${JSONCPP_SOVERSION}
82
- POSITION_INDEPENDENT_CODE ON
83
- )
159
+ if (BUILD_STATIC_LIBS )
160
+ set (STATIC_LIB ${PROJECT_NAME} _static )
161
+ add_library (${STATIC_LIB} STATIC ${PUBLIC_HEADERS} ${JSONCPP_SOURCES} )
162
+
163
+ # avoid name clashes on windows as the shared import lib is also named jsoncpp.lib
164
+ if (NOT DEFINED STATIC_SUFFIX AND BUILD_SHARED_LIBS )
165
+ set (STATIC_SUFFIX "_static" )
166
+ endif ()
167
+
168
+ set_target_properties ( ${STATIC_LIB} PROPERTIES
169
+ OUTPUT_NAME jsoncpp${STATIC_SUFFIX}
170
+ VERSION ${JSONCPP_VERSION}
171
+ )
172
+
173
+ # Set library's runtime search path on OSX
174
+ if (APPLE )
175
+ set_target_properties (${STATIC_LIB} PROPERTIES INSTALL_RPATH "@loader_path/." )
176
+ endif ()
84
177
85
- # Set library's runtime search path on OSX
86
- if (APPLE )
87
- set_target_properties (jsoncpp_lib PROPERTIES INSTALL_RPATH "@loader_path/." )
178
+ COMPILE_FEATURES (${STATIC_LIB} )
179
+
180
+ if (NOT CMAKE_VERSION VERSION_LESS 2.8.11 )
181
+ target_include_directories (${STATIC_LIB} PUBLIC
182
+ $< INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR} >
183
+ $< BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR} /${JSONCPP_INCLUDE_DIR} >
184
+ $< BUILD_INTERFACE:${PROJECT_BINARY_DIR} /include/json>
185
+ )
186
+ endif ()
187
+
188
+ list (APPEND CMAKE_TARGETS ${STATIC_LIB} )
88
189
endif ()
89
190
90
- # Specify compiler features required when compiling a given target.
91
- # See https://cmake.org/cmake/help/v3.1/prop_gbl/CMAKE_CXX_KNOWN_FEATURES.html#prop_gbl:CMAKE_CXX_KNOWN_FEATURES
92
- # for complete list of features available
93
- if (CMAKE_CXX_STANDARD EQUAL "11" )
94
- target_compile_features (jsoncpp_lib PUBLIC
95
- cxx_std_11 # Compiler mode is aware of C++ 11.
96
- #MSVC 1900 cxx_alignas # Alignment control alignas, as defined in N2341.
97
- #MSVC 1900 cxx_alignof # Alignment control alignof, as defined in N2341.
98
- #MSVC 1900 cxx_attributes # Generic attributes, as defined in N2761.
99
- cxx_auto_type # Automatic type deduction, as defined in N1984.
100
- #MSVC 1900 cxx_constexpr # Constant expressions, as defined in N2235.
101
- cxx_decltype # Decltype, as defined in N2343.
102
- cxx_default_function_template_args # Default template arguments for function templates, as defined in DR226
103
- cxx_defaulted_functions # Defaulted functions, as defined in N2346.
104
- #MSVC 1900 cxx_defaulted_move_initializers # Defaulted move initializers, as defined in N3053.
105
- cxx_delegating_constructors # Delegating constructors, as defined in N1986.
106
- #MSVC 1900 cxx_deleted_functions # Deleted functions, as defined in N2346.
107
- cxx_enum_forward_declarations # Enum forward declarations, as defined in N2764.
108
- cxx_explicit_conversions # Explicit conversion operators, as defined in N2437.
109
- cxx_extended_friend_declarations # Extended friend declarations, as defined in N1791.
110
- cxx_extern_templates # Extern templates, as defined in N1987.
111
- cxx_final # Override control final keyword, as defined in N2928, N3206 and N3272.
112
- #MSVC 1900 cxx_func_identifier # Predefined __func__ identifier, as defined in N2340.
113
- #MSVC 1900 cxx_generalized_initializers # Initializer lists, as defined in N2672.
114
- #MSVC 1900 cxx_inheriting_constructors # Inheriting constructors, as defined in N2540.
115
- #MSVC 1900 cxx_inline_namespaces # Inline namespaces, as defined in N2535.
116
- cxx_lambdas # Lambda functions, as defined in N2927.
117
- #MSVC 1900 cxx_local_type_template_args # Local and unnamed types as template arguments, as defined in N2657.
118
- cxx_long_long_type # long long type, as defined in N1811.
119
- #MSVC 1900 cxx_noexcept # Exception specifications, as defined in N3050.
120
- #MSVC 1900 cxx_nonstatic_member_init # Non-static data member initialization, as defined in N2756.
121
- cxx_nullptr # Null pointer, as defined in N2431.
122
- cxx_override # Override control override keyword, as defined in N2928, N3206 and N3272.
123
- cxx_range_for # Range-based for, as defined in N2930.
124
- cxx_raw_string_literals # Raw string literals, as defined in N2442.
125
- #MSVC 1900 cxx_reference_qualified_functions # Reference qualified functions, as defined in N2439.
126
- cxx_right_angle_brackets # Right angle bracket parsing, as defined in N1757.
127
- cxx_rvalue_references # R-value references, as defined in N2118.
128
- #MSVC 1900 cxx_sizeof_member # Size of non-static data members, as defined in N2253.
129
- cxx_static_assert # Static assert, as defined in N1720.
130
- cxx_strong_enums # Strongly typed enums, as defined in N2347.
131
- #MSVC 1900 cxx_thread_local # Thread-local variables, as defined in N2659.
132
- cxx_trailing_return_types # Automatic function return type, as defined in N2541.
133
- #MSVC 1900 cxx_unicode_literals # Unicode string literals, as defined in N2442.
134
- cxx_uniform_initialization # Uniform initialization, as defined in N2640.
135
- #MSVC 1900 cxx_unrestricted_unions # Unrestricted unions, as defined in N2544.
136
- #MSVC 1900 cxx_user_literals # User-defined literals, as defined in N2765.
137
- cxx_variadic_macros # Variadic macros, as defined in N1653.
138
- cxx_variadic_templates # Variadic templates, as defined in N2242.
139
- )
140
- else ()
141
- set (CMAKE_CXX_STANDARD 98 )
142
- target_compile_features (jsoncpp_lib PUBLIC )
191
+ if (BUILD_OBJECT_LIBS )
192
+ set (OBJECT_LIB ${PROJECT_NAME} _object )
193
+ add_library (${OBJECT_LIB} OBJECT ${PUBLIC_HEADERS} ${JSONCPP_SOURCES} )
194
+ set_target_properties ( ${OBJECT_LIB} PROPERTIES
195
+ OUTPUT_NAME jsoncpp
196
+ VERSION ${JSONCPP_VERSION}
197
+ SOVERSION ${JSONCPP_SOVERSION}
198
+ POSITION_INDEPENDENT_CODE ON
199
+ )
200
+
201
+ # Set library's runtime search path on OSX
202
+ if (APPLE )
203
+ set_target_properties (${OBJECT_LIB} PROPERTIES INSTALL_RPATH "@loader_path/." )
204
+ endif ()
205
+
206
+ COMPILE_FEATURES (${OBJECT_LIB} )
207
+
208
+ if (NOT CMAKE_VERSION VERSION_LESS 2.8.11 )
209
+ target_include_directories (${OBJECT_LIB} PUBLIC
210
+ $< INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR} >
211
+ $< BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR} /${JSONCPP_INCLUDE_DIR} >
212
+ $< BUILD_INTERFACE:${PROJECT_BINARY_DIR} /include/json>
213
+ )
214
+ endif ()
215
+
216
+ list (APPEND CMAKE_TARGETS ${OBJECT_LIB} )
143
217
endif ()
144
218
145
- install (TARGETS jsoncpp_lib ${INSTALL_EXPORT}
219
+ install (TARGETS ${CMAKE_TARGETS} ${INSTALL_EXPORT}
146
220
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
147
221
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
148
222
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
223
+ OBJECTS DESTINATION ${CMAKE_INSTALL_LIBDIR}
149
224
)
150
225
151
- if (NOT CMAKE_VERSION VERSION_LESS 2.8.11 )
152
- target_include_directories (jsoncpp_lib PUBLIC
153
- $< INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR} >
154
- $< BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR} /${JSONCPP_INCLUDE_DIR} >
155
- $< BUILD_INTERFACE:${PROJECT_BINARY_DIR} /include/json>
156
- )
157
- endif ()
0 commit comments