-
Notifications
You must be signed in to change notification settings - Fork 36
CMake build infra-stucture #88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
c3e4866
support for building the CVMix library and the CVMix driver using CMake
bolding 29bf5b3
CMake build instructions added to README.md
bolding 393ab26
update documentation
bolding 0f005b0
improved support for NetCDF
bolding 4dd8764
fixed compilation with VisualStudio
bolding a323cef
updated README.md
bolding f5818f5
README.md - a few typos
bolding 6d7bb49
removed trailing blank
bolding 1dbf897
Create directory for cmake build
mnlevy1981 1cb7ba2
Allow reg_tests to use cmake
mnlevy1981 b583d7d
Lowering required version
mnlevy1981 4c61476
Clean up install instructions in README
mnlevy1981 3019c4e
updated README
bolding 30de4dc
Merge branch 'master' into cmake_updates
bolding 04cc49f
Clean up more trailing whitespace
mnlevy1981 d416bde
Merge branch 'mnlevy1981-cmake_updates'
bolding File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| cmake_minimum_required( VERSION 3.9 ) | ||
|
|
||
| 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 ) | ||
| 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 ) | ||
|
|
||
| # 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_SOURCE_DIR}/src/dummy.F90 $<TARGET_OBJECTS:cvmix_objects> ) | ||
| else() | ||
| add_library( cvmix_static STATIC $<TARGET_OBJECTS:cvmix_objects> ) | ||
| 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_SOURCE_DIR}/src/dummy.F90 $<TARGET_OBJECTS:cvmix_objects> ) | ||
| else() | ||
| add_library( cvmix_shared SHARED $<TARGET_OBJECTS:cvmix_objects> ) | ||
| 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 | ||
| $<INSTALL_INTERFACE:include/cvmix> | ||
| PRIVATE | ||
| $<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/${INCLUDE_DIR}> ) | ||
| set_target_properties( ${_lib} PROPERTIES OUTPUT_NAME cvmix) | ||
| endforeach() | ||
|
|
||
| if(CVMIX_BUILD_DRIVER) | ||
|
|
||
| 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 ) | ||
|
|
||
| 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) | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| * | ||
| !.gitignore |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| bin | ||
| include | ||
| lib | ||
| cmake |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,6 +43,9 @@ while [ $# -gt 0 ]; do | |
| bad_input $1 | ||
| fi | ||
| ;; | ||
| -cm|--cmake) | ||
| CMAKE_BUILD=TRUE | ||
| ;; | ||
| * ) | ||
| bad_input $1 | ||
| ;; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| # 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 driver ) | ||
| target_sources( cvmix_io PRIVATE | ||
| cvmix_io.F90 | ||
| ) | ||
| # 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 driver ) | ||
| 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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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. | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.