@@ -53,7 +53,7 @@ list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
5353
5454# Build options
5555option (OPENMP "Build FMS with OpenMP support" OFF )
56- option (32BIT "Build 32-bit (r4) FMS library" ON )
56+ option (32BIT "Build 32-bit (r4) FMS library" OFF )
5757option (64BIT "Build 64-bit (r8) FMS library" OFF )
5858option (FPIC "Build with position independent code" OFF )
5959option (SHARED_LIBS "Build shared/dynamic libraries" OFF )
@@ -76,7 +76,7 @@ endif()
7676if (NOT kinds)
7777 message (STATUS "Single Precision 32BIT: ${32BIT} " )
7878 message (STATUS "Double Precision 64BIT: ${64BIT} " )
79- message (FATAL_ERROR "Either 32BIT or 64BIT should be ON " )
79+ message (STATUS "No kind specified, building default double precision (with mixed precision support). Real size will not be included in built library name. " )
8080endif ()
8181
8282# Find dependencies
@@ -89,7 +89,7 @@ if (OPENMP)
8989endif ()
9090
9191if (WITH_YAML)
92- find_package (libyaml REQUIRED )
92+ find_package (libyaml REQUIRED COMPONENTS C )
9393 include_directories (${LIBYAML_INCLUDE_DIR} )
9494endif ()
9595
@@ -290,6 +290,7 @@ endif()
290290# Obtain compiler-specific flags
291291include (fms_compiler_flags )
292292
293+ # TODO remove this section eventually, separate builds are no longer required
293294foreach (kind ${kinds} )
294295
295296 set (libTgt fms_${kind} )
@@ -300,9 +301,8 @@ foreach(kind ${kinds})
300301 add_library (${libTgt} _c OBJECT ${fms_c_src_files} )
301302
302303 target_include_directories (${libTgt} _c PRIVATE include
303- grid_utils )
304+ grid_utils )
304305 target_compile_definitions (${libTgt} _c PRIVATE "${fms_defs} " )
305-
306306 target_link_libraries (${libTgt} _c PRIVATE NetCDF::NetCDF_C
307307 MPI::MPI_C )
308308
@@ -340,22 +340,18 @@ foreach(kind ${kinds})
340340 coupler/include
341341 data_override/include
342342 amip_interp/include )
343-
344343 target_compile_definitions (${libTgt} _f PRIVATE "${fms_defs} " )
345344 target_compile_definitions (${libTgt} _f PRIVATE "${${kind} _defs}" )
346-
347345 set_target_properties (${libTgt} _f PROPERTIES COMPILE_FLAGS "${${kind} _flags}" )
348-
349346 set_target_properties (${libTgt} _f PROPERTIES Fortran_MODULE_DIRECTORY
350347 ${moduleDir} )
351-
352348 target_link_libraries (${libTgt} _f PRIVATE NetCDF::NetCDF_Fortran
353349 MPI::MPI_Fortran )
354-
355350 if (OpenMP_Fortran_FOUND)
356351 target_link_libraries (${libTgt} _f PRIVATE OpenMP::OpenMP_Fortran )
357352 endif ()
358353
354+
359355 # Check if gnu 10 or higher
360356 # this should only be needed with mpich, but wasn't able to find a good way to find the MPI flavor consistently
361357 if ( CMAKE_Fortran_COMPILER_VERSION MATCHES "1[0-9]\. [0-9]*\. [0-9]*" AND CMAKE_Fortran_COMPILER_ID MATCHES "GNU" )
@@ -405,7 +401,6 @@ foreach(kind ${kinds})
405401 $<BUILD_INTERFACE :${CMAKE_CURRENT_SOURCE_DIR} /data_override /include >
406402 $<BUILD_INTERFACE :${CMAKE_CURRENT_SOURCE_DIR} /tridiagonal /include >
407403 $<BUILD_INTERFACE :${CMAKE_CURRENT_SOURCE_DIR} /amip_interp /include >)
408-
409404 set (moduleDir "${CMAKE_CURRENT_BINARY_DIR} /${includeDir} " )
410405 target_include_directories (${libTgt} INTERFACE
411406 $<BUILD_INTERFACE :${moduleDir} >
@@ -430,6 +425,149 @@ foreach(kind ${kinds})
430425
431426endforeach ()
432427
428+ # default build, same as an r8 build just different name
429+ if (NOT kinds)
430+ message (STATUS "building default kind" )
431+ set (libTgt "fms" )
432+ set (includeDir "include" )
433+ set (moduleDir "${CMAKE_CURRENT_BINARY_DIR} /${includeDir} " )
434+ set (kind "r8" )
435+
436+ # C
437+ add_library (${libTgt} _c OBJECT ${fms_c_src_files} )
438+
439+ target_include_directories (${libTgt} _c PRIVATE include
440+ grid_utils )
441+ target_compile_definitions (${libTgt} _c PRIVATE "${fms_defs} " )
442+ target_link_libraries (${libTgt} _c PRIVATE NetCDF::NetCDF_C
443+ MPI::MPI_C )
444+
445+ if (OpenMP_C_FOUND)
446+ target_link_libraries (${libTgt} _c PRIVATE OpenMP::OpenMP_C )
447+ endif ()
448+
449+ if (WITH_YAML)
450+ target_link_libraries (${libTgt} _c PRIVATE libyaml_C )
451+ set_target_properties (${libTgt} _c PROPERTIES COMPILE_FLAGS "-L${LIBYAML_LIBRARIES} -lyaml" )
452+ endif ()
453+
454+
455+ # Fortran
456+ add_library (${libTgt} _f OBJECT ${fms_fortran_src_files} )
457+
458+ target_include_directories (${libTgt} _f PRIVATE include
459+ fms
460+ fms/include
461+ fms2_io/include
462+ string_utils/include
463+ mpp/include
464+ column_diagnostics/include
465+ monin_obukhov/include
466+ sat_vapor_pres/include
467+ horiz_interp/include
468+ diag_integral/include
469+ random_numbers/include
470+ diag_manager/include
471+ constants4
472+ topography/include
473+ axis_utils/include
474+ mosaic2/include
475+ constants
476+ astronomy/include
477+ field_manager/include
478+ time_interp/include
479+ tracer_manager/include
480+ tridiagonal/include
481+ interpolator/include
482+ coupler/include
483+ data_override/include
484+ amip_interp/include )
485+ target_compile_definitions (${libTgt} _f PRIVATE "${fms_defs} " )
486+ target_compile_definitions (${libTgt} _f PRIVATE "${${kind} _defs}" )
487+ set_target_properties (${libTgt} _f PROPERTIES COMPILE_FLAGS "${${kind} _flags}" )
488+ set_target_properties (${libTgt} _f PROPERTIES Fortran_MODULE_DIRECTORY
489+ ${moduleDir} )
490+ target_link_libraries (${libTgt} _f PRIVATE NetCDF::NetCDF_Fortran
491+ MPI::MPI_Fortran )
492+ if (OpenMP_Fortran_FOUND)
493+ target_link_libraries (${libTgt} _f PRIVATE OpenMP::OpenMP_Fortran )
494+ endif ()
495+
496+ # Check if gnu 10 or higher
497+ # this should only be needed with mpich, but wasn't able to find a good way to find the MPI flavor consistently
498+ if ( CMAKE_Fortran_COMPILER_VERSION MATCHES "1[0-9]\. [0-9]*\. [0-9]*" AND CMAKE_Fortran_COMPILER_ID MATCHES "GNU" )
499+ include (CheckFortranCompilerFlag )
500+ check_fortran_compiler_flag ("-fallow-argument-mismatch" _arg_mismatch_flag )
501+ if (_arg_mismatch_flag)
502+ message (STATUS "Adding -fallow-argument-mismatch flag to compile with GCC >=10 and MPICH" )
503+ target_compile_options (${libTgt} _f PRIVATE "-fallow-argument-mismatch;-w" )
504+ endif ()
505+ endif ()
506+
507+ # FMS (C + Fortran)
508+ if (SHARED_LIBS)
509+ message (STATUS "Shared library target: ${libTgt} " )
510+ add_library (${libTgt} SHARED $<TARGET_OBJECTS :${libTgt} _c >
511+ $<TARGET_OBJECTS :${libTgt} _f >)
512+ else ()
513+ message (STATUS "Static library target: ${libTgt} " )
514+ add_library (${libTgt} STATIC $<TARGET_OBJECTS :${libTgt} _c >
515+ $<TARGET_OBJECTS :${libTgt} _f >)
516+ endif ()
517+
518+ target_include_directories (${libTgt} PUBLIC
519+ $<BUILD_INTERFACE :${CMAKE_CURRENT_SOURCE_DIR} /include >
520+ $<BUILD_INTERFACE :${CMAKE_CURRENT_SOURCE_DIR} /fms >
521+ $<BUILD_INTERFACE :${CMAKE_CURRENT_SOURCE_DIR} /fms /include >
522+ $<BUILD_INTERFACE :${CMAKE_CURRENT_SOURCE_DIR} /fms2_io /include >
523+ $<BUILD_INTERFACE :${CMAKE_CURRENT_SOURCE_DIR} /column_diagnostics /include >
524+ $<BUILD_INTERFACE :${CMAKE_CURRENT_SOURCE_DIR} /astronomy /include >
525+ $<BUILD_INTERFACE :${CMAKE_CURRENT_SOURCE_DIR} /monin_obukhov /include >
526+ $<BUILD_INTERFACE :${CMAKE_CURRENT_SOURCE_DIR} /sat_vapor_pres /include >
527+ $<BUILD_INTERFACE :${CMAKE_CURRENT_SOURCE_DIR} /field_manager /include >
528+ $<BUILD_INTERFACE :${CMAKE_CURRENT_SOURCE_DIR} /grid_utils >
529+ $<BUILD_INTERFACE :${CMAKE_CURRENT_SOURCE_DIR} /horiz_interp /include >
530+ $<BUILD_INTERFACE :${CMAKE_CURRENT_SOURCE_DIR} /mosaic2 /include >
531+ $<BUILD_INTERFACE :${CMAKE_CURRENT_SOURCE_DIR} /string_utils /include >
532+ $<BUILD_INTERFACE :${CMAKE_CURRENT_SOURCE_DIR} /mpp /include >
533+ $<BUILD_INTERFACE :${CMAKE_CURRENT_SOURCE_DIR} /diag_manager /include >
534+ $<BUILD_INTERFACE :${CMAKE_CURRENT_SOURCE_DIR} /topography /include >
535+ $<BUILD_INTERFACE :${CMAKE_CURRENT_SOURCE_DIR} /random_numbers /include >
536+ $<BUILD_INTERFACE :${CMAKE_CURRENT_SOURCE_DIR} /diag_integral /include >
537+ $<BUILD_INTERFACE :${CMAKE_CURRENT_SOURCE_DIR} /diag_manager /include >
538+ $<BUILD_INTERFACE :${CMAKE_CURRENT_SOURCE_DIR} /tracer_manager /include >
539+ $<BUILD_INTERFACE :${CMAKE_CURRENT_SOURCE_DIR} /interpolator /include >
540+ $<BUILD_INTERFACE :${CMAKE_CURRENT_SOURCE_DIR} /coupler /include >
541+ $<BUILD_INTERFACE :${CMAKE_CURRENT_SOURCE_DIR} /mosaic2 /include >
542+ $<BUILD_INTERFACE :${CMAKE_CURRENT_SOURCE_DIR} /data_override /include >
543+ $<BUILD_INTERFACE :${CMAKE_CURRENT_SOURCE_DIR} /tridiagonal /include >
544+ $<BUILD_INTERFACE :${CMAKE_CURRENT_SOURCE_DIR} /amip_interp /include >)
545+
546+ set (moduleDir "${CMAKE_CURRENT_BINARY_DIR} /${includeDir} " )
547+ target_include_directories (${libTgt} INTERFACE
548+ $<BUILD_INTERFACE :${moduleDir} >
549+ $<INSTALL_INTERFACE :${includeDir} >)
550+
551+ target_compile_definitions (${libTgt} PRIVATE "${fms_defs} " )
552+ target_compile_definitions (${libTgt} PRIVATE "${${kind} _defs}" )
553+
554+ target_link_libraries (${libTgt} PUBLIC NetCDF::NetCDF_C
555+ NetCDF::NetCDF_Fortran
556+ MPI::MPI_Fortran )
557+
558+ if (OpenMP_Fortran_FOUND)
559+ target_link_libraries (${libTgt} PRIVATE OpenMP::OpenMP_C OpenMP::OpenMP_Fortran )
560+ endif ()
561+
562+ add_library (FMS::${libTgt} ALIAS ${libTgt} )
563+
564+ list (APPEND LIB_TARGETS ${libTgt} )
565+ install (DIRECTORY ${moduleDir} DESTINATION ${CMAKE_INSTALL_PREFIX} )
566+ install (FILES ${fms_header_files} DESTINATION ${CMAKE_INSTALL_PREFIX} /${includeDir} )
567+
568+
569+ endif ()
570+
433571install (
434572 TARGETS ${LIB_TARGETS}
435573 EXPORT FMSExports
@@ -440,23 +578,16 @@ install(
440578### Unit Testing
441579include (CTest )
442580
443- # TODO set these like autotools
581+ # TODO autotools also checks if srun is available
444582set (MPI_LAUNCHER "mpirun" )
583+ # used in the test-lib.sh.in to make it behave differently when parsed by cmake
584+ set (USING_CMAKE "true" )
445585
446- # parse and add build info to test script util functions (test-lib-cmake.sh.in)
586+ # parse and add build info to test script util file
447587configure_file (${CMAKE_CURRENT_SOURCE_DIR} /test_fms/test-lib.sh.in ${CMAKE_CURRENT_SOURCE_DIR} /test-lib.sh
448588 @ONLY )
449589
450- # single test for reference
451- #add_executable(test_mpp test_fms/mpp/test_mpp.F90)
452- #target_link_libraries(test_mpp FMS::fms_r4)
453- #target_include_directories(test_mpp PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/include_r4)
454- #add_test(NAME test_mpp
455- # COMMAND test_mpp2.sh
456- # WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/test_fms/mpp)
457-
458-
459- # first we need to build any helper modules that are used by unit tests
590+ # build any helper modules that are used by unit tests
460591list (APPEND TEST_MODS_SRC
461592 test_fms/diag_manager/testing_utils.F90
462593 test_fms/fms/test_fms.F90
@@ -471,11 +602,10 @@ list(APPEND TEST_MODS_SRC
471602 test_fms/mpp/test_mpp_update_domains_real.F90
472603 test_fms/mpp/test_system_clock.F90)
473604
474-
475605add_library (testLibs "${TEST_MODS_SRC} " )
476- target_link_libraries (testLibs FMS::fms_r4 )
606+ target_link_libraries (testLibs FMS::fms )
477607target_compile_definitions (testLibs PRIVATE TEST_MOS_KIND_=r8_kind )
478- target_include_directories (testLibs PRIVATE ${CMAKE_CURRENT_BINARY_DIR} /include_r4
608+ target_include_directories (testLibs PRIVATE ${CMAKE_CURRENT_BINARY_DIR} /include
479609 PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} /test_fms/fms/include
480610 PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} /test_fms/data_override/include
481611 PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} /test_fms/mosaic2
@@ -489,20 +619,28 @@ foreach (testFile ${TEST_SRC})
489619 get_filename_component (TName ${testFile} NAME_WE )
490620
491621 add_executable (${TName} ${testFile} )
492- # openmp/ mpi ?
493- target_link_libraries (${TName} PUBLIC FMS::fms_r4
622+ target_compile_definitions (${TName} PRIVATE "${r8_defs} " )
623+ set_target_properties (${TName} PROPERTIES COMPILE_FLAGS "${r8_flags} " )
624+ target_link_libraries (${TName} PUBLIC FMS::fms
625+ PRIVATE testLibs
626+ )
627+
628+ if (WITH_YAML)
629+ target_link_libraries (${TName} PRIVATE yaml ${LIBYAML_LIBRARIES} )
630+ endif ()
494631
495- PRIVATE testLibs )
632+ if (OPENMP)
633+ target_link_libraries (${TName} PRIVATE OpenMP::OpenMP_Fortran )
634+ endif ()
496635
497636 set_target_properties (${TName} PROPERTIES Fortran_MODULE_DIRECTORY
498- ${moduleDir} )
499- target_include_directories (${TName} PRIVATE ${CMAKE_CURRENT_BINARY_DIR} /include_r4
637+ ${moduleDir} )
638+ target_include_directories (${TName} PRIVATE ${CMAKE_CURRENT_BINARY_DIR} /include
500639 PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} /test_fms/fms/include
501640 PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} /test_fms/data_override/include
502641 PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} /test_fms/mosaic2
503642 PRIVATE ${CMAKE_CURRENT_BINARY_DIR} )
504- # TODO we'll need to compile the tests with both precisions and change the executable names accordingly
505- # this is just to get the compile working
643+ # TODO compile with both precisions
506644 target_compile_definitions (${TName} PRIVATE TEST_MOS_KIND_=r8_kind
507645 PRIVATE AU_TEST_KIND_=r8_kind
508646 PRIVATE FMS_TEST_BC_TYPE_=bc
@@ -523,11 +661,32 @@ foreach (testFile ${TEST_SRC})
523661endforeach ()
524662
525663
526- # find any test scripts and run them
527- file (GLOB_RECURSE TEST_SCRIPTS ${CMAKE_CURRENT_SOURCE_DIR} /test_fms/mpp/*.sh )
528- #list(FILTER ${TEST_SCRIPTS} EXCLUDE REGEX "test-lib*")
529- #list(FILTER ${TEST_SCRIPTS} EXCLUDE REGEX "tap-driver.*")
530-
664+ # find any test scripts and run them (TODO after the precision tests are worked out this can be used)
665+ #file(GLOB_RECURSE TEST_SCRIPTS ${CMAKE_CURRENT_SOURCE_DIR}/test_fms/*/*.sh)
666+ #list(FILTER TEST_SCRIPTS EXCLUDE REGEX "test-lib*")
667+ #list(FILTER TEST_SCRIPTS EXCLUDE REGEX "tap-driver.*")
668+
669+ # gather all the tests scripts that don't need mixed precision executables
670+ file (GLOB_RECURSE DM_TEST_SCRIPTS ${CMAKE_CURRENT_SOURCE_DIR} /test_fms/diag_manager/*.sh )
671+ file (GLOB_RECURSE IO_TEST_SCRIPTS ${CMAKE_CURRENT_SOURCE_DIR} /test_fms/fms2_io/*.sh )
672+ file (GLOB_RECURSE MPP_TEST_SCRIPTS ${CMAKE_CURRENT_SOURCE_DIR} /test_fms/mpp/*.sh )
673+ list (APPEND TEST_SCRIPTS
674+ ${CMAKE_CURRENT_SOURCE_DIR} /test_fms/block_control/test_block_control.sh
675+ ${CMAKE_CURRENT_SOURCE_DIR} /test_fms/coupler/test_gex.sh
676+ ${CMAKE_CURRENT_SOURCE_DIR} /test_fms/data_override/test_data_override_init.sh
677+ ${CMAKE_CURRENT_SOURCE_DIR} /test_fms/drifters/test_drifters2.sh
678+ ${CMAKE_CURRENT_SOURCE_DIR} /test_fms/exchange/test_xgrid2.sh
679+ ${CMAKE_CURRENT_SOURCE_DIR} /test_fms/fms/test_fms2.sh
680+ ${CMAKE_CURRENT_SOURCE_DIR} /test_fms/parser/test_yaml_parser.sh
681+ ${CMAKE_CURRENT_SOURCE_DIR} /test_fms/string_utils/test_string_utils.sh
682+ ${CMAKE_CURRENT_SOURCE_DIR} /test_fms/time_manager/test_time_manager2.sh
683+ ${DM_TEST_SCRIPTS}
684+ ${IO_TEST_SCRIPTS}
685+ ${MPP_TEST_SCRIPTS} )
686+
687+ list (FILTER TEST_SCRIPTS EXCLUDE REGEX "check_crashes.*" )
688+
689+ # add each test
531690foreach (testScript ${TEST_SCRIPTS} )
532691 get_filename_component (testName ${testScript} NAME_WE )
533692 add_test (NAME ${testName}
0 commit comments