1- # cmake version, project name, language
2- cmake_minimum_required (VERSION 2.8 FATAL_ERROR)
3- project (neural-fortran Fortran)
1+ # CMake version, project name, language
2+ cmake_minimum_required (VERSION 3.20)
43
5- # set output paths for modules, archives, and executables
6- set (CMAKE_Fortran_MODULE_DIRECTORY ${PROJECT_BINARY_DIR} /include )
7- set (CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} /lib)
8- set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} /lib)
9- set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} /bin)
10-
11- # if build type not specified, default to release
4+ # If build type not specified, default to release
125if (NOT CMAKE_BUILD_TYPE )
13- set (CMAKE_BUILD_TYPE "release" )
14- endif ()
15-
16- if (SERIAL)
17- message (STATUS "Configuring build for serial execution" )
18- else ()
19- message (STATUS "Configuring build for parallel execution" )
6+ set (CMAKE_BUILD_TYPE "Release" CACHE STRING "Default build Release" )
207endif ()
218
22- # compiler flags for gfortran
23- if (CMAKE_Fortran_COMPILER_ID MATCHES GNU)
24-
25- if (SERIAL)
26- message (STATUS "Configuring to build with -fcoarray=single" )
27- set (CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fcoarray=single" )
28- endif ()
29-
30- if (BLAS)
31- set (CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fexternal-blas ${BLAS} " )
32- set (LIBS "${LIBS} blas" )
33- message (STATUS "Configuring build to use BLAS from ${BLAS} " )
34- endif ()
35-
36- set (CMAKE_Fortran_FLAGS_DEBUG "-O0 -g -fcheck=bounds -fbacktrace" )
37- set (CMAKE_Fortran_FLAGS_RELEASE "-Ofast -fno-frontend-optimize" )
38- endif ()
39-
40- # compiler flags for ifort
41- if (CMAKE_Fortran_COMPILER_ID MATCHES Intel)
42-
43- if (SERIAL)
44- message (STATUS "Configuring to build with -coarray=single" )
45- set (CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -coarray=single" )
46- endif ()
9+ project (neural-fortran
10+ LANGUAGES C Fortran
11+ )
4712
48- set (CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -assume byterecl" )
49- set (CMAKE_Fortran_FLAGS_DEBUG "-O0 -g -C -traceback" )
50- set (CMAKE_Fortran_FLAGS_RELEASE "-O3" )
13+ enable_testing ()
5114
52- if (NOT SERIAL)
53- set (CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -coarray=shared" )
54- endif ()
15+ include (FetchContent)
5516
56- endif ()
17+ include (cmake/options .cmake)
18+ include (cmake/compilers.cmake)
5719
58- # compiler flags for Cray ftn
59- if (CMAKE_Fortran_COMPILER_ID MATCHES Cray)
60- set (CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -h noomp" )
61- set (CMAKE_Fortran_FLAGS_DEBUG "-O0 -g" )
62- set (CMAKE_Fortran_FLAGS_RELEASE "-O3" )
63- endif ()
20+ include (cmake/h5fortran.cmake)
21+ include (cmake/json.cmake)
6422
6523# library to archive (libneural.a)
6624add_library (neural
@@ -70,6 +28,8 @@ add_library(neural
7028 src/nf/nf_base_layer_submodule.f90
7129 src/nf/nf_conv2d_layer.f90
7230 src/nf/nf_conv2d_layer_submodule.f90
31+ src/nf/nf_datasets.f90
32+ src/nf/nf_datasets_submodule.f90
7333 src/nf/nf_datasets_mnist.f90
7434 src/nf/nf_datasets_mnist_submodule.f90
7535 src/nf/nf_dense_layer.f90
@@ -80,8 +40,8 @@ add_library(neural
8040 src/nf/nf_input1d_layer_submodule.f90
8141 src/nf/nf_input3d_layer.f90
8242 src/nf/nf_input3d_layer_submodule.f90
83- src/nf/nf_io .f90
84- src/nf/nf_io_submodule .f90
43+ src/nf/nf_keras .f90
44+ src/nf/nf_keras_submodule .f90
8545 src/nf/nf_layer_constructors.f90
8646 src/nf/nf_layer_constructors_submodule.f90
8747 src/nf/nf_layer.f90
@@ -97,20 +57,22 @@ add_library(neural
9757 src/nf/nf_parallel_submodule.f90
9858 src/nf/nf_random.f90
9959 src/nf/nf_random_submodule.f90
60+ src/nf/io/nf_io_binary.f90
61+ src/nf/io/nf_io_binary_submodule.f90
62+ src/nf/io/nf_io_hdf5.f90
63+ src/nf/io/nf_io_hdf5_submodule.f90
10064)
65+ target_link_libraries (neural PRIVATE h5fortran::h5fortran HDF5::HDF5 jsonfortran::jsonfortran)
66+
67+ install (TARGETS neural)
10168
10269# Remove leading or trailing whitespace
10370string (REGEX REPLACE "^ | $" "" LIBS "${LIBS} " )
10471
105- # tests
106- enable_testing ()
107- foreach (execid input1d_layer input3d_layer dense_layer conv2d_layer maxpool2d_layer flatten_layer dense_network conv2d_network)
108- add_executable (test_${execid} test /test_${execid} .f90)
109- target_link_libraries (test_${execid} neural ${LIBS} )
110- add_test (test_${execid} bin/test_${execid} )
111- endforeach ()
112-
113- foreach (execid cnn mnist simple sine)
114- add_executable (${execid} example/${execid} .f90)
115- target_link_libraries (${execid} neural ${LIBS} )
116- endforeach ()
72+ if (${PROJECT_NAME} _BUILD_TESTING)
73+ add_subdirectory (test )
74+ endif ()
75+
76+ if (${PROJECT_NAME} _BUILD_EXAMPLES)
77+ add_subdirectory (example)
78+ endif ()
0 commit comments