-
Notifications
You must be signed in to change notification settings - Fork 100
Update for cmake use of neural-fortran #192
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
milancurcic
merged 7 commits into
modern-fortran:main
from
mathomp4:feature/mathomp4/update-cmake
Sep 13, 2024
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3d748d5
Update for cmake use of neural-fortran
mathomp4 7e3855e
Update readme
mathomp4 55eb0ef
Fix up comment in cmake file
mathomp4 2cf9052
Add CMakeLists.txt to CI
mathomp4 413c042
Update cmake
mathomp4 ccb8095
Remove -DSERIAL=1
milancurcic fdf7921
Remove -DSERIAL=1
milancurcic 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
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 |
|---|---|---|
| @@ -1,179 +1,31 @@ | ||
| # SPDX-Identifier: MIT | ||
| # Based on https://github.com/fortran-lang/stdlib-cmake-example | ||
|
|
||
| #[[.rst: | ||
| Find neural-fortran | ||
| ------------------- | ||
|
|
||
| Makes the neural-fortran library project available. | ||
|
|
||
| Imported Targets | ||
| ^^^^^^^^^^^^^^^^ | ||
|
|
||
| This module provides the following imported target, if found: | ||
|
|
||
| ``neural-fortran::neural-fortran`` | ||
| The neural-fortran library | ||
|
|
||
|
|
||
| Result Variables | ||
| ^^^^^^^^^^^^^^^^ | ||
|
|
||
| This module will define the following variables: | ||
|
|
||
| ``NEURAL-FORTRAN_FOUND`` | ||
| True if the neural-fortran library is available | ||
|
|
||
| ``NEURAL-FORTRAN_SOURCE_DIR`` | ||
| Path to the source directory of the neural-fortran library project, | ||
| only set if the project is included as source. | ||
|
|
||
| ``NEURAL-FORTRAN_BINARY_DIR`` | ||
| Path to the binary directory of the neural-fortran library project, | ||
| only set if the project is included as source. | ||
|
|
||
| Cache variables | ||
| ^^^^^^^^^^^^^^^ | ||
|
|
||
| The following cache variables may be set to influence the library detection: | ||
|
|
||
| ``NEURAL-FORTRAN_FIND_METHOD`` | ||
| Methods to find or make the project available. Available methods are | ||
| - ``cmake``: Try to find via CMake config file | ||
| - ``pkgconf``: Try to find via pkg-config file | ||
| - ``subproject``: Use source in subprojects directory | ||
| - ``fetch``: Fetch the source from upstream | ||
|
|
||
| ``NEURAL-FORTRAN_DIR`` | ||
| Used for searching the CMake config file | ||
|
|
||
| ``NEURAL-FORTRAN_SUBPROJECT`` | ||
| Directory to find the neural-fortran library subproject, relative to the project root | ||
|
|
||
| #]] | ||
|
|
||
| set(_lib "neural-fortran") | ||
| set(_pkg "NEURAL-FORTRAN") | ||
| set(_url "https://github.com/modern-fortran/neural-fortran.git") | ||
|
|
||
| if(NOT DEFINED "${_pkg}_FIND_METHOD") | ||
| if(DEFINED "${PROJECT_NAME}-dependency-method") | ||
| set("${_pkg}_FIND_METHOD" "${${PROJECT_NAME}-dependency-method}") | ||
| else() | ||
| set("${_pkg}_FIND_METHOD" "cmake" "pkgconf" "subproject" "fetch") | ||
| endif() | ||
| set("_${_pkg}_FIND_METHOD") | ||
| endif() | ||
|
|
||
| foreach(method ${${_pkg}_FIND_METHOD}) | ||
| if(TARGET "${_lib}::${_lib}") | ||
| break() | ||
| endif() | ||
|
|
||
| if("${method}" STREQUAL "cmake") | ||
| message(STATUS "${_lib}: Find installed package") | ||
| if(DEFINED "${_pkg}_DIR") | ||
| set("_${_pkg}_DIR") | ||
| set("${_lib}_DIR" "${_pkg}_DIR") | ||
| endif() | ||
| find_package("${_lib}" CONFIG) | ||
| if("${_lib}_FOUND") | ||
| message(STATUS "${_lib}: Found installed package") | ||
| break() | ||
| endif() | ||
| endif() | ||
|
|
||
| if("${method}" STREQUAL "pkgconf") | ||
| find_package(PkgConfig QUIET) | ||
| pkg_check_modules("${_pkg}" QUIET "${_lib}") | ||
| if("${_pkg}_FOUND") | ||
| message(STATUS "Found ${_lib} via pkg-config") | ||
|
|
||
| add_library("${_lib}::${_lib}" INTERFACE IMPORTED) | ||
| target_link_libraries( | ||
| "${_lib}::${_lib}" | ||
| INTERFACE | ||
| "${${_pkg}_LINK_LIBRARIES}" | ||
| ) | ||
| target_include_directories( | ||
| "${_lib}::${_lib}" | ||
| INTERFACE | ||
| "${${_pkg}_INCLUDE_DIRS}" | ||
| ) | ||
|
|
||
| break() | ||
| endif() | ||
| endif() | ||
|
|
||
| if("${method}" STREQUAL "subproject") | ||
| if(NOT DEFINED "${_pkg}_SUBPROJECT") | ||
| set("_${_pkg}_SUBPROJECT") | ||
| set("${_pkg}_SUBPROJECT" "subprojects/${_lib}") | ||
| endif() | ||
| set("${_pkg}_SOURCE_DIR" "${PROJECT_SOURCE_DIR}/${${_pkg}_SUBPROJECT}") | ||
| set("${_pkg}_BINARY_DIR" "${PROJECT_BINARY_DIR}/${${_pkg}_SUBPROJECT}") | ||
| if(EXISTS "${${_pkg}_SOURCE_DIR}/CMakeLists.txt") | ||
| message(STATUS "Include ${_lib} from ${${_pkg}_SUBPROJECT}") | ||
| add_subdirectory( | ||
| "${${_pkg}_SOURCE_DIR}" | ||
| "${${_pkg}_BINARY_DIR}" | ||
| ) | ||
|
|
||
| add_library("${_lib}::${_lib}" INTERFACE IMPORTED) | ||
| target_link_libraries("${_lib}::${_lib}" INTERFACE "${_lib}") | ||
|
|
||
| # We need the module directory in the subproject before we finish the configure stage | ||
| if(NOT EXISTS "${${_pkg}_BINARY_DIR}/mod_files") | ||
| make_directory("${${_pkg}_BINARY_DIR}/mod_files") | ||
| endif() | ||
|
|
||
| break() | ||
| endif() | ||
| endif() | ||
|
|
||
| if("${method}" STREQUAL "fetch") | ||
| message(STATUS "Retrieving ${_lib} from ${_url}") | ||
| include(FetchContent) | ||
| FetchContent_Declare( | ||
| "${_lib}" | ||
| GIT_REPOSITORY "${_url}" | ||
| GIT_TAG "HEAD" | ||
| ) | ||
| FetchContent_MakeAvailable("${_lib}") | ||
|
|
||
| add_library("${_lib}::${_lib}" INTERFACE IMPORTED) | ||
| target_link_libraries("${_lib}::${_lib}" INTERFACE "${_lib}") | ||
|
|
||
| # We need the module directory in the subproject before we finish the configure stage | ||
| FetchContent_GetProperties("${_lib}" SOURCE_DIR "${_pkg}_SOURCE_DIR") | ||
| FetchContent_GetProperties("${_lib}" BINARY_DIR "${_pkg}_BINARY_DIR") | ||
| if(NOT EXISTS "${${_pkg}_BINARY_DIR}/mod_files") | ||
| make_directory("${${_pkg}_BINARY_DIR}/mod_files") | ||
| endif() | ||
|
|
||
| break() | ||
| endif() | ||
|
|
||
| endforeach() | ||
|
|
||
| if(TARGET "${_lib}::${_lib}") | ||
| set("${_pkg}_FOUND" TRUE) | ||
| else() | ||
| set("${_pkg}_FOUND" FALSE) | ||
| endif() | ||
|
|
||
| if(DEFINED "_${_pkg}_SUBPROJECT") | ||
| unset("${_pkg}_SUBPROJECT") | ||
| unset("_${_pkg}_SUBPROJECT") | ||
| endif() | ||
| if(DEFINED "_${_pkg}_DIR") | ||
| unset("${_lib}_DIR") | ||
| unset("_${_pkg}_DIR") | ||
| endif() | ||
| if(DEFINED "_${_pkg}_FIND_METHOD") | ||
| unset("${_pkg}_FIND_METHOD") | ||
| unset("_${_pkg}_FIND_METHOD") | ||
| # Find the native neural-fortran includes and library | ||
| # | ||
| # neural-fortran_INCLUDE_DIRS - where to find nf.mod, etc. | ||
| # neural-fortran_LIBRARIES - List of libraries when using neural-fortran. | ||
| # neural-fortran_FOUND - True if neural-fortran found. | ||
| # | ||
| # To use neural-fortran_ROOT_DIR to specify the prefix directory of neural-fortran | ||
|
|
||
|
|
||
| find_path(neural-fortran_INCLUDE_DIRS | ||
| NAMES nf.mod | ||
| HINTS ${neural-fortran_ROOT_DIR}/include ENV neural-fortran_INCLUDE_DIR) | ||
|
|
||
| find_library(neural-fortran_LIBRARIES | ||
| NAMES neural-fortran | ||
| HINTS ${neural-fortran_ROOT_DIR}/lib ENV neural-fortran_LIB_DIR) | ||
|
|
||
| include(FindPackageHandleStandardArgs) | ||
| find_package_handle_standard_args(neural-fortran DEFAULT_MSG neural-fortran_LIBRARIES neural-fortran_INCLUDE_DIRS) | ||
|
|
||
| mark_as_advanced( | ||
| neural-fortran_LIBRARIES | ||
| neural-fortran_INCLUDE_DIRS) | ||
|
|
||
| if(neural-fortran_FOUND AND NOT (TARGET neural-fortran::neural-fortran)) | ||
| add_library (neural-fortran::neural-fortran STATIC IMPORTED) | ||
| set_target_properties(neural-fortran::neural-fortran | ||
| PROPERTIES | ||
| IMPORTED_LOCATION ${neural-fortran_LIBRARIES} | ||
| INTERFACE_INCLUDE_DIRECTORIES ${neural-fortran_INCLUDE_DIRS}) | ||
| endif() | ||
| unset(_lib) | ||
| unset(_pkg) | ||
| unset(_url) |
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.