Skip to content

Commit

Permalink
Fixes 62: CMakeLists now check that the run directory's major.minor v…
Browse files Browse the repository at this point in the history
…ersion number matches the source code's
  • Loading branch information
LiamBindle committed Sep 11, 2019
1 parent 316526f commit 8ab5a66
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,15 @@ if(NOT GC_EXTERNAL_CONFIG)
get_filename_component(RUNDIR "${RUNDIR}" ABSOLUTE BASE_DIR "${CMAKE_BINARY_DIR}") # Make RUNDIR an absolute path

# Configure the GEOS-Chem build for GCHP or GC-Classic
set(BUILD_WITHOUT_RUNDIR FALSE)
if(EXISTS ${RUNDIR}/input.geos)
file(STRINGS ${RUNDIR}/input.geos GCHP REGEX ": *gchp_*")
elseif(EXISTS ${RUNDIR}/getRunInfo)
set(GCHP FALSE) # getRunInfo is only in GC-Classic run direcotries
elseif((NOT EXISTS RUNDIR) AND (DEFINED RUNDIR_SIM))
set(GCHP FALSE) # special case for building without a run directory
set(RUNDIR ${CMAKE_BINARY_DIR})
set(BUILD_WITHOUT_RUNDIR TRUE)
else()
message(FATAL_ERROR "Your run directory doesn't have an input.geos or getRunInfo! Set RUNDIR to a valid run directory.")
endif()
Expand Down
30 changes: 29 additions & 1 deletion CMakeScripts/GC-ConfigureClassic.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,35 @@ function(configureGCClassic)
target_link_libraries(BaseTarget INTERFACE ${OpenMP_Fortran_FLAGS})
else()
target_compile_definitions(BaseTarget INTERFACE "NO_OMP")
endif()
endif()

# Check that GEOS-Chem's version number matches the run directory's version
if(EXISTS ${RUNDIR}/Makefile AND NOT "${BUILD_WITHOUT_RUNDIR}")
# Read ${RUNDIR}/Makefile which has the version number
file(READ ${RUNDIR}/Makefile RUNDIR_MAKEFILE)

# Pull out the major.minor version
if(RUNDIR_MAKEFILE MATCHES "VERSION[ \t]*:=[ \t]*([0-9]+\\.[0-9]+)\\.[0-9]+")
set(RUNDIR_VERSION ${CMAKE_MATCH_1})
else()
message(FATAL_ERROR "Failed to determine your run directory's version from ${RUNDIR}/Makefile")
endif()

# Get the major.minor version of GEOS-Chem
if(PROJECT_VERSION MATCHES "([0-9]+\\.[0-9]+)\\.[0-9]+")
set(GC_VERSION ${CMAKE_MATCH_1})
else()
message(FATAL_ERROR "Internal error. Bad GEOS-Chem version number.")
endif()

# Throw error if major.minor versions don't match
if(NOT "${GC_VERSION}" VERSION_EQUAL "${RUNDIR_VERSION}")
message(FATAL_ERROR
"Mismatched version numbers. Your run directory's version number "
"is ${RUNDIR_VERSION} but the GEOS-Chem source's version number is ${PROJECT_VERSION}"
)
endif()
endif()

# Configure the build based on the run directory. Propagate the configuration variables.
# Define a macro for inspecting the run directory. Inspecting the run
Expand Down

0 comments on commit 8ab5a66

Please sign in to comment.