Skip to content

Commit

Permalink
reverting more netcdf changes
Browse files Browse the repository at this point in the history
  • Loading branch information
K20shores committed Nov 12, 2024
1 parent 332265b commit 2383fbd
Showing 1 changed file with 90 additions and 67 deletions.
157 changes: 90 additions & 67 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,29 @@ list(APPEND CMAKE_PREFIX_PATH
$ENV{GC_F_LIB} $ENV{GC_LIB}
)

#-----------------------------------------------------------------------------
# Link NetCDF-F to CloudJBuildProperties
#-----------------------------------------------------------------------------
find_package(NetCDF REQUIRED)
target_include_directories(CloudJBuildProperties
INTERFACE ${NETCDF_INCLUDE_DIRS}
)
target_link_libraries(CloudJBuildProperties
INTERFACE ${NETCDF_LIBRARIES}
)

#-----------------------------------------------------------------------------
# Use the NC_HAS_COMPRESSION def if nf_def_var_deflate is in netcdf.inc
#-----------------------------------------------------------------------------
if(EXISTS ${NETCDF_F77_INCLUDE_DIR}/netcdf.inc)
file(READ ${NETCDF_F77_INCLUDE_DIR}/netcdf.inc NCINC)
if("${NCINC}" MATCHES ".*nf_def_var_deflate.*")
target_compile_definitions(CloudJBuildProperties
INTERFACE "NC_HAS_COMPRESSION"
)
endif()
endif()

