@@ -12,96 +12,13 @@ LANGUAGES C Fortran
1212
1313enable_testing ()
1414
15- option (SERIAL "Serial execution" )
16-
17- # Set output paths for modules, archives, and executables
18- set (CMAKE_Fortran_MODULE_DIRECTORY ${PROJECT_BINARY_DIR} /include )
19- set (CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} /lib)
20- set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} /lib)
21- set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} /bin)
22-
23- if (SERIAL)
24- message (STATUS "Configuring build for serial execution" )
25- else ()
26- message (STATUS "Configuring build for parallel execution" )
27- endif ()
28-
2915include (FetchContent)
3016
31- set (h5fortran_BUILD_TESTING false )
32-
33- FetchContent_Declare(
34- h5fortran
35- GIT_REPOSITORY https://github.com/geospace-code/h5fortran
36- GIT_TAG v4.6.3
37- GIT_SHALLOW true
38- )
39-
40- FetchContent_Declare(
41- jsonfortran
42- GIT_REPOSITORY https://github.com/jacobwilliams/json-fortran
43- GIT_TAG 8.3.0
44- GIT_SHALLOW true
45- )
46-
47- FetchContent_MakeAvailable(h5fortran jsonfortran)
48-
49- file (MAKE_DIRECTORY ${h5fortran_BINARY_DIR} /include )
50- include_directories (${h5fortran_BINARY_DIR} /include )
51-
52- file (MAKE_DIRECTORY ${jsonfortran_BINARY_DIR} /include )
53- include_directories (${jsonfortran_BINARY_DIR} )
17+ include (cmake/options .cmake)
18+ include (cmake/compilers.cmake)
5419
55- list (APPEND CMAKE_MODULE_PATH ${h5fortran_SOURCE_DIR} /cmake/Modules)
56- find_package (HDF5 COMPONENTS Fortran REQUIRED)
57-
58- # compiler flags for gfortran
59- if (CMAKE_Fortran_COMPILER_ID STREQUAL "GNU" )
60-
61- if (SERIAL)
62- message (STATUS "Configuring to build with -fcoarray=single" )
63- add_compile_options ("$<$<COMPILE_LANGUAGE:Fortran>:-fcoarray=single>" )
64- else ()
65- add_compile_options ("$<$<COMPILE_LANGUAGE:Fortran>:-fcoarray=lib>" )
66- endif ()
67-
68- if (BLAS)
69- add_compile_options ("$<$<COMPILE_LANGUAGE:Fortran>:-fexternal-blas;${BLAS} >" )
70- list (APPEND LIBS "blas" )
71- message (STATUS "Configuring build to use BLAS from ${BLAS} " )
72- endif ()
73-
74- add_compile_options ("$<$<AND:$<COMPILE_LANGUAGE:Fortran>,$<CONFIG:Debug>>:-fcheck=bounds;-fbacktrace>" )
75- add_compile_options ("$<$<AND:$<COMPILE_LANGUAGE:Fortran>,$<CONFIG:Release>>:-Ofast;-fno-frontend-optimize;-fno-backtrace>" )
76-
77- elseif (CMAKE_Fortran_COMPILER_ID MATCHES "^Intel" )
78- # compiler flags for ifort
79-
80- if (SERIAL)
81- message (STATUS "Configuring to build with -coarray=single" )
82- if (WIN32 )
83- add_compile_options ("$<$<COMPILE_LANGUAGE:Fortran>:/Qcoarray:single>" )
84- else ()
85- add_compile_options ("$<$<COMPILE_LANGUAGE:Fortran>:-coarray=single>" )
86- endif ()
87- else ()
88- if (WIN32 )
89- add_compile_options ("$<$<COMPILE_LANGUAGE:Fortran>:/Qcoarray:shared>" )
90- else ()
91- add_compile_options ("$<$<COMPILE_LANGUAGE:Fortran>:-coarray=shared>" )
92- endif ()
93- endif ()
94-
95- string (APPEND CMAKE_Fortran_FLAGS " -assume byterecl" )
96- add_compile_options ("$<$<AND:$<COMPILE_LANGUAGE:Fortran>,$<CONFIG:Debug>>:-check;-traceback>" )
97- # add_compile_options("$<$<AND:$<COMPILE_LANGUAGE:Fortran>,$<CONFIG:Release>>:-O3>")
98-
99- elseif (CMAKE_Fortran_COMPILER_ID STREQUAL "Cray" )
100- # compiler flags for Cray ftn
101- string (APPEND CMAKE_Fortran_FLAGS " -h noomp" )
102- add_compile_options ("$<$<AND:$<COMPILE_LANGUAGE:Fortran>,$<CONFIG:Debug>>:-O0;-g>" )
103- add_compile_options ("$<$<AND:$<COMPILE_LANGUAGE:Fortran>,$<CONFIG:Release>>:-O3>" )
104- endif ()
20+ include (cmake/h5fortran.cmake)
21+ include (cmake/json.cmake)
10522
10623# library to archive (libneural.a)
10724add_library (neural
@@ -145,8 +62,9 @@ add_library(neural
14562 src/nf/io/nf_io_hdf5.f90
14663 src/nf/io/nf_io_hdf5_submodule.f90
14764)
148- target_link_libraries (neural PRIVATE h5fortran::h5fortran HDF5::HDF5)
149- target_include_directories (neural PRIVATE ${jsonfortran_BINARY_DIR} /include )
65+ target_link_libraries (neural PRIVATE h5fortran::h5fortran HDF5::HDF5 jsonfortran::jsonfortran)
66+
67+ install (TARGETS neural)
15068
15169# Remove leading or trailing whitespace
15270string (REGEX REPLACE "^ | $" "" LIBS "${LIBS} " )
@@ -155,11 +73,11 @@ string(REGEX REPLACE "^ | $" "" LIBS "${LIBS}")
15573
15674foreach (execid input1d_layer input3d_layer dense_layer conv2d_layer maxpool2d_layer flatten_layer dense_network dense_network_from_keras conv2d_network io_hdf5 keras_read_model)
15775 add_executable (test_${execid} test /test_${execid} .f90)
158- target_link_libraries (test_${execid} PRIVATE neural h5fortran::h5fortran jsonfortran ${LIBS} )
76+ target_link_libraries (test_${execid} PRIVATE neural h5fortran::h5fortran jsonfortran::jsonfortran ${LIBS} )
15977 add_test (test_${execid} bin/test_${execid} )
16078endforeach ()
16179
16280foreach (execid cnn mnist mnist_from_keras simple sine)
16381 add_executable (${execid} example/${execid} .f90)
164- target_link_libraries (${execid} PRIVATE neural h5fortran::h5fortran jsonfortran ${LIBS} )
82+ target_link_libraries (${execid} PRIVATE neural h5fortran::h5fortran jsonfortran::jsonfortran ${LIBS} )
16583endforeach ()
0 commit comments