From c3e486600448c237f4a1fd7f292b06adee46e9cf Mon Sep 17 00:00:00 2001 From: Karsten Bolding Date: Tue, 28 Apr 2020 08:42:56 +0200 Subject: [PATCH 01/14] support for building the CVMix library and the CVMix driver using CMake --- CMakeLists.txt | 102 +++++++++++++++++++++++++++++++++++++++++++++ src/CMakeLists.txt | 40 ++++++++++++++++++ 2 files changed, 142 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 src/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 000000000..342ee1eba --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,102 @@ +cmake_minimum_required( VERSION 3.10 ) + +project( cvmix VERSION 4.0.1 LANGUAGES Fortran ) + +# Use solution folders in IDEs +set_property(GLOBAL PROPERTY USE_FOLDERS ON) + +# Use standard GNU installation directories +if ( NOT WIN32 ) + include( GNUInstallDirs ) +endif() + +# Configuration options +option( CVMIX_USE_NetCDF "Enable NetCDF format" OFF ) +option( CVMIX_BUILD_STATIC_LIBS "Build static library" ON ) +option( CVMIX_BUILD_SHARED_LIBS "Build shared library" ON ) +option( CVMIX_BUILD_DRIVER "Build CVMix example/test driver" OFF ) + +# Check if shared or static builds are turned off +if( NOT CVMIX_BUILD_STATIC_LIBS ) + message( STATUS "Turning STATIC builds OFF" ) +endif() +if( NOT CVMIX_BUILD_SHARED_LIBS ) + message( STATUS "Turning SHARED builds OFF" ) +endif() + +# Set default build type to Release if not specified +if( NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE ) + message( STATUS "Setting default build type to 'Release'. Set CMAKE_BUILD_TYPE variable to change build types." ) + set_property( CACHE CMAKE_BUILD_TYPE PROPERTY VALUE "Release" ) +endif() + +set( CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/modules ) +set( CMAKE_POSITION_INDEPENDENT_CODE ON ) + +add_subdirectory( src ) + +# Note - KB: +# Building static and shared libs require an ugly construct to build on both +# Windows and Linux. Windows will not create the libraries unless a Fortran +# file is explicitly given - and Linux complains (I think due to a race +# condition) if it is. Therefor the construct below - a proper solution is +# most welcome. + +# Add static lib target +if( CVMIX_BUILD_STATIC_LIBS ) + if ( WIN32 ) + add_library( cvmix_static STATIC ${CMAKE_BINARY_DIR}/src/cvmix_version.F90 $ ) + else() + add_library( cvmix_static STATIC $ ) + endif() + list( APPEND LIB_TARGETS cvmix_static ) +endif() + +# Add shared lib target +if( CVMIX_BUILD_SHARED_LIBS ) + if ( WIN32 ) + add_library( cvmix_shared SHARED ${CMAKE_BINARY_DIR}/src/cvmix_version.F90 $ ) + else() + add_library( cvmix_shared SHARED $ ) + endif() + list( APPEND LIB_TARGETS cvmix_shared ) +endif() + +# Set common lib target properties +foreach( _lib IN LISTS LIB_TARGETS ) + target_compile_definitions( ${_lib} PUBLIC "${PUBLIC_FLAGS}" ) + target_include_directories( ${_lib} + PUBLIC + $ + PRIVATE + $ ) + set_target_properties( ${_lib} PROPERTIES OUTPUT_NAME cvmix) +endforeach() + +if(CVMIX_BUILD_DRIVER) + + if(CVMIX_USE_NetCDF) + find_package(NetCDF REQUIRED) + endif(CVMIX_USE_NetCDF) + add_executable( cvmix_driver . ) + target_sources( cvmix_driver PRIVATE src/cvmix_driver.F90 ) + set_property( TARGET cvmix_driver PROPERTY FOLDER driver ) + target_include_directories( cvmix_driver PRIVATE ${CMAKE_BINARY_DIR}/modules ) + target_link_libraries( cvmix_driver PRIVATE cvmix_drivers cvmix_static netcdf ) + +endif() + +# Install +if(CVMIX_BUILD_DRIVER) +install( TARGETS cvmix_driver EXPORT cvmixConfig + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} ) +endif() +install( TARGETS ${LIB_TARGETS} EXPORT cvmixConfig + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ) +install( DIRECTORY ${CMAKE_BINARY_DIR}/modules/ EXPORT cvmixConfig + DESTINATION include/cvmix + FILES_MATCHING + PATTERN "*.mod" ) +install(EXPORT cvmixConfig DESTINATION cmake) + diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 000000000..5333d0a2b --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,40 @@ +# CVMix library +add_library(cvmix_objects OBJECT .) +set_property( TARGET cvmix_objects PROPERTY FOLDER cvmixlib ) +target_sources( cvmix_objects PRIVATE + shared/cvmix_kinds_and_types.F90 + shared/cvmix_background.F90 + shared/cvmix_convection.F90 + shared/cvmix_ddiff.F90 + shared/cvmix_kpp.F90 + shared/cvmix_math.F90 + shared/cvmix_put_get.F90 + shared/cvmix_shear.F90 + shared/cvmix_tidal.F90 + shared/cvmix_utils.F90 +) + +#configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cvmix_version.F90.in ${CMAKE_CURRENT_BINARY_DIR}/cvmix_version.F90) + +# CVMix driver dependencies +if(CVMIX_BUILD_DRIVER) + + add_library(cvmix_io STATIC .) + set_property( TARGET cvmix_io PROPERTY FOLDER drivers ) + target_sources( cvmix_io PRIVATE + cvmix_io.F90 + ) + target_link_libraries(cvmix_io PRIVATE cvmix_static) + + add_library(cvmix_drivers STATIC .) + set_property( TARGET cvmix_drivers PROPERTY FOLDER drivers ) + target_sources( cvmix_drivers PRIVATE + drivers/cvmix_bgrnd_BL.F90 + drivers/cvmix_ddiff_drv.F90 + drivers/cvmix_kpp_drv.F90 + drivers/cvmix_shear_drv.F90 + drivers/cvmix_tidal_Simmons.F90 + ) + target_link_libraries( cvmix_drivers PRIVATE cvmix_io ) + +endif() From 29bf5b351016eccbdacdc9c062c3ff34f2bac268 Mon Sep 17 00:00:00 2001 From: Karsten Bolding Date: Tue, 28 Apr 2020 09:05:42 +0200 Subject: [PATCH 02/14] CMake build instructions added to README.md --- README.md | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/README.md b/README.md index bb35506a8..75c816ff3 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,12 @@ goes into details about how to contribute, but basically we ask three things: INSTALLATION NOTES ------------------ +CVMix can be installed using two different methods. The original using Make +and a set of Makefiles. Or, using CMake using two CMakelists.txt files for +configuration. + +### Building/installing using Make + The src directory contains a Makefile and a simple 'make' should be sufficient to build the standalone driver. The first time you build, the 'cvmix_setup' utility will run and prompt you for compiler and netcdf information - it will @@ -58,6 +64,39 @@ $ make FC=[compiler] \ And then use -I$(INC_DIR) -L$(LIB_DIR) -lcvmix when you build software using the CVMix library. +### Building/installing using CMake + +[CMake](https://cmake.org/) can be used in GUI mode. Further information can +be found on the CMake web-page. Below is provided the command line commands +to configure and compile CVMix. Note that CVMix has been build on Windows using +VisualStudio and the Intel Fortran compiler. + +In this recipe CVMIX\_BASE s a convinience environmental variable pointing to +the CVMix source directory. It is possible to execute the following commands +providing the full path. + + +1. mkdir ~/build/cvmix + * [CMake](https://cmake.org/) promotes out of source compilation +2. cd ~/build/cvmix +3. cmake $CVMIX\_BASE + * The simplest configuration - using default Fortran compiler +4. cmake $CVMIX\_BASE -DCMAKE\_Fortran\_COMPILER=ifort + * Specifying a Fortran compiler +5. cmake $CVMIX\_BASE -DCVMIX\_BUILD\_DRIVER=on + * Build the CVMix driver program +5. cmake $CVMIX\_BASE -DCMAKE\_INSTALL\_PREFIX=~/local + * Providing installation folder + +After configuration has been done compilation is as simple as: +``` +make +``` + +and instllation by: +``` +make install +``` DIRECTORY STRUCTURE ------------------- From 393ab26991412bf9b0105b0decb651fc508295a4 Mon Sep 17 00:00:00 2001 From: Karsten Bolding Date: Tue, 28 Apr 2020 09:16:24 +0200 Subject: [PATCH 03/14] update documentation --- README.md | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 75c816ff3..ea5f81202 100644 --- a/README.md +++ b/README.md @@ -37,11 +37,11 @@ goes into details about how to contribute, but basically we ask three things: INSTALLATION NOTES ------------------ -CVMix can be installed using two different methods. The original using Make -and a set of Makefiles. Or, using CMake using two CMakelists.txt files for -configuration. +CVMix can be installed using two different methods. The original uses Make +and a set of Makefiles. The new methos uses CMake and two CMakelists.txt +files. -### Building/installing using Make +#### Building/installing using Make The src directory contains a Makefile and a simple 'make' should be sufficient to build the standalone driver. The first time you build, the 'cvmix_setup' @@ -64,7 +64,7 @@ $ make FC=[compiler] \ And then use -I$(INC_DIR) -L$(LIB_DIR) -lcvmix when you build software using the CVMix library. -### Building/installing using CMake +#### Building/installing using CMake [CMake](https://cmake.org/) can be used in GUI mode. Further information can be found on the CMake web-page. Below is provided the command line commands @@ -85,9 +85,14 @@ providing the full path. * Specifying a Fortran compiler 5. cmake $CVMIX\_BASE -DCVMIX\_BUILD\_DRIVER=on * Build the CVMix driver program -5. cmake $CVMIX\_BASE -DCMAKE\_INSTALL\_PREFIX=~/local +6. cmake $CVMIX\_BASE -DCVMIX\_BUILD\_DRIVER=on CVMIX\_USE\_NetCDF=on + * Include support for NetCDF in the driver model + * Note that this requires proper configuration of the installed NetCDF library. +7. cmake $CVMIX\_BASE -DCMAKE\_INSTALL\_PREFIX=~/local * Providing installation folder +Combination of the above commands is possible. + After configuration has been done compilation is as simple as: ``` make @@ -98,6 +103,13 @@ and instllation by: make install ``` +After installation the build directory can be removed. + +The support for CMake builds provides sufficient infrastructure for CVMix +being included in ocean models using the GIT submodule feature. This has +been used in the [GOTM](https:/gotm.net) inclusion of the CVMix mixing +models as a supplement to the original turbulence models in GOTM. + DIRECTORY STRUCTURE ------------------- From 0f005b090513906b621a94eeccc4daf87f2ecde1 Mon Sep 17 00:00:00 2001 From: Karsten Bolding Date: Tue, 28 Apr 2020 12:54:21 +0200 Subject: [PATCH 04/14] improved support for NetCDF --- CMakeLists.txt | 9 +++++---- README.md | 5 ++++- src/CMakeLists.txt | 7 ++++--- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 342ee1eba..499e33901 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,6 +12,10 @@ endif() # Configuration options option( CVMIX_USE_NetCDF "Enable NetCDF format" OFF ) +if(CVMIX_USE_NetCDF) + add_compile_definitions(_NETCDF) + include_directories($ENV{NetCDF_INCLUDE}) +endif(CVMIX_USE_NetCDF) option( CVMIX_BUILD_STATIC_LIBS "Build static library" ON ) option( CVMIX_BUILD_SHARED_LIBS "Build shared library" ON ) option( CVMIX_BUILD_DRIVER "Build CVMix example/test driver" OFF ) @@ -75,14 +79,11 @@ endforeach() if(CVMIX_BUILD_DRIVER) - if(CVMIX_USE_NetCDF) - find_package(NetCDF REQUIRED) - endif(CVMIX_USE_NetCDF) add_executable( cvmix_driver . ) target_sources( cvmix_driver PRIVATE src/cvmix_driver.F90 ) set_property( TARGET cvmix_driver PROPERTY FOLDER driver ) target_include_directories( cvmix_driver PRIVATE ${CMAKE_BINARY_DIR}/modules ) - target_link_libraries( cvmix_driver PRIVATE cvmix_drivers cvmix_static netcdf ) + target_link_libraries( cvmix_driver PRIVATE cvmix_drivers ) endif() diff --git a/README.md b/README.md index ea5f81202..4f6502731 100644 --- a/README.md +++ b/README.md @@ -86,8 +86,9 @@ providing the full path. 5. cmake $CVMIX\_BASE -DCVMIX\_BUILD\_DRIVER=on * Build the CVMix driver program 6. cmake $CVMIX\_BASE -DCVMIX\_BUILD\_DRIVER=on CVMIX\_USE\_NetCDF=on - * Include support for NetCDF in the driver model + * Include support for NetCDF in the driver model(1) * Note that this requires proper configuration of the installed NetCDF library. + * Setting NetCDF\_INCLUDE and NetCDF\_LIBRARIES might help. 7. cmake $CVMIX\_BASE -DCMAKE\_INSTALL\_PREFIX=~/local * Providing installation folder @@ -110,6 +111,8 @@ being included in ocean models using the GIT submodule feature. This has been used in the [GOTM](https:/gotm.net) inclusion of the CVMix mixing models as a supplement to the original turbulence models in GOTM. +1): There is unfortunately not an official NetCDF module finder in CMake. + DIRECTORY STRUCTURE ------------------- diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5333d0a2b..b456cd394 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -20,14 +20,15 @@ target_sources( cvmix_objects PRIVATE if(CVMIX_BUILD_DRIVER) add_library(cvmix_io STATIC .) - set_property( TARGET cvmix_io PROPERTY FOLDER drivers ) + set_property( TARGET cvmix_io PROPERTY FOLDER driver ) target_sources( cvmix_io PRIVATE cvmix_io.F90 ) - target_link_libraries(cvmix_io PRIVATE cvmix_static) +# target_link_libraries(cvmix_io PRIVATE cvmix_static PUBLIC netcdff ) + target_link_libraries(cvmix_io PRIVATE cvmix_static PUBLIC $ENV{NetCDF_LIBRARIES} ) add_library(cvmix_drivers STATIC .) - set_property( TARGET cvmix_drivers PROPERTY FOLDER drivers ) + set_property( TARGET cvmix_drivers PROPERTY FOLDER driver ) target_sources( cvmix_drivers PRIVATE drivers/cvmix_bgrnd_BL.F90 drivers/cvmix_ddiff_drv.F90 From 4dd8764ec56974752207567812607c556538a533 Mon Sep 17 00:00:00 2001 From: Karsten Bolding Date: Tue, 28 Apr 2020 13:08:30 +0200 Subject: [PATCH 05/14] fixed compilation with VisualStudio --- CMakeLists.txt | 4 ++-- src/dummy.F90 | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 src/dummy.F90 diff --git a/CMakeLists.txt b/CMakeLists.txt index 499e33901..983ec8336 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -49,7 +49,7 @@ add_subdirectory( src ) # Add static lib target if( CVMIX_BUILD_STATIC_LIBS ) if ( WIN32 ) - add_library( cvmix_static STATIC ${CMAKE_BINARY_DIR}/src/cvmix_version.F90 $ ) + add_library( cvmix_static STATIC ${CMAKE_SOURCE_DIR}/src/dummy.F90 $ ) else() add_library( cvmix_static STATIC $ ) endif() @@ -59,7 +59,7 @@ endif() # Add shared lib target if( CVMIX_BUILD_SHARED_LIBS ) if ( WIN32 ) - add_library( cvmix_shared SHARED ${CMAKE_BINARY_DIR}/src/cvmix_version.F90 $ ) + add_library( cvmix_shared SHARED ${CMAKE_SOURCE_DIR}/src/dummy.F90 $ ) else() add_library( cvmix_shared SHARED $ ) endif() diff --git a/src/dummy.F90 b/src/dummy.F90 new file mode 100644 index 000000000..2bf5e0338 --- /dev/null +++ b/src/dummy.F90 @@ -0,0 +1,5 @@ +! This file is needed to compile the driver program using VisualStudio. +! This is a known issue when building static/dynamic libraries based on +! object library. +! VisualStudio requires an explicit listed Fortran file to make the +! libraries - even if it is empty. From a323cef9b12755b25fe5d3c7a02e3efcbac3024e Mon Sep 17 00:00:00 2001 From: Karsten Bolding Date: Tue, 28 Apr 2020 13:10:22 +0200 Subject: [PATCH 06/14] updated README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4f6502731..b1f8ef743 100644 --- a/README.md +++ b/README.md @@ -69,7 +69,8 @@ the CVMix library. [CMake](https://cmake.org/) can be used in GUI mode. Further information can be found on the CMake web-page. Below is provided the command line commands to configure and compile CVMix. Note that CVMix has been build on Windows using -VisualStudio and the Intel Fortran compiler. +VisualStudio and the Intel Fortran compiler but NetCDF support has not been +tested. In this recipe CVMIX\_BASE s a convinience environmental variable pointing to the CVMix source directory. It is possible to execute the following commands From f5818f55edaab5d50ec7056579f2ee2bfc1c4a48 Mon Sep 17 00:00:00 2001 From: Karsten Bolding Date: Tue, 28 Apr 2020 13:14:42 +0200 Subject: [PATCH 07/14] README.md - a few typos --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b1f8ef743..e6e2370cd 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ INSTALLATION NOTES ------------------ CVMix can be installed using two different methods. The original uses Make -and a set of Makefiles. The new methos uses CMake and two CMakelists.txt +and a set of Makefiles. The new method uses CMake and two CMakelists.txt files. #### Building/installing using Make @@ -85,13 +85,13 @@ providing the full path. 4. cmake $CVMIX\_BASE -DCMAKE\_Fortran\_COMPILER=ifort * Specifying a Fortran compiler 5. cmake $CVMIX\_BASE -DCVMIX\_BUILD\_DRIVER=on - * Build the CVMix driver program + * Build the CVMix driver program - off by default 6. cmake $CVMIX\_BASE -DCVMIX\_BUILD\_DRIVER=on CVMIX\_USE\_NetCDF=on * Include support for NetCDF in the driver model(1) * Note that this requires proper configuration of the installed NetCDF library. * Setting NetCDF\_INCLUDE and NetCDF\_LIBRARIES might help. 7. cmake $CVMIX\_BASE -DCMAKE\_INSTALL\_PREFIX=~/local - * Providing installation folder + * Providing an installation folder Combination of the above commands is possible. From 6d7bb49124bb26ca0d05cbcdb0a7c9510b5756ef Mon Sep 17 00:00:00 2001 From: Karsten Bolding Date: Sat, 16 May 2020 13:57:56 +0200 Subject: [PATCH 08/14] removed trailing blank --- src/dummy.F90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dummy.F90 b/src/dummy.F90 index 2bf5e0338..3ddf711b8 100644 --- a/src/dummy.F90 +++ b/src/dummy.F90 @@ -1,5 +1,5 @@ ! This file is needed to compile the driver program using VisualStudio. -! This is a known issue when building static/dynamic libraries based on +! This is a known issue when building static/dynamic libraries based on ! object library. ! VisualStudio requires an explicit listed Fortran file to make the ! libraries - even if it is empty. From 1dbf89780f6ea078cd469cb84e9651198787b2e0 Mon Sep 17 00:00:00 2001 From: Michael Levy Date: Tue, 19 May 2020 21:33:00 -0600 Subject: [PATCH 09/14] Create directory for cmake build --- bld/cmake_bld/.gitignore | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 bld/cmake_bld/.gitignore diff --git a/bld/cmake_bld/.gitignore b/bld/cmake_bld/.gitignore new file mode 100644 index 000000000..d6b7ef32c --- /dev/null +++ b/bld/cmake_bld/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore From 1cb7ba2266f0ab1018170263a1df7b8608bd76c1 Mon Sep 17 00:00:00 2001 From: Michael Levy Date: Tue, 19 May 2020 21:52:13 -0600 Subject: [PATCH 10/14] Allow reg_tests to use cmake At this point, it's pretty klunky -- no netcdf support, forces compiler to be gfortran. But it should get cmake tested in travis, which is a good start. --- .travis.yml | 1 + reg_tests/common/build.sh | 15 ++++++++++++--- reg_tests/common/parse_inputs.sh | 3 +++ reg_tests/common/run.sh | 7 ++++++- 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 60b929f48..cb8f49f7d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,6 +14,7 @@ python: script: - cd bld; ./cvmix_setup gfortran $(dirname $(dirname $(which nc-config))) - cd ../CVMix_tools; ./run_test_suite.sh --already-ran-setup + - cd ../reg_tests/Bryan-Lewis/; ./Bryan-Lewis-test.sh --cmake branches: only: diff --git a/reg_tests/common/build.sh b/reg_tests/common/build.sh index 200be0e6d..1395a3a66 100644 --- a/reg_tests/common/build.sh +++ b/reg_tests/common/build.sh @@ -2,8 +2,17 @@ build () { if [ -z ${NO_BUILD} ]; then - make -f $CVMix/src/Makefile CVMIX_ROOT=$CVMix ${USE_NETCDF} - if [ $? != 0 ]; then + if [ "${CMAKE_BUILD}" == "TRUE" ]; then + CWD=$PWD + cd $CVMix/bld/cmake_bld + cmake $CVMix -DCVMIX_BUILD_DRIVER=on -DCMAKE_Fortran_COMPILER=gfortran && make + STATUS=$? + cd $CWD + else + make -f $CVMix/src/Makefile CVMIX_ROOT=$CVMix ${USE_NETCDF} + STATUS=$? + fi + if [ $STATUS != 0 ]; then echo "Build error!" exit 2 fi @@ -12,7 +21,7 @@ build () { if [ "`cat ../../bld/.netcdf_info`" == "YES" ]; then USE_NETCDF=netcdf fi - fi + fi fi } diff --git a/reg_tests/common/parse_inputs.sh b/reg_tests/common/parse_inputs.sh index c62a9f0a5..100a6e3d2 100644 --- a/reg_tests/common/parse_inputs.sh +++ b/reg_tests/common/parse_inputs.sh @@ -43,6 +43,9 @@ while [ $# -gt 0 ]; do bad_input $1 fi ;; + -cm|--cmake) + CMAKE_BUILD=TRUE + ;; * ) bad_input $1 ;; diff --git a/reg_tests/common/run.sh b/reg_tests/common/run.sh index ed279dc29..4307868af 100644 --- a/reg_tests/common/run.sh +++ b/reg_tests/common/run.sh @@ -2,7 +2,12 @@ run () { - $CVMix/bin/cvmix < $NAMELIST + if [ "${CMAKE_BUILD}" == "TRUE" ]; then + CVMIX_EXE=$CVMix/bld/cmake_bld/cvmix_driver + else + CVMIX_EXE=$CVMix/bin/cvmix + fi + ${CVMIX_EXE} < $NAMELIST if [ $? != 0 ]; then echo "Error in execution!" From b583d7dfe59825246eb3efc53c5c02ad7ebbac26 Mon Sep 17 00:00:00 2001 From: Michael Levy Date: Tue, 19 May 2020 22:06:06 -0600 Subject: [PATCH 11/14] Lowering required version Travis CI provides cmake 3.9.2 (we are using an old linux distribution so the apt-get versions of gfortran and libnetcdf-dev play nicely together); hoping there aren't actually features introduced in 3.10 in the system... --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 983ec8336..65d75055e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required( VERSION 3.10 ) +cmake_minimum_required( VERSION 3.9 ) project( cvmix VERSION 4.0.1 LANGUAGES Fortran ) From 4c6147632c8d08e4f6d7b1669a1102dd3a4d087e Mon Sep 17 00:00:00 2001 From: Michael Levy Date: Tue, 26 May 2020 11:28:44 -0600 Subject: [PATCH 12/14] Clean up install instructions in README Also modified build.sh and run.sh to follow directions laid out in the README (created cmake_bin/ for build target, build.sh calls "make install" and run.sh runs from cmake_bin/bin/) --- README.md | 33 +++++++++++++++------------------ cmake_bin/.gitignore | 4 ++++ reg_tests/common/build.sh | 5 ++++- reg_tests/common/run.sh | 2 +- 4 files changed, 24 insertions(+), 20 deletions(-) create mode 100644 cmake_bin/.gitignore diff --git a/README.md b/README.md index e6e2370cd..ba5fe1287 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ INSTALLATION NOTES ------------------ CVMix can be installed using two different methods. The original uses Make -and a set of Makefiles. The new method uses CMake and two CMakelists.txt +and a set of Makefiles. The new method uses CMake and two CMakelists.txt files. #### Building/installing using Make @@ -72,42 +72,39 @@ to configure and compile CVMix. Note that CVMix has been build on Windows using VisualStudio and the Intel Fortran compiler but NetCDF support has not been tested. -In this recipe CVMIX\_BASE s a convinience environmental variable pointing to -the CVMix source directory. It is possible to execute the following commands -providing the full path. - - -1. mkdir ~/build/cvmix - * [CMake](https://cmake.org/) promotes out of source compilation -2. cd ~/build/cvmix -3. cmake $CVMIX\_BASE +1. cd $CVMix/bld/cmake_bld + * [CMake](https://cmake.org/) promotes out of source compilation, + any such directory will do. +2. cmake $CVMix * The simplest configuration - using default Fortran compiler -4. cmake $CVMIX\_BASE -DCMAKE\_Fortran\_COMPILER=ifort +3. cmake $CVMix -DCMAKE\_Fortran\_COMPILER=ifort * Specifying a Fortran compiler -5. cmake $CVMIX\_BASE -DCVMIX\_BUILD\_DRIVER=on +4. cmake $CVMix -DCVMIX\_BUILD\_DRIVER=on * Build the CVMix driver program - off by default -6. cmake $CVMIX\_BASE -DCVMIX\_BUILD\_DRIVER=on CVMIX\_USE\_NetCDF=on +5. cmake $CVMix -DCVMIX\_BUILD\_DRIVER=on CVMIX\_USE\_NetCDF=on * Include support for NetCDF in the driver model(1) * Note that this requires proper configuration of the installed NetCDF library. * Setting NetCDF\_INCLUDE and NetCDF\_LIBRARIES might help. -7. cmake $CVMIX\_BASE -DCMAKE\_INSTALL\_PREFIX=~/local - * Providing an installation folder +6. cmake $CVMix -DCMAKE\_INSTALL\_PREFIX=$CVMix/bin + * Providing an installation folder (again, any such directory will do) Combination of the above commands is possible. After configuration has been done compilation is as simple as: + ``` make ``` and instllation by: + ``` make install ``` After installation the build directory can be removed. -The support for CMake builds provides sufficient infrastructure for CVMix +The support for CMake builds provides sufficient infrastructure for CVMix being included in ocean models using the GIT submodule feature. This has been used in the [GOTM](https:/gotm.net) inclusion of the CVMix mixing models as a supplement to the original turbulence models in GOTM. @@ -120,7 +117,7 @@ DIRECTORY STRUCTURE bin/ -- Default location for the cvmix executable. bld/ -- Contains auxiliary files needed by the build system. CompileFlags.mak - has default compile flags for 5 different compilers -- gfortran, + has default compile flags for 5 different compilers -- gfortran, pgf90, ifort, xlf90, and nagfor, as well as ftn (the Cray wrapper for pgf90). At this time, no other compilers are supported on Cray systems. cvmix_setup is a python script that saves information about what @@ -234,7 +231,7 @@ src/ -- Contains the source code, organized as follows. The top directory src/drivers/ -- Subroutines called by the driver (one per test). - src/shared/ -- Where all the modules that are needed to use CVMix with an + src/shared/ -- Where all the modules that are needed to use CVMix with an outside model are stored. Also contains the Makefile used to build the libcvmix.a library. diff --git a/cmake_bin/.gitignore b/cmake_bin/.gitignore new file mode 100644 index 000000000..01319b51b --- /dev/null +++ b/cmake_bin/.gitignore @@ -0,0 +1,4 @@ +bin +include +lib +cmake diff --git a/reg_tests/common/build.sh b/reg_tests/common/build.sh index 1395a3a66..32e5896fb 100644 --- a/reg_tests/common/build.sh +++ b/reg_tests/common/build.sh @@ -5,7 +5,10 @@ build () { if [ "${CMAKE_BUILD}" == "TRUE" ]; then CWD=$PWD cd $CVMix/bld/cmake_bld - cmake $CVMix -DCVMIX_BUILD_DRIVER=on -DCMAKE_Fortran_COMPILER=gfortran && make + cmake $CVMix -DCVMIX_BUILD_DRIVER=on \ + -DCMAKE_Fortran_COMPILER=gfortran \ + -DCMAKE_INSTALL_PREFIX=$CVMix/cmake_bin \ + && make && make install STATUS=$? cd $CWD else diff --git a/reg_tests/common/run.sh b/reg_tests/common/run.sh index 4307868af..db0e89ee5 100644 --- a/reg_tests/common/run.sh +++ b/reg_tests/common/run.sh @@ -3,7 +3,7 @@ run () { if [ "${CMAKE_BUILD}" == "TRUE" ]; then - CVMIX_EXE=$CVMix/bld/cmake_bld/cvmix_driver + CVMIX_EXE=$CVMix/cmake_bin/bin/cvmix_driver else CVMIX_EXE=$CVMix/bin/cvmix fi From 3019c4e75ae917cdbe89dffdae8634bb88bd286a Mon Sep 17 00:00:00 2001 From: Karsten Bolding Date: Wed, 27 May 2020 08:02:32 +0200 Subject: [PATCH 13/14] updated README --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e6e2370cd..ccba66402 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,7 @@ to configure and compile CVMix. Note that CVMix has been build on Windows using VisualStudio and the Intel Fortran compiler but NetCDF support has not been tested. -In this recipe CVMIX\_BASE s a convinience environmental variable pointing to +In this recipe CVMIX\_BASE is a convinient environmental variable pointing to the CVMix source directory. It is possible to execute the following commands providing the full path. @@ -100,7 +100,7 @@ After configuration has been done compilation is as simple as: make ``` -and instllation by: +and installation by: ``` make install ``` From 04cc49f10e08e1d8c6b2d8c8c69130c169a158ee Mon Sep 17 00:00:00 2001 From: Michael Levy Date: Fri, 19 Jun 2020 10:38:36 -0600 Subject: [PATCH 14/14] Clean up more trailing whitespace --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 65d75055e..ee9a1e8a5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,8 +42,8 @@ add_subdirectory( src ) # Note - KB: # Building static and shared libs require an ugly construct to build on both # Windows and Linux. Windows will not create the libraries unless a Fortran -# file is explicitly given - and Linux complains (I think due to a race -# condition) if it is. Therefor the construct below - a proper solution is +# file is explicitly given - and Linux complains (I think due to a race +# condition) if it is. Therefor the construct below - a proper solution is # most welcome. # Add static lib target