@@ -12,96 +12,13 @@ LANGUAGES C Fortran
12
12
13
13
enable_testing ()
14
14
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
-
29
15
include (FetchContent )
30
16
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 )
54
19
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 )
105
22
106
23
# library to archive (libneural.a)
107
24
add_library (neural
@@ -145,8 +62,9 @@ add_library(neural
145
62
src/nf/io/nf_io_hdf5.f90
146
63
src/nf/io/nf_io_hdf5_submodule.f90
147
64
)
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 )
150
68
151
69
# Remove leading or trailing whitespace
152
70
string (REGEX REPLACE "^ | $" "" LIBS "${LIBS} " )
@@ -155,11 +73,11 @@ string(REGEX REPLACE "^ | $" "" LIBS "${LIBS}")
155
73
156
74
foreach (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 )
157
75
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} )
159
77
add_test (test_${execid} bin/test_${execid} )
160
78
endforeach ()
161
79
162
80
foreach (execid cnn mnist mnist_from_keras simple sine )
163
81
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} )
165
83
endforeach ()
0 commit comments