Skip to content

Commit bd7bda5

Browse files
committed
cmake: build tests,examples option (default on)
1 parent d6753e8 commit bd7bda5

File tree

4 files changed

+33
-11
lines changed

4 files changed

+33
-11
lines changed

CMakeLists.txt

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,10 @@ install(TARGETS neural)
6969
# Remove leading or trailing whitespace
7070
string(REGEX REPLACE "^ | $" "" LIBS "${LIBS}")
7171

72-
# tests
73-
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)
75-
add_executable(test_${execid} test/test_${execid}.f90)
76-
target_link_libraries(test_${execid} PRIVATE neural h5fortran::h5fortran jsonfortran::jsonfortran ${LIBS})
77-
add_test(test_${execid} bin/test_${execid})
78-
endforeach()
72+
if(${PROJECT_NAME}_BUILD_TESTING)
73+
add_subdirectory(test)
74+
endif()
7975

80-
foreach(execid cnn mnist mnist_from_keras simple sine)
81-
add_executable(${execid} example/${execid}.f90)
82-
target_link_libraries(${execid} PRIVATE neural h5fortran::h5fortran jsonfortran::jsonfortran ${LIBS})
83-
endforeach()
76+
if(${PROJECT_NAME}_BUILD_EXAMPLES)
77+
add_subdirectory(example)
78+
endif()

cmake/options.cmake

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
option(SERIAL "Serial execution")
2+
option(${PROJECT_NAME}_BUILD_TESTING "build ${PROJECT_NAME} tests" true)
3+
option(${PROJECT_NAME}_BUILD_EXAMPLES "build ${PROJECT_NAME} examples" true)
24

35
# Set output paths for modules, archives, and executables
46
set(CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/include)
@@ -11,3 +13,18 @@ if(SERIAL)
1113
else()
1214
message(STATUS "Configuring build for parallel execution")
1315
endif()
16+
17+
# --- Generally useful CMake project options
18+
19+
# Rpath options necessary for shared library install to work correctly in user projects
20+
set(CMAKE_INSTALL_NAME_DIR ${CMAKE_INSTALL_PREFIX}/lib)
21+
set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/lib)
22+
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH true)
23+
24+
# Necessary for shared library with Visual Studio / Windows oneAPI
25+
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS true)
26+
27+
# --- auto-ignore build directory
28+
if(NOT EXISTS ${PROJECT_BINARY_DIR}/.gitignore)
29+
file(WRITE ${PROJECT_BINARY_DIR}/.gitignore "*")
30+
endif()

example/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
foreach(execid cnn mnist mnist_from_keras simple sine)
2+
add_executable(${execid} ${execid}.f90)
3+
target_link_libraries(${execid} PRIVATE neural h5fortran::h5fortran jsonfortran::jsonfortran ${LIBS})
4+
endforeach()

test/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
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)
2+
add_executable(test_${execid} test_${execid}.f90)
3+
target_link_libraries(test_${execid} PRIVATE neural h5fortran::h5fortran jsonfortran::jsonfortran ${LIBS})
4+
5+
add_test(NAME test_${execid} COMMAND test_${execid})
6+
endforeach()

0 commit comments

Comments
 (0)