#-----------------------------------------------------------------------------
# Print a description of the source code repo's version
# (Needs more work to enable)
Expand Down Expand Up @@ -305,73 +328,73 @@ file(WRITE ${CMAKE_BINARY_DIR}/CloudJBuildProperties.txt
# -----------------------------------------------------------------------------
# Try to compile a simple program that uses NetCDF-Fortran and OpenMP
# -----------------------------------------------------------------------------
# if(NOT CLOUDJ_EXTERNAL_CONFIG AND NOT CLOUDJ_TRY_RUN_PASSED)

# # Format definitions with -D prefix
# set(TRY_RUN_LIBRARIES "")
# set(TRY_RUN_INCLUDE_DIRS "")
# set(TRY_RUN_COMPILER_FLAGS "")
# set(TRY_RUN_DEFINITIONS "")

# if(OMP)
# list(APPEND TRY_RUN_LIBRARIES ${OpenMP_Fortran_LIBRARIES})
# list(APPEND TRY_RUN_COMPILER_FLAGS ${OpenMP_Fortran_FLAGS})
# else()
# list(APPEND TRY_RUN_DEFINITIONS -DNO_OMP)
# endif()

# # Try to compile and run try_compile.F90
# try_run(RUN_FAILED COMPILED_OK
# ${CMAKE_CURRENT_BINARY_DIR}/try_compile # binary dir
# ${CMAKE_CURRENT_SOURCE_DIR}/CMakeScripts/try_compile.F90 # test src file
# LINK_LIBRARIES ${TRY_RUN_LIBRARIES}
# CMAKE_FLAGS "-DINCLUDE_DIRECTORIES=${TRY_RUN_INCLUDE_DIRS}" "-DCMAKE_Fortran_FLAGS=${TRY_RUN_COMPILER_FLAGS}"
# COMPILE_DEFINITIONS ${TRY_RUN_DEFINITIONS}
# COMPILE_OUTPUT_VARIABLE COMPILE_OUTPUT
# RUN_OUTPUT_VARIABLE RUN_OUTPUT
# )

# # Display a warning if its compilation failed
# if(NOT COMPILED_OK)
# if(OMP)
# set(CONDITIONAL_AND_OMP " and OpenMP")
# endif()
# message(WARNING
# "Failed to compile a simple program that uses "
# "NetCDF-Fortran ${CONDITIONAL_AND_OMP}! Could "
# "your NetCDF installation be broken?\nSee "
# "\"FailedCompile.txt\" for more info."
# )
# file(WRITE ${CMAKE_BINARY_DIR}/FailedCompile.txt
# "${COMPILE_OUTPUT}"
# )
# else()
# file(REMOVE ${CMAKE_BINARY_DIR}/FailedCompile.txt)
# endif()

# # Display a warning if its execution failed
# if(RUN_FAILED)
# if(OMP)
# set(CONDITIONAL_AND_OMP "and OpenMP ")
# endif()
# message(WARNING
# "A simple program that uses NetCDF-Fortran "
# "${CONDITIONAL_AND_OMP}compiled successfully, "
# "but its execution failed!\n\nSee "
# "\"FailedExecution.txt\" for more info."
# )
# file(WRITE ${CMAKE_BINARY_DIR}/FailedEasyRun.txt
# "${COMPILE_OUTPUT}\n${RUN_OUTPUT}"
# )
# else()
# file(REMOVE ${CMAKE_BINARY_DIR}/FailedEasyRun.txt
# ${CMAKE_BINARY_DIR}/simple_xy.nc
# )
# set(GC_TRY_RUN_PASSED TRUE CACHE INTERNAL
# "try_run passed" FORCE
# )
# endif()
# endif()
if(NOT CLOUDJ_EXTERNAL_CONFIG AND NOT CLOUDJ_TRY_RUN_PASSED)

# Format definitions with -D prefix
set(TRY_RUN_LIBRARIES "")
set(TRY_RUN_INCLUDE_DIRS "")
set(TRY_RUN_COMPILER_FLAGS "")
set(TRY_RUN_DEFINITIONS "")

if(OMP)
list(APPEND TRY_RUN_LIBRARIES ${OpenMP_Fortran_LIBRARIES})
list(APPEND TRY_RUN_COMPILER_FLAGS ${OpenMP_Fortran_FLAGS})
else()
list(APPEND TRY_RUN_DEFINITIONS -DNO_OMP)
endif()

# Try to compile and run try_compile.F90
try_run(RUN_FAILED COMPILED_OK
${CMAKE_CURRENT_BINARY_DIR}/try_compile # binary dir
${CMAKE_CURRENT_SOURCE_DIR}/CMakeScripts/try_compile.F90 # test src file
LINK_LIBRARIES ${TRY_RUN_LIBRARIES}
CMAKE_FLAGS "-DINCLUDE_DIRECTORIES=${TRY_RUN_INCLUDE_DIRS}" "-DCMAKE_Fortran_FLAGS=${TRY_RUN_COMPILER_FLAGS}"
COMPILE_DEFINITIONS ${TRY_RUN_DEFINITIONS}
COMPILE_OUTPUT_VARIABLE COMPILE_OUTPUT
RUN_OUTPUT_VARIABLE RUN_OUTPUT
)

# Display a warning if its compilation failed
if(NOT COMPILED_OK)
if(OMP)
set(CONDITIONAL_AND_OMP " and OpenMP")
endif()
message(WARNING
"Failed to compile a simple program that uses "
"NetCDF-Fortran ${CONDITIONAL_AND_OMP}! Could "
"your NetCDF installation be broken?\nSee "
"\"FailedCompile.txt\" for more info."
)
file(WRITE ${CMAKE_BINARY_DIR}/FailedCompile.txt
"${COMPILE_OUTPUT}"
)
else()
file(REMOVE ${CMAKE_BINARY_DIR}/FailedCompile.txt)
endif()

# Display a warning if its execution failed
if(RUN_FAILED)
if(OMP)
set(CONDITIONAL_AND_OMP "and OpenMP ")
endif()
message(WARNING
"A simple program that uses NetCDF-Fortran "
"${CONDITIONAL_AND_OMP}compiled successfully, "
"but its execution failed!\n\nSee "
"\"FailedExecution.txt\" for more info."
)
file(WRITE ${CMAKE_BINARY_DIR}/FailedEasyRun.txt
"${COMPILE_OUTPUT}\n${RUN_OUTPUT}"
)
else()
file(REMOVE ${CMAKE_BINARY_DIR}/FailedEasyRun.txt
${CMAKE_BINARY_DIR}/simple_xy.nc
)
set(GC_TRY_RUN_PASSED TRUE CACHE INTERNAL
"try_run passed" FORCE
)
endif()
endif()

#-----------------------------------------------------------------------------
# Print output of environment variable settings
Expand Down

0 comments on commit 2383fbd

Please sign in to comment.