@@ -17,7 +17,6 @@ set ( CMAKE_BUILD_TYPE "Release"
17
17
CACHE STRING "Select which configuration to build." )
18
18
set_property ( CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS ${CMAKE_CONFIGURATION_TYPES} )
19
19
20
-
21
20
enable_language ( Fortran )
22
21
include ( "cmake/pickFortranCompilerFlags.cmake" )
23
22
@@ -42,14 +41,14 @@ set ( VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}" )
42
41
#-------------------------------------
43
42
# Collect source files for the library
44
43
#-------------------------------------
45
- set ( JF_LIB_SRCS src/json_module.f90 )
46
- set ( JF_TEST_SRCS tests/json_example .f90 )
44
+ set ( JF_LIB_SRCS src/json_module.f90 )
45
+ file ( GLOB JF_TEST_SRCS "src/ tests/jf_test_* .f90" )
47
46
48
47
#-----------------------------------------
49
48
# Collect all the mod files into their own
50
49
# directory to ease installation issues
51
50
#-----------------------------------------
52
- set ( CMAKE_Fortran_MODULE_DIRECTORY "${CMAKE_BINARY_DIR} /lib" )
51
+ set ( MODULE_DIR "${CMAKE_BINARY_DIR} /lib" )
53
52
54
53
#-------------------------------------
55
54
# Define where our files get installed
@@ -75,14 +74,14 @@ if ( "${CMAKE_SYSTEM_NAME}" MATCHES "Darwin" )
75
74
set ( ENABLE_DYLIBS_USE_RPATH TRUE CACHE BOOL
76
75
"Enable @rpath install name for dylibs" )
77
76
mark_as_advanced ( ENABLE_DYLIBS_USE_RPATH )
78
- endif ( " ${CMAKE_SYSTEM_NAME} " MATCHES "Darwin" )
77
+ endif ()
79
78
80
79
if ( ENABLE_DYLIBS_USE_RPATH )
81
80
set ( CMAKE_MACOSX_RPATH TRUE )
82
- else ( ENABLE_DYLIBS_USE_RPATH )
81
+ else ()
83
82
set ( CMAKE_INSTALL_NAME_DIR
84
83
"${ABS_LIB_INSTALL_DIR} " )
85
- endif ( ENABLE_DYLIBS_USE_RPATH )
84
+ endif ()
86
85
87
86
#---------------------------------------------
88
87
# Build a shared and static library by default
@@ -96,7 +95,8 @@ set_target_properties ( ${LIB_NAME}-static
96
95
OUTPUT_NAME ${LIB_NAME}
97
96
PREFIX lib
98
97
VERSION ${VERSION}
99
- ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} /lib )
98
+ ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} /lib
99
+ Fortran_MODULE_DIRECTORY ${MODULE_DIR} )
100
100
set_target_properties ( ${LIB_NAME}
101
101
PROPERTIES
102
102
OUTPUT_NAME ${LIB_NAME}
@@ -106,17 +106,6 @@ set_target_properties ( ${LIB_NAME}
106
106
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} /lib
107
107
Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR} )
108
108
109
- #--------------------------
110
- # Build the test executable
111
- #--------------------------
112
- add_executable ( test -${CMAKE_PROJECT_NAME} ${JF_TEST_SRCS} )
113
- target_link_libraries ( test -${CMAKE_PROJECT_NAME} ${LIB_NAME} )
114
- add_executable ( test -${CMAKE_PROJECT_NAME} -static ${JF_TEST_SRCS} )
115
- target_link_libraries ( test -${CMAKE_PROJECT_NAME} -static ${LIB_NAME} -static )
116
- set_target_properties ( test -${CMAKE_PROJECT_NAME} test -${CMAKE_PROJECT_NAME} -static
117
- PROPERTIES
118
- RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} /bin )
119
-
120
109
#-------------------------------------
121
110
# Build the documentation with ROBODoc
122
111
#-------------------------------------
@@ -142,143 +131,125 @@ if ( NOT SKIP_DOC_GEN )
142
131
execute_process ( COMMAND ${CMAKE_COMMAND} -E remove_directory ${DOC_DIR} )
143
132
message ( STATUS "Done dynamically computing ROBODoc outputs." )
144
133
134
+ foreach ( SRC_FILE ${JF_LIB_SRCS} ${JF_TEST_SRCS} )
135
+ list ( APPEND ROBO_DEPENDS "${SRC_FILE} " )
136
+ endforeach ( SRC_FILE )
145
137
add_custom_command ( OUTPUT ${ROBODOC_OUTPUTS}
146
138
COMMAND "${CMAKE_COMMAND} " -E make_directory "${DOC_DIR} " # Ensure DOC_DIR exists at build time
147
139
COMMAND "${ROBODOC} " ${REQUIRED_ROBODOC_OPTIONS} ${ROBODOC_OPTIONS}
148
- DEPENDS " ${CMAKE_SOURCE_DIR} / ${JF_LIB_SRCS} " " ${CMAKE_SOURCE_DIR} / ${JF_TEST_SRCS} "
140
+ DEPENDS ${ROBO_DEPENDS}
149
141
COMMENT "Building HTML documentation for ${CMAKE_PROJECT_NAME} using ROBODoc" )
150
142
add_custom_target ( documentation ALL
151
143
DEPENDS ${ROBODOC_OUTPUTS} )
152
- else ( ROBODOC ) # Not found
144
+ else () # Not found
153
145
message ( WARNING
154
146
"ROBODoc not found! Please set the CMake cache variable ROBODOC to point to the installed ROBODoc binary, and reconfigure or disable building the documentation. ROBODoc can be installed from: http://www.xs4all.nl/~rfsber/Robo/ If you do not wish to install ROBODoc and build the json-fortran documentation, then please set the CMake cache variable SKIP_DOC_GEN to TRUE." )
155
- endif ( ROBODOC )
156
- endif ( NOT SKIP_DOC_GEN )
147
+ endif ()
148
+ endif ()
149
+
150
+ #--------------------------
151
+ # Handle test related stuff
152
+ #--------------------------
153
+ set ( ENABLE_TESTS TRUE CACHE BOOL
154
+ "Enable the json-fortran tests. If true this will force build of example program too" )
157
155
158
156
#---------------------------------------------------------------------
159
157
# Add some tests to ensure that the software is performing as expected
160
158
#---------------------------------------------------------------------
161
- enable_testing ()
162
- find_program ( JSONLINT jsonlint )
163
- find_program ( DIFF diff )
164
- set ( DATA_DIR ${CMAKE_BINARY_DIR} /files )
165
- configure_file ( ${CMAKE_SOURCE_DIR} /files /test1.json ${DATA_DIR} /test1.json COPYONLY )
166
- configure_file ( ${CMAKE_SOURCE_DIR} /files /test5.json ${DATA_DIR} /test5.json COPYONLY )
167
- configure_file ( ${CMAKE_SOURCE_DIR} /files /invalid.json ${DATA_DIR} /invalid.json COPYONLY )
168
- configure_file ( ${CMAKE_SOURCE_DIR} /files /invalid2.json ${DATA_DIR} /invalid2.json COPYONLY )
169
-
170
- # Validate input
171
- if ( JSONLINT )
172
- add_test ( NAME validate-input1
173
- WORKING_DIRECTORY ${DATA_DIR}
174
- COMMAND ${JSONLINT} test1.json )
175
- add_test ( NAME validate-input5
176
- WORKING_DIRECTORY ${DATA_DIR}
177
- COMMAND ${JSONLINT} test5.json )
178
- endif ( JSONLINT )
179
- # As of now these are kind of sniff tests... Need to modify test program to indicate failure with `stop` codes
180
- # or more easily parsed results, and be able to validate json sent to stdout
181
-
182
- # Dynamic lib
183
- add_test ( NAME test -${CMAKE_PROJECT_NAME}
184
- WORKING_DIRECTORY ${CMAKE_BINARY_DIR} /bin/
185
- COMMAND test -${CMAKE_PROJECT_NAME} )
186
- # Validate output
187
- if ( JSONLINT )
188
- add_test ( NAME validate-test2
189
- WORKING_DIRECTORY ${DATA_DIR}
190
- COMMAND ${JSONLINT} test2.json )
191
- set ( OPTIONAL_TESTS2 ${OPTIONAL_TESTS2} validate-test2 )
192
- add_test ( NAME validate-test4
193
- WORKING_DIRECTORY ${DATA_DIR}
194
- COMMAND ${JSONLINT} test4.json )
195
- set ( OPTIONAL_TESTS4 ${OPTIONAL_TESTS4} validate-test4 )
196
- endif ( JSONLINT )
197
- # Check output for differences
198
- if ( DIFF )
199
- add_test ( NAME test2-regression
200
- WORKING_DIRECTORY ${DATA_DIR}
201
- COMMAND ${DIFF} -q test2.json ${CMAKE_SOURCE_DIR} /files /test2.json )
202
- set ( OPTIONAL_TESTS2 ${OPTIONAL_TESTS2} test2-regression )
203
- add_test ( NAME test4-regression
204
- WORKING_DIRECTORY ${DATA_DIR}
205
- COMMAND ${DIFF} -q test4.json ${CMAKE_SOURCE_DIR} /files /test4.json )
206
- set ( OPTIONAL_TESTS4 ${OPTIONAL_TESTS4} test4-regression )
207
- else ( DIFF )
208
- message ( WARNING
209
- "For full test coverage diff, or a similar tool must be present on your system" )
210
- endif ( DIFF )
211
- if ( DIFF OR JSONLINT )
212
- set_tests_properties ( ${OPTIONAL_TESTS2}
213
- PROPERTIES
214
- DEPENDS test -${CMAKE_PROJECT_NAME}
215
- REQUIRED_FILES "${DATA_DIR} /test2.json"
216
- RESOURCE_LOCK "${DATA_DIR} /test2.json" )
217
- set_tests_properties ( ${OPTIONAL_TESTS4}
218
- PROPERTIES
219
- DEPENDS test -${CMAKE_PROJECT_NAME}
220
- REQUIRED_FILES "${DATA_DIR} /test4.json"
221
- RESOURCE_LOCK "${DATA_DIR} /test4.json" )
222
- endif ( DIFF OR JSONLINT )
223
- # Static lib
224
- add_test ( NAME test -${CMAKE_PROJECT_NAME} -static
225
- WORKING_DIRECTORY "${CMAKE_BINARY_DIR} /bin/"
226
- COMMAND test -${CMAKE_PROJECT_NAME} -static )
227
- unset ( OPTIONAL_TESTS2 )
228
- unset ( OPTIONAL_TESTS4 )
229
- # Validate output
230
- if ( JSONLINT )
231
- add_test ( NAME validate-test2-static
232
- WORKING_DIRECTORY ${DATA_DIR}
233
- COMMAND ${JSONLINT} test2.json )
234
- set ( OPTIONAL_TESTS2 ${OPTIONAL_TESTS2} validate-test2-static )
235
- add_test ( NAME validate-test4-static
236
- WORKING_DIRECTORY ${DATA_DIR}
237
- COMMAND ${JSONLINT} test4.json )
238
- set ( OPTIONAL_TESTS4 ${OPTIONAL_TESTS4} validate-test4-static )
239
- endif ( JSONLINT )
240
- # Check output for differences
241
- if ( DIFF )
242
- add_test ( NAME test2-regression-static
243
- WORKING_DIRECTORY ${DATA_DIR}
244
- COMMAND ${DIFF} -q test2.json ${CMAKE_SOURCE_DIR} /files /test2.json )
245
- set ( OPTIONAL_TESTS2 ${OPTIONAL_TESTS2} test2-regression-static )
246
- add_test ( NAME test4-regression-static
247
- WORKING_DIRECTORY ${DATA_DIR}
248
- COMMAND ${DIFF} -q test4.json ${CMAKE_SOURCE_DIR} /files /test4.json )
249
- set ( OPTIONAL_TESTS4 ${OPTIONAL_TESTS4} test4-regression-static )
250
- endif ( DIFF )
251
- if ( JSONLINT OR DIFF )
252
- set_tests_properties ( ${OPTIONAL_TESTS2}
253
- PROPERTIES
254
- DEPENDS test -${CMAKE_PROJECT_NAME} -static
255
- REQUIRED_FILES "${DATA_DIR} /test2.json"
256
- RESOURCE_LOCK "${DATA_DIR} /test2.json" )
257
- set_tests_properties ( ${OPTIONAL_TESTS4}
258
- PROPERTIES
259
- DEPENDS test -${CMAKE_PROJECT_NAME} -static
260
- REQUIRED_FILES "${DATA_DIR} /test4.json"
261
- RESOURCE_LOCK "${DATA_DIR} /test4.json" )
262
- endif ( JSONLINT OR DIFF )
263
-
264
- if ( JSONLINT )
265
- set_tests_properties ( test -${CMAKE_PROJECT_NAME} test -${CMAKE_PROJECT_NAME} -static
266
- PROPERTIES
267
- FAIL_REGULAR_EXPRESSION "Error;ERROR;error"
268
- REQUIRED_FILES "${DATA_DIR} /test1.json;${DATA_DIR} /test5.json"
269
- RESOURCE_LOCK "${DATA_DIR} /test2.json;${DATA_DIR} /test4.json"
270
- DEPENDS "validate-input1;validate-input5" )
271
- else ( JSONLINT ) # Don't force validation of input if no JSONLINT
272
- message ( WARNING
273
- "For full test coverage please download and install jsonlint, a NODEJS package <http://nodejs.org>" )
274
- set_tests_properties ( test -${CMAKE_PROJECT_NAME} test -${CMAKE_PROJECT_NAME} -static
275
- PROPERTIES
276
- FAIL_REGULAR_EXPRESSION "Error;ERROR;error"
277
- REQUIRED_FILES "${DATA_DIR} /test1.json;${DATA_DIR} /test5.json"
278
- RESOURCE_LOCK "${DATA_DIR} /test2.json;${DATA_DIR} /test4.json" )
279
- endif ( JSONLINT )
280
- set_directory_properties ( PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES
281
- "${DATA_DIR} /test2.json;${DATA_DIR} /test4.json" )
159
+ if ( ENABLE_TESTS ) # BUILD_EXAMPLE_PROGRAM will be true too
160
+ enable_testing ()
161
+
162
+ find_program ( JSONLINT jsonlint )
163
+ find_program ( DIFF diff )
164
+ set ( DATA_DIR ${CMAKE_BINARY_DIR} /files )
165
+ configure_file ( ${CMAKE_SOURCE_DIR} /files /test1.json ${DATA_DIR} /test1.json COPYONLY )
166
+ configure_file ( ${CMAKE_SOURCE_DIR} /files /test5.json ${DATA_DIR} /test5.json COPYONLY )
167
+ configure_file ( ${CMAKE_SOURCE_DIR} /files /invalid.json ${DATA_DIR} /invalid.json COPYONLY )
168
+ configure_file ( ${CMAKE_SOURCE_DIR} /files /invalid2.json ${DATA_DIR} /invalid2.json COPYONLY )
169
+
170
+ set_directory_properties ( PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES
171
+ "${DATA_DIR} /test2.json;${DATA_DIR} /test4.json" )
172
+
173
+ # Validate input
174
+ if ( JSONLINT )
175
+ add_test ( NAME validate-input1
176
+ WORKING_DIRECTORY ${DATA_DIR}
177
+ COMMAND ${JSONLINT} test1.json )
178
+ add_test ( NAME validate-input5
179
+ WORKING_DIRECTORY ${DATA_DIR}
180
+ COMMAND ${JSONLINT} test5.json )
181
+ add_test ( NAME validate-invalid
182
+ WORKING_DIRECTORY ${DATA_DIR}
183
+ COMMAND ${JSONLINT} invalid.json )
184
+ set_property ( TEST validate-invalid
185
+ PROPERTY
186
+ WILL_FAIL TRUE )
187
+ add_test ( NAME validate-invalid2
188
+ WORKING_DIRECTORY ${DATA_DIR}
189
+ COMMAND ${JSONLINT} invalid2.json )
190
+ set_property ( TEST validate-invalid2
191
+ PROPERTY
192
+ WILL_FAIL TRUE )
193
+ endif ()
194
+
195
+ set ( UNIT_TESTS '' )
196
+ foreach ( UNIT_TEST ${JF_TEST_SRCS} )
197
+ get_filename_component ( TEST ${UNIT_TEST} NAME_WE )
198
+ add_executable ( ${TEST} ${UNIT_TEST} )
199
+ target_link_libraries ( ${TEST} ${LIB_NAME} )
200
+ set_target_properties ( ${TEST}
201
+ PROPERTIES
202
+ RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} /bin )
203
+ add_test ( NAME ${TEST}
204
+ WORKING_DIRECTORY ${CMAKE_BINARY_DIR} /bin
205
+ COMMAND ./${TEST} )
206
+ list ( APPEND UNIT_TESTS ${TEST} )
207
+ if ( JSONLINT )
208
+ set_property ( TEST ${TEST}
209
+ APPEND
210
+ PROPERTY DEPENDS validate-input1 validate-input2 )
211
+ endif ()
212
+ endforeach ( UNIT_TEST )
213
+
214
+ set_property ( TEST jf_test_3
215
+ APPEND
216
+ PROPERTY DEPENDS jf_test_2 )
217
+
218
+ # Validate output
219
+ if ( JSONLINT )
220
+ file ( GLOB JSON_FILES "${DATA_DIR} /test*.json" )
221
+ foreach ( JSON_FILE ${JSON_FILES} )
222
+ get_filename_component ( JSON_STEM ${JSON_FILE} NAME_WE )
223
+ add_test ( NAME validate-output -${JSON_STEM} .json
224
+ WORKING_DIRECTORY ${DATA_DIR}
225
+ COMMAND ${JSONLINT} ${JSON_STEM} .json )
226
+ set_property ( TEST validate-output -${JSON_STEM} .json
227
+ APPEND
228
+ PROPERTY
229
+ DEPENDS ${UNIT_TESTS}
230
+ REQUIRED_FILES ${JSON_FILES} )
231
+ endforeach ( JSON_FILE )
232
+ endif ()
233
+ # Check output for differences
234
+ if ( DIFF )
235
+ file ( GLOB JSON_FILES "${DATA_DIR} /test*.json" )
236
+ foreach ( JSON_FILE ${JSON_FILES} )
237
+ get_filename_component ( JSON_STEM ${JSON_FILE} NAME_WE )
238
+ add_test ( NAME regression-${JSON_STEM} .json
239
+ WORKING_DIRECTORY ${DATA_DIR}
240
+ COMMAND ${DIFF} -q ${JSON_STEM} .json ${CMAKE_SOURCE_DIR} /files /${JSON_STEM} .json )
241
+ set_property ( TEST regression-${JSON_STEM} .json
242
+ APPEND
243
+ PROPERTY
244
+ DEPENDS ${UNIT_TESTS}
245
+ REQUIRED_FILES ${JSON_FILES} )
246
+ endforeach ( JSON_FILE )
247
+ else ()
248
+ message ( WARNING
249
+ "For full test coverage diff, or a similar tool must be present on your system" )
250
+ endif ()
251
+
252
+ endif ()
282
253
283
254
#-------------------------
284
255
# Perform the installation
@@ -292,7 +263,7 @@ install ( TARGETS ${LIB_NAME} ${LIB_NAME}-static
292
263
# Code to fix the dylib install name on Mac.
293
264
include ( cmake/fixupInstallNameDir.cmake )
294
265
295
- install ( DIRECTORY "${CMAKE_Fortran_MODULE_DIRECTORY } /" DESTINATION "${INSTALL_MOD_DIR} " )
266
+ install ( DIRECTORY "${MODULE_DIR } /" DESTINATION "${INSTALL_MOD_DIR} " )
296
267
297
268
#------------------------------------------
298
269
# Add portable unistall command to makefile
@@ -345,4 +316,4 @@ set ( ENABLE_BUILD_TREE_EXPORT FALSE CACHE BOOL
345
316
"Add the ${PACKAGE_NAME} build tree to the CMake package registry?" )
346
317
if ( ENABLE_BUILD_TREE_EXPORT )
347
318
export ( PACKAGE ${PACKAGE_NAME} )
348
- endif ( ENABLE_BUILD_TREE_EXPORT )
319
+ endif ()
0 commit comments