Skip to content

Commit 1ef6f16

Browse files
committed
Clean references to json_example
- PR #64 removed json_example, but some references to it still exist in a few places - Small CMake bug fixed for compiling other projects against the uninstalled json-fortran build tree.
1 parent 7f2cbf6 commit 1ef6f16

File tree

4 files changed

+25
-20
lines changed

4 files changed

+25
-20
lines changed

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,12 @@ endif ()
151151
# Handle test related stuff
152152
#--------------------------
153153
set ( ENABLE_TESTS TRUE CACHE BOOL
154-
"Enable the json-fortran tests. If true this will force build of example program too" )
154+
"Enable the json-fortran tests." )
155155

156156
#---------------------------------------------------------------------
157157
# Add some tests to ensure that the software is performing as expected
158158
#---------------------------------------------------------------------
159-
if ( ENABLE_TESTS ) # BUILD_EXAMPLE_PROGRAM will be true too
159+
if ( ENABLE_TESTS )
160160
enable_testing()
161161

162162
find_program ( JSONLINT jsonlint )

README.md

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ compiler](http://gcc.gnu.org/wiki/GFortran/News#GCC4.9).
3636
Currently, several ways are provided to build the jsonfortran library
3737
(libjsonfortran).
3838

39-
* A build script, `build.sh` is provided in the project root directory. This script uses [FoBiS](https://github.com/szaghi/FoBiS) to build the json-fortran library and the example program. Edit the script to use either the [Intel Fortran Compiler](https://software.intel.com/en-us/fortran-compilers) or [Gfortran](https://gcc.gnu.org/wiki/GFortran). Note that version 1.2.5 of FoBiS (or later) is required.
39+
* A build script, `build.sh` is provided in the project root directory. This script uses [FoBiS](https://github.com/szaghi/FoBiS) to build the json-fortran library and the unit tests. Edit the script to use either the [Intel Fortran Compiler](https://software.intel.com/en-us/fortran-compilers) or [Gfortran](https://gcc.gnu.org/wiki/GFortran). Note that version 1.2.5 of FoBiS (or later) is required.
4040

41-
* A [Visual Studio](http://www.visualstudio.com) project is included for building the library (and example program) on Windows with the Intel Fortran Compiler. The project has been tested with Visual Studio 2010 and 2013.
41+
* A [Visual Studio](http://www.visualstudio.com) project is included for building the library (and unit tests) on Windows with the Intel Fortran Compiler. The project has been tested with Visual Studio 2010 and 2013.
4242

43-
* An [SCons](http://www.scons.org) `SConstruct` file. The library and example program are built by typing `scons` and installed by `scons install` or `sudo scons install`.
43+
* An [SCons](http://www.scons.org) `SConstruct` file. The library and unit tests are built by typing `scons` and tested by typing `scons test`. The library may be optionally installed by `scons install` or `sudo scons install`.
4444

4545
* Additionally, a [CMake](http://www.cmake.org) build
4646
system is provided. This build system has been tested on Mac and Linux
@@ -53,28 +53,33 @@ environment variable `FC` to point to your Fortran compiler, and
5353
create a build directory. Then `(cmake-gui|ccmake|cmake)
5454
/path/to/json-fortran-root` to configure, `make` to build and `make
5555
install` to optionally install. As long as the project is built with
56-
CMake, other CMake projects can find it and link against it:
56+
CMake, other CMake projects can find it and link against it. For example,
57+
if you have a second copy of the json-fortran project tree, and want to build the unit tests
58+
linking against those compiled/installed by the first copy:
5759

5860
```CMake
59-
cmake_minimum_required ( VERSION 2.8 FATAL_ERROR )
61+
cmake_minimum_required ( VERSION 2.8.8 FATAL_ERROR )
6062
enable_language ( Fortran )
6163
project ( jf_test NONE )
6264
6365
find_package ( jsonfortran-${CMAKE_Fortran_COMPILER_ID} 3.0.0 REQUIRED )
6466
65-
add_executable ( json_example src/json_example.f90 )
66-
target_include_directories ( json_example BEFORE PUBLIC ${jsonfortran_INCLUDE_DIRS} )
67-
target_link_libraries ( json_example jsonfortran-static )
68-
# or for linking against the dynamic/shared library:
69-
# target_link_libraries ( json_example jsonfortran ) # instead
67+
file ( GLOB JF_TEST_SRCS "src/tests/jf_test_*.f90" )
68+
foreach ( UNIT_TEST ${JF_TEST_SRCS} )
69+
get_filename_component ( TEST ${UNIT_TEST} NAME_WE )
70+
add_executable ( ${TEST} ${UNIT_TEST} )
71+
target_link_libraries ( ${TEST} jsonfortran-static )
72+
# or for linking against the dynamic/shareed library:
73+
# target_link_libraries ( ${TEST} jsonfortran ) # instead
74+
endforeach()
7075
```
7176

7277
Reading JSON from a file
7378
---------------
7479

7580
Reading a JSON file and getting data from it is fairly
76-
straightforward using the ```json_file``` class. Here is an example. See the json_example.f90 file
77-
for more examples.
81+
straightforward using the `json_file` class. Here is an example. See unit tests 1 and 3-6
82+
for more examples. The source files may be found in `src/tests/`.
7883

7984
```fortran
8085
program example1
@@ -116,7 +121,7 @@ JSON can also be read directly from a character string like so:
116121
Modifying variables in a JSON file
117122
---------------
118123

119-
After reading a JSON file, if you want to change the values of some of the variables, you can use the ```update``` method. For the example above:
124+
After reading a JSON file, if you want to change the values of some of the variables, you can use the `update` method. For the example above:
120125

121126
```fortran
122127
! [found can be used to check if the data was really there]
@@ -128,7 +133,7 @@ After reading a JSON file, if you want to change the values of some of the varia
128133
Writing a JSON file
129134
---------------
130135

131-
To print the JSON file (either to a file or the console), the ```print_file``` method can be used. For the above example:
136+
To print the JSON file (either to a file or the console), the `print_file` method can be used. For the above example:
132137

133138
```fortran
134139
call json%print_file() !prints to the console
@@ -139,7 +144,7 @@ Building a JSON file from scratch
139144
---------------
140145

141146
Constructing a JSON file element by element is slightly more complicated and involves the use
142-
of ```json_value``` pointers. See the json_example.f90 file for more examples.
147+
of `json_value` pointers. For more examples see unit tests 2,4 and 7 in `src/tests/`.
143148

144149
```fortran
145150
program example2
@@ -183,7 +188,7 @@ of ```json_value``` pointers. See the json_example.f90 file for more examples.
183188

184189
The code above produces the file:
185190

186-
```Python
191+
```JSON
187192
{
188193
"inputs": {
189194
"t0": 0.1E+0,

build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22

33
#
4-
# Build the json-fortran library and example program.
4+
# Build the json-fortran library and unit tests.
55
#
66
# Requires:
77
# FoBiS.py : https://github.com/szaghi/FoBiS [version 1.2.5 or later required]

cmake/jsonfortran-config.cmake.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ set ( @CMAKE_PROJECT_NAME@_VERSION @VERSION@ )
1212
include ( "@CMAKE_BINARY_DIR@/@[email protected]" )
1313

1414
# Tell the compiler where to find the mod files
15-
set ( @CMAKE_PROJECT_NAME@_INCLUDE_DIRS "@CMAKE_Fortran_MODULE_DIRECTORY@" )
15+
set ( @CMAKE_PROJECT_NAME@_INCLUDE_DIRS "@MODULE_DIR@" )

0 commit comments

Comments
 (0)