Skip to content

Commit a99966c

Browse files
committed
build.sh and CMake added option for Unicode support
- If user requests unicode support then: - Attempt to compile and run test program to determine compiler support for iso 10646 - If support preprocess code to enable unicode support - If not supported by compiler or not requested use default character encoding
1 parent 88a8a04 commit a99966c

File tree

3 files changed

+68
-5
lines changed

3 files changed

+68
-5
lines changed

CMakeLists.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ set ( VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}" )
4343
#-------------------------------------
4444
set ( JF_LIB_SRCS src/json_module.F90 )
4545
file ( GLOB JF_TEST_SRCS "src/tests/jf_test_*.f90" )
46+
set ( JF_TEST_UCS4_SUPPORT_SRC "${CMAKE_SOURCE_DIR}/src/tests/introspection/test_iso_10646_support.f90")
4647

4748
#-----------------------------------------
4849
# Collect all the mod files into their own
@@ -83,6 +84,22 @@ else ()
8384
"${ABS_LIB_INSTALL_DIR}" )
8485
endif ()
8586

87+
#---------------------------------------------
88+
# See if our compiler supports ISO 10646/UCS4
89+
#---------------------------------------------
90+
set ( ENABLE_UNICODE FLASE CACHE BOOL
91+
"Enable unicode/UCS4 support" )
92+
if ( ENABLE_UNICODE )
93+
try_run( UCS4_TEST_RUNS UCS4_TEST_COMPILES
94+
${CMAKE_BINARY_DIR}/bin ${JF_TEST_UCS4_SUPPORT_SRC} )
95+
if (UCS4_TEST_RUNS EQUAL 0)
96+
add_definitions (-DUSE_UCS4)
97+
else ()
98+
message ( WARNING
99+
"Unicode support requested but ${CMAKE_Fortran_COMPILER_ID} Fortran compiler does not support 'ISO_10646' characters!" )
100+
endif ()
101+
endif ()
102+
86103
#---------------------------------------------
87104
# Build a shared and static library by default
88105
#---------------------------------------------

build.sh

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ PROJECTNAME='jsonfortran' # project name for robodoc (example: jsonfortran
2525
DOCDIR='./documentation/' # build directory for documentation
2626
SRCDIR='./src/' # library source directory
2727
TESTDIR='./src/tests/' # unit test source directory
28+
INTROSPECDIR='./src/tests/introspection/' # pre compile configuration tests directory
29+
UCS4TESTCODE='test_iso_10646_support.f90'
2830
BINDIR='./bin/' # build directory for unit tests
2931
LIBDIR='./lib/' # build directory for library
3032
MODCODE='json_module.F90' # json module file name
@@ -35,10 +37,10 @@ LIBOUT='libjsonfortran.a' # name of json library
3537
# warning #7601: F2008 standard does not allow an internal procedure to be an actual argument procedure name. (R1214.4).
3638
# In the context of F2008 this is an erroneous warning.
3739
# See https://prd1idz.cps.intel.com/en-us/forums/topic/486629
38-
INTELCOMPILERFLAGS='-c -O2 -warn -stand f08 -diag-disable 7601 -traceback'
40+
INTELCOMPILERFLAGS='-c -O2 -warn -stand f08 -diag-disable 7601 -diag-disable 4013 -traceback'
3941
#INTELCOMPILERFLAGS='-c -O2 -warn -traceback -stand f08 -assume protect_parens -assume buffered_io -check all'
4042

41-
GNUCOMPILERFLAGS='-c -O2 -fbacktrace -Wall -Wextra -Wno-maybe-uninitialized -pedantic -std=f2008'
43+
GNUCOMPILERFLAGS='-c -O2 -fbacktrace -Wall -Wextra -Wno-maybe-uninitialized -Wno-unused-function -pedantic -std=f2008'
4244

4345
FCOMPILER='gnu' #Set default compiler to gfortran
4446

@@ -55,7 +57,7 @@ print_usage () {
5557
echo -e "\n\nUsage:\n"
5658
echo -e "${script_name} [--compiler {intel|gnu|<other>}] [--cflags '<custom compiler flags here>']\n\
5759
[--coverage [{yes|no}]] [--profile [{yes|no}]] [--skip-tests [{yes|no}]]\n\
58-
[--skip-documentation [{yes|no}]] [--help]"
60+
[--skip-documentation [{yes|no}]] [--enable-unicode [{yes|no}]] [--help]"
5961
echo ""
6062
echo -e "Any flags that take an optional yes or no argument will default to 'yes' when no\n\
6163
argument is passed. Additionally, A custom compiler may be passed to the 'compiler'\n\
@@ -94,6 +96,22 @@ while [ "$#" -ge "1" ]; do # Get command line arguments while there are more lef
9496
# no good way to check that the user didn't do something questionable
9597
shift
9698
;;
99+
--enable-unicode)
100+
case $2 in
101+
yes|Yes|YES)
102+
TRY_UNICODE="yes"
103+
shift
104+
;;
105+
no|No|NO)
106+
TRY_UNICODE="no"
107+
shift
108+
;;
109+
*)
110+
TRY_UNICODE="yes"
111+
# don't shift; $2 is next arg
112+
;;
113+
esac
114+
;;
97115
--coverage) # enable coverage
98116
case $2 in
99117
yes|Yes|YES)
@@ -185,17 +203,26 @@ if [[ $CODE_PROFILE == [yY]* ]]; then
185203
fi
186204

