Skip to content

Commit

Permalink
Add underscore check
Browse files Browse the repository at this point in the history
  • Loading branch information
islas committed Aug 6, 2024
1 parent 64a9e28 commit 55656fe
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
25 changes: 25 additions & 0 deletions confcheck/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,31 @@ if ( NOT "${FSEEKO64}" )
)
endif()


# Check if underscores are needing for implicit c-Fortran intrefacing functions that
# don't use ISO C binding to map symbols
wrf_conf_check(
# try_run() with more than one source was introduced in CMake 3.25+
# so we won't use it here until we see reasonable need to incease the
# version requirements
RESULT_VAR NOUNDERSCORE_SYMBOL
SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/check_underscore.c ${CMAKE_CURRENT_SOURCE_DIR}/check_underscore.f90
OPTIONS
COMPILE_DEFINITIONS -DNOUNDERSCORE
MESSAGE "Implicit symbol usage between C and Fortran are not identical, checking with underscores"
)
if ( NOT ${NOUNDERSCORE_SYMBOL} )
# If the above fails we NEED the following to work
wrf_conf_check(
RESULT_VAR UNDERSCORE_SYMBOL
SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/check_underscore.c ${CMAKE_CURRENT_SOURCE_DIR}/check_underscore.f90
OPTIONS
COMPILE_DEFINITIONS -DUNDERSCORE
MESSAGE "Implicit symbol usage between C with underscores and Fortran did not link!"
REQUIRED
)
endif()

# Unsure if this is even necessary. Defines littered throughout configure.defaults
# if ( ${USE_MPI} )
# wrf_conf_check(
Expand Down
8 changes: 8 additions & 0 deletions confcheck/check_underscore.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include <stdio.h>
#ifdef UNDERSCORE
# define foo foo_
#endif
void foo( void )
{
printf( "Hello World!\n" );
}
5 changes: 5 additions & 0 deletions confcheck/check_underscore.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

program test
write( *, * ) "Calling foo() from Fortran"
call foo()
end program test

0 comments on commit 55656fe

Please sign in to comment.