Skip to content

Commit

Permalink
cpu_count: work with Visual Studio, single target
Browse files Browse the repository at this point in the history
  • Loading branch information
scivision committed Jul 29, 2022
1 parent bfd0d1c commit 423f87c
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 14 deletions.
16 changes: 12 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,18 @@ DESCRIPTION "Lightweight object-oriented HDF5 MPI parallel Fortran interface"
HOMEPAGE_URL https://github.com/geospace-code/h5fortran-mpi
)

include(CTest)
enable_testing()

if(NOT DEFINED ${PROJECT_NAME}_BUILD_TESTING)
set(${PROJECT_NAME}_BUILD_TESTING ${BUILD_TESTING})
if(DEFINED BUILD_TESTING)
set(${PROJECT_NAME}_BUILD_TESTING ${BUILD_TESTING})
else()
set(${PROJECT_NAME}_BUILD_TESTING true)
endif()
endif()

if(benchmark)
set(${PROJECT_NAME}_BUILD_TESTING true)
endif()

if(${PROJECT_NAME}_BUILD_TESTING)
Expand Down Expand Up @@ -76,11 +85,10 @@ if(${PROJECT_NAME}_BUILD_TESTING)
add_subdirectory(test)
endif()

if(ENABLE_BENCHMARKS)
if(benchmark)
add_subdirectory(benchmark)
endif()


# additional Find*.cmake necessary
install(FILES
${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/FindHDF5.cmake
Expand Down
4 changes: 2 additions & 2 deletions benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ add_library(partition OBJECT partition.f90)

add_library(cli OBJECT cli.f90)

add_executable(runner frontend.f90 cpu_count.cpp)
add_executable(runner frontend.f90)
target_include_directories(runner PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(runner PRIVATE partition cli)
target_link_libraries(runner PRIVATE partition cli cpu_count)
if(CMAKE_Fortran_COMPILER_ID MATCHES "^Intel")
set_property(TARGET runner PROPERTY LINKER_LANGUAGE Fortran)
else()
Expand Down
2 changes: 1 addition & 1 deletion cmake/compilers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ $<$<COMPILE_LANGUAGE:Fortran>:-fimplicit-none>
endif()

# --- code coverage
if(ENABLE_COVERAGE)
if(coverage)
include(CodeCoverage)
append_coverage_compiler_flags()
set(COVERAGE_EXCLUDES ${PROJECT_SOURCE_DIR}/test)
Expand Down
4 changes: 2 additions & 2 deletions cmake/options.cmake
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
message(STATUS "${PROJECT_NAME} ${PROJECT_VERSION} CMake ${CMAKE_VERSION}")

option(ENABLE_BENCHMARKS "write / read benchmarks")
option(ENABLE_COVERAGE "Code coverage tests")
option(benchmark "Run benchmarks")
option(coverage "Code coverage tests")
option(hdf5_parallel "use HDF5-MPI layer" true)

set(CMAKE_TLS_VERIFY true)
Expand Down
4 changes: 2 additions & 2 deletions codemeta.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
"@type": "SoftwareSourceCode",
"codeRepository": "https://github.com/geospace-code/h5fortran-mpi",
"contIntegration": "https://github.com/geospace-code/h5fortran-mpi/actions",
"dateModified": "2022-07-28",
"dateModified": "2022-07-29",
"downloadUrl": "https://github.com/geospace-code/h5fortran-mpi/releases",
"issueTracker": "https://github.com/geospace-code/h5fortran-mpi/issues",
"name": "h5fortran-mpi",
"version": "2.0.1",
"version": "2.0.2",
"identifier": "10.5281/zenodo.5847354",
"description": "Lightweight object-oriented HDF5-MPI parallel Fortran interface",
"applicationCategory": "file I/O",
Expand Down
2 changes: 1 addition & 1 deletion fpm.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "h5fortran-mpi"
description = "Lightweight object-oriented HDF5 MPI parallel interface"
categories = "io"
version = "2.0.0"
version = "2.0.2"

[build]
auto-tests = false
Expand Down
7 changes: 6 additions & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
add_library(cpu_count OBJECT cpu_count.cpp)
target_compile_features(cpu_count PRIVATE cxx_std_11)
target_compile_definitions(cpu_count PRIVATE $<$<BOOL:${MSVC}>:_CRT_SECURE_NO_WARNINGS>)
target_include_directories(cpu_count PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

# --- Python h5py
find_package(Python COMPONENTS Interpreter)
if(NOT DEFINED h5py_ok)
Expand Down Expand Up @@ -29,7 +34,7 @@ if(hdf5_parallel)
add_subdirectory(mpi)
endif()

if(ENABLE_COVERAGE)
if(coverage)
setup_target_for_coverage_gcovr_html(
NAME coverage
EXECUTABLE ${CMAKE_CTEST_COMMAND}
Expand Down
1 change: 1 addition & 0 deletions benchmark/cpu_count.cpp → test/cpu_count.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <thread>

#ifdef _WIN32
#define NOMINMAX
#include <windows.h>
#elif defined (__APPLE__)
#include <sys/sysctl.h>
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion test/mpi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ endfunction(mpi_test)
# --- test files

add_executable(test_runner runner.f90
${PROJECT_SOURCE_DIR}/benchmark/cpu_count.cpp
${PROJECT_SOURCE_DIR}/benchmark/partition.f90
${PROJECT_SOURCE_DIR}/benchmark/cli.f90
)
target_include_directories(test_runner PRIVATE ${PROJECT_SOURCE_DIR}/benchmark)
target_link_libraries(test_runner PRIVATE cpu_count)
# not linked as libraries in case benchmarks aren't built
if(CMAKE_Fortran_COMPILER_ID MATCHES "^Intel")
set_property(TARGET test_runner PROPERTY LINKER_LANGUAGE Fortran)
Expand Down

0 comments on commit 423f87c

Please sign in to comment.