|
1 | 1 | # CMake version, project name, language |
2 | 2 | cmake_minimum_required(VERSION 3.20) |
3 | | -project(neural-fortran Fortran) |
4 | | - |
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 | 3 |
|
11 | 4 | # If build type not specified, default to release |
12 | 5 | if(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") |
20 | 7 | endif() |
21 | 8 |
|
22 | | -find_package(HDF5 COMPONENTS Fortran HL) |
23 | | -include_directories(${HDF5_INCLUDE_DIRS}) |
24 | | - |
25 | | -include(FetchContent) |
26 | | - |
27 | | -FetchContent_Declare( |
28 | | - h5fortran |
29 | | - GIT_REPOSITORY https://github.com/geospace-code/h5fortran |
30 | | - GIT_TAG v4.6.3 |
| 9 | +project(neural-fortran |
| 10 | +LANGUAGES C Fortran |
31 | 11 | ) |
32 | 12 |
|
33 | | -FetchContent_Declare( |
34 | | - jsonfortran |
35 | | - GIT_REPOSITORY https://github.com/jacobwilliams/json-fortran |
36 | | - GIT_TAG 8.3.0 |
37 | | -) |
38 | | - |
39 | | -FetchContent_MakeAvailable(h5fortran jsonfortran) |
40 | | - |
41 | | -file(MAKE_DIRECTORY ${h5fortran_BINARY_DIR}/include) |
42 | | -include_directories(${h5fortran_BINARY_DIR}/include) |
43 | | - |
44 | | -file(MAKE_DIRECTORY ${jsonfortran_BINARY_DIR}/include) |
45 | | -include_directories(${jsonfortran_BINARY_DIR}) |
46 | | - |
47 | | -# compiler flags for gfortran |
48 | | -if(CMAKE_Fortran_COMPILER_ID MATCHES GNU) |
49 | | - |
50 | | - if(SERIAL) |
51 | | - message(STATUS "Configuring to build with -fcoarray=single") |
52 | | - set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fcoarray=single") |
53 | | - endif() |
54 | | - |
55 | | - if(BLAS) |
56 | | - set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fexternal-blas ${BLAS}") |
57 | | - set(LIBS "${LIBS} blas") |
58 | | - message(STATUS "Configuring build to use BLAS from ${BLAS}") |
59 | | - endif() |
60 | | - |
61 | | - set(CMAKE_Fortran_FLAGS_DEBUG "-O0 -g -fcheck=bounds -fbacktrace") |
62 | | - set(CMAKE_Fortran_FLAGS_RELEASE "-Ofast -fno-frontend-optimize") |
63 | | -endif() |
64 | | - |
65 | | -# compiler flags for ifort |
66 | | -if(CMAKE_Fortran_COMPILER_ID MATCHES Intel) |
67 | | - |
68 | | - if(SERIAL) |
69 | | - message(STATUS "Configuring to build with -coarray=single") |
70 | | - set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -coarray=single") |
71 | | - endif() |
| 13 | +enable_testing() |
72 | 14 |
|
73 | | - set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -assume byterecl") |
74 | | - set(CMAKE_Fortran_FLAGS_DEBUG "-O0 -g -C -traceback") |
75 | | - set(CMAKE_Fortran_FLAGS_RELEASE "-O3") |
| 15 | +include(FetchContent) |
76 | 16 |
|
77 | | - if(NOT SERIAL) |
78 | | - set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -coarray=shared") |
79 | | - endif() |
| 17 | +include(cmake/options.cmake) |
| 18 | +include(cmake/compilers.cmake) |
80 | 19 |
|
81 | | -endif() |
82 | | - |
83 | | -# compiler flags for Cray ftn |
84 | | -if(CMAKE_Fortran_COMPILER_ID MATCHES Cray) |
85 | | - set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -h noomp") |
86 | | - set(CMAKE_Fortran_FLAGS_DEBUG "-O0 -g") |
87 | | - set(CMAKE_Fortran_FLAGS_RELEASE "-O3") |
88 | | -endif() |
| 20 | +include(cmake/h5fortran.cmake) |
| 21 | +include(cmake/json.cmake) |
89 | 22 |
|
90 | 23 | # library to archive (libneural.a) |
91 | 24 | add_library(neural |
@@ -129,19 +62,17 @@ add_library(neural |
129 | 62 | src/nf/io/nf_io_hdf5.f90 |
130 | 63 | src/nf/io/nf_io_hdf5_submodule.f90 |
131 | 64 | ) |
| 65 | +target_link_libraries(neural PRIVATE h5fortran::h5fortran HDF5::HDF5 jsonfortran::jsonfortran) |
| 66 | + |
| 67 | +install(TARGETS neural) |
132 | 68 |
|
133 | 69 | # Remove leading or trailing whitespace |
134 | 70 | string(REGEX REPLACE "^ | $" "" LIBS "${LIBS}") |
135 | 71 |
|
136 | | -# tests |
137 | | -enable_testing() |
138 | | -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) |
139 | | - add_executable(test_${execid} test/test_${execid}.f90) |
140 | | - target_link_libraries(test_${execid} PRIVATE neural h5fortran::h5fortran jsonfortran ${LIBS}) |
141 | | - add_test(test_${execid} bin/test_${execid}) |
142 | | -endforeach() |
143 | | - |
144 | | -foreach(execid cnn mnist mnist_from_keras simple sine) |
145 | | - add_executable(${execid} example/${execid}.f90) |
146 | | - target_link_libraries(${execid} PRIVATE neural h5fortran::h5fortran jsonfortran ${LIBS}) |
147 | | -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