187205
if [[ $FCOMPILER == custom ]]; then
206+
echo "Trying to compile with custom compiler, $FC"
188207
CUSTOM="-fc $FC"
189208
fi
190209

210+
if [[ $TRY_UNICODE == [yY]* ]]; then
211+
echo "Trying to compile library with Unicode/UCS4 support"
212+
FoBiS.py build -ch -compiler ${FCOMPILER} ${CUSTOM} -cflags "${FCOMPILERFLAGS}" -dbld "${BINDIR}" -s "${INTROSPECDIR}" -dmod ./ -dobj ./ -t ${UCS4TESTCODE} -o ${UCS4TESTCODE%.f90} -colors
213+
if "${BINDIR}/${UCS4TESTCODE%.f90}"; then
214+
DEFINES="-DUSE_UCS4 -Wunused-function"
215+
fi
216+
fi
217+
191218
#build the stand-alone library:
192219
echo ""
193220
echo "Building library..."
194221

195222
# work around for FoBiS.py PR #45
196223
[ -d "$LIBDIR" ] || mkdir "$LIBDIR"
197224

198-
FoBiS.py build -ch -compiler ${FCOMPILER} ${CUSTOM} -cflags "${FCOMPILERFLAGS}" ${COVERAGE} ${PROFILING} -dbld ${LIBDIR} -s ${SRCDIR} -dmod ./ -dobj ./ -t ${MODCODE} -o ${LIBOUT} -mklib static -colors
225+
FoBiS.py build -ch -compiler ${FCOMPILER} ${CUSTOM} -cflags "${FCOMPILERFLAGS} ${DEFINES}" ${COVERAGE} ${PROFILING} -dbld ${LIBDIR} -s ${SRCDIR} -dmod ./ -dobj ./ -t ${MODCODE} -o ${LIBOUT} -mklib static -colors
199226

200227
#build the unit tests (uses the above library):
201228
if [[ $JF_SKIP_TESTS != [yY]* ]]; then
@@ -208,7 +235,7 @@ if [[ $JF_SKIP_TESTS != [yY]* ]]; then
208235
for TEST in "${TESTDIR%/}"/jf_test_*.f90; do
209236
THIS_TEST=${TEST##*/}
210237
echo "Build ${THIS_TEST%.f90}"
211-
FoBiS.py build -ch -compiler ${FCOMPILER} ${CUSTOM} -cflags "${FCOMPILERFLAGS}" ${COVERAGE} ${PROFILING} -dbld ${BINDIR} -s ${TESTDIR} -i ${LIBDIR} -libs ${LIBDIR}/${LIBOUT} -dmod ./ -dobj ./ -t ${THIS_TEST} -o ${THIS_TEST%.f90} -colors
238+
FoBiS.py build -ch -compiler ${FCOMPILER} ${CUSTOM} -cflags "${FCOMPILERFLAGS} ${DEFINES}" ${COVERAGE} ${PROFILING} -dbld ${BINDIR} -s ${TESTDIR} -i ${LIBDIR} -libs ${LIBDIR}/${LIBOUT} -dmod ./ -dobj ./ -t ${THIS_TEST} -o ${THIS_TEST%.f90} -colors
212239
done
213240
else
214241
echo "Skip building the unit tests since \$JF_SKIP_TESTS has been set to 'true'."
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
! This program is run when configuring the json-fortran build,
2+
! to determine whether or not ISO 10646/UCS4 characters are
3+
! supported by the compiler
4+
program test_iso_10646_support
5+
use iso_fortran_env ,only: output_unit, error_unit
6+
implicit none
7+
integer, parameter :: UCS4_K = selected_char_kind('ISO_10646')
8+
9+
if ( UCS4_K == -1 ) then !Not supported!
10+
write(error_unit,'(A)') 'Your compiler does not support ISO 10646/UCS4 characters!'
11+
write(error_unit,'(A)') 'JSON-Fortran must/will be configured to use the "DEFAULT"'
12+
write(error_unit,'(A)') 'character set. (Should be "ASCII" on a reasonable system.)'
13+
stop 2
14+
else
15+
write(error_unit,'(A)') 'Congratulations! Your compiler supports ISO 10646/UCS4!'
16+
write(error_unit,'(A)') 'JSON-Fortran may be configured to enable UCS4 support.'
17+
write(output_unit,'(A)') 'UCS4_SUPPORTED'
18+
end if
19+
end program test_iso_10646_support

0 commit comments

Comments
 (0)