pax_global_header00006660000000000000000000000064151370676070014526gustar00rootroot0000000000000052 comment=a300704ace53a09e164bbe747967be862263ec82 ecbuild-3.13.1/000077500000000000000000000000001513706760700132225ustar00rootroot00000000000000ecbuild-3.13.1/.cd/000077500000000000000000000000001513706760700136665ustar00rootroot00000000000000ecbuild-3.13.1/.cd/conda/000077500000000000000000000000001513706760700147525ustar00rootroot00000000000000ecbuild-3.13.1/.cd/conda/build.sh000066400000000000000000000004531513706760700164070ustar00rootroot00000000000000#!/usr/bin/env bash set -eux SOURCE_DIR=$(pwd) BUILD_DIR=build ECBUILD_BIN=$SOURCE_DIR/bin/ecbuild test -x $(which $ECBUILD_BIN) rm -rf $BUILD_DIR mkdir $BUILD_DIR cd $BUILD_DIR $ECBUILD_BIN --prefix=$PREFIX --log=DEBUG -- -DINSTALL_LIB_DIR=lib $SOURCE_DIR make test -j $CPU_COUNT make install ecbuild-3.13.1/.cd/conda/meta.yaml000066400000000000000000000021321513706760700165620ustar00rootroot00000000000000{% set name = "ecbuild" %} {% set git_tag = environ.get('GIT_DESCRIBE_TAG', '0.0.0').lstrip('v') %} {% set version = git_tag.replace('-', '') | lower %} package: name: {{ name|lower }} version: {{ version }} source: path: ../.. build: number: 0 skip: true # [win] requirements: build: - cmake - {{ compiler('cxx') }} run: - cmake - {{ compiler('cxx') }} test: commands: - test -f $PREFIX/bin/ecbuild - test -d $PREFIX/share/ecbuild/cmake - $PREFIX/bin/ecbuild --version about: home: https://github.com/ecmwf/ecbuild license: Apache-2.0 license_family: APACHE license_file: LICENSE summary: | A CMake-based build system, consisting of a collection of CMake macros and functions that ease the managing of software build systems. description: | ecBuild is built on top of CMake and consists of a set of macros as well as a wrapper around CMake. doc_url: https://github.com/ecmwf/ecbuild#readme dev_url: https://github.com/ecmwf/ecbuild extra: recipe-maintainers: - simondsmart - marcosbento - wdeconinck - iainrussell ecbuild-3.13.1/.github/000077500000000000000000000000001513706760700145625ustar00rootroot00000000000000ecbuild-3.13.1/.github/cd-config.yml000066400000000000000000000001361513706760700171360ustar00rootroot00000000000000builds: - name: "conda-build" type: "conda" enabled: true release: enabled: true ecbuild-3.13.1/.github/ci-config.yml000066400000000000000000000000611513706760700171400ustar00rootroot00000000000000dependency_branch: develop parallelism_factor: 8 ecbuild-3.13.1/.github/ci-hpc-config.yml000066400000000000000000000000741513706760700177140ustar00rootroot00000000000000build: modules: - ninja - python3 parallel: 64 ecbuild-3.13.1/.github/workflows/000077500000000000000000000000001513706760700166175ustar00rootroot00000000000000ecbuild-3.13.1/.github/workflows/cd.yml000066400000000000000000000013711513706760700177320ustar00rootroot00000000000000name: CD on: push: tags: - 'v?[0-9]+.[0-9]+.[0-9]+' - 'v?[0-9]+.[0-9]+.[0-9]+-*' branches: - '*' pull_request: types: [opened, synchronize, reopened, labeled] workflow_dispatch: permissions: contents: write jobs: build-and-release: name: "${{ startsWith(github.ref, 'refs/tags/') && 'Build and Release' || 'Dry Run' }}" if: | startsWith(github.ref, 'refs/tags/') || github.ref_name == github.event.repository.default_branch || (github.event.pull_request.base.ref == github.event.repository.default_branch && github.event.label.name == 'approved-for-cd') uses: ecmwf/reusable-workflows/.github/workflows/main-cd.yml@v2 with: ref_name: ${{ github.ref_name }} secrets: inherit ecbuild-3.13.1/.github/workflows/check-release-version.yml000066400000000000000000000003071513706760700235200ustar00rootroot00000000000000name: Check VERSION file on: push: branches: - "release/**" - "hotfix/**" jobs: check_version: uses: ecmwf/reusable-workflows/.github/workflows/check-release-version.yml@v2 ecbuild-3.13.1/.github/workflows/ci-single.yml000066400000000000000000000012531513706760700212150ustar00rootroot00000000000000name: ci-single # Controls when the workflow will run on: # Trigger the workflow on all pushes, except on tag creation push: branches: - '**' tags-ignore: - '**' paths-ignore: - ".cd/**" # Trigger the workflow on all pull requests pull_request: ~ # Allow workflow to be dispatched on demand workflow_dispatch: ~ jobs: # Calls a reusable CI workflow to build & test the current repository. # We skip jobs that will result in duplicate artifacts, since the code does not depend on the compiler. ci: name: ci uses: ecmwf/reusable-workflows/.github/workflows/ci.yml@v2 with: skip_matrix_jobs: | clang@rocky-8.6 ecbuild-3.13.1/.github/workflows/ci.yml000066400000000000000000000067331513706760700177460ustar00rootroot00000000000000name: ci on: # Trigger the workflow on push to master or develop, except tag creation push: branches: - "master" - "develop" tags-ignore: - "**" paths-ignore: - "docs/**" - "bamboo/**" - "README.rst" - ".cd/**" # Trigger the workflow on pull request pull_request: ~ # Trigger the workflow manually workflow_dispatch: ~ # Trigger after public PR approved for CI pull_request_target: types: [labeled] jobs: # Run CI including downstream packages on self-hosted runners downstream-ci: name: downstream-ci if: ${{ !github.event.pull_request.head.repo.fork && github.event.action != 'labeled' || github.event.label.name == 'approved-for-ci' }} uses: ecmwf/downstream-ci/.github/workflows/downstream-ci.yml@main with: ecbuild: ecmwf/ecbuild@${{ github.event.pull_request.head.sha || github.sha }} codecov_upload: false secrets: inherit # Run CI of private downstream packages on self-hosted runners private-downstream-ci: name: private-downstream-ci needs: [downstream-ci] if: ${{ (success() || failure()) && (!github.event.pull_request.head.repo.fork && github.event.action != 'labeled' || github.event.label.name == 'approved-for-ci') }} runs-on: ubuntu-latest permissions: pull-requests: write steps: - name: Dispatch private downstream CI uses: ecmwf/dispatch-private-downstream-ci@v1 with: token: ${{ secrets.GH_REPO_READ_TOKEN }} owner: ecmwf repository: private-downstream-ci event_type: downstream-ci payload: '{"ecbuild": "ecmwf/ecbuild@${{ github.event.pull_request.head.sha || github.sha }}"}' # Build downstream packages on HPC downstream-ci-hpc: name: downstream-ci-hpc if: ${{ !github.event.pull_request.head.repo.fork && github.event.action != 'labeled' || github.event.label.name == 'approved-for-ci' }} uses: ecmwf/downstream-ci/.github/workflows/downstream-ci-hpc.yml@main with: ecbuild: ecmwf/ecbuild@${{ github.event.pull_request.head.sha || github.sha }} secrets: inherit # Run CI of private downstream packages on HPC private-downstream-ci-hpc: name: private-downstream-ci-hpc needs: [downstream-ci-hpc] if: ${{ (success() || failure()) && (!github.event.pull_request.head.repo.fork && github.event.action != 'labeled' || github.event.label.name == 'approved-for-ci') }} runs-on: ubuntu-latest permissions: pull-requests: write steps: - name: Dispatch private downstream CI uses: ecmwf/dispatch-private-downstream-ci@v1 with: token: ${{ secrets.GH_REPO_READ_TOKEN }} owner: ecmwf repository: private-downstream-ci event_type: downstream-ci-hpc payload: '{"ecbuild": "ecmwf/ecbuild@${{ github.event.pull_request.head.sha || github.sha }}","skip_matrix_jobs": "nvidia-22.11"}' # DISABLED FOR NOW UNTIL REPO IS SET UP FOR THIS # notify: # runs-on: ubuntu-latest # needs: # - downstream-ci # - private-downstream-ci # - downstream-ci-hpc # - private-downstream-ci-hpc # if: ${{ always() && !github.event.pull_request.head.repo.fork && github.event.action != 'labeled' || github.event.label.name == 'approved-for-ci' }} # steps: # - name: Trigger Teams notification # uses: ecmwf/notify-teams@v1 # with: # incoming_webhook: ${{ secrets.MS_TEAMS_INCOMING_WEBHOOK }} # needs_context: ${{ toJSON(needs) }} ecbuild-3.13.1/.github/workflows/sync.yml000066400000000000000000000012561513706760700203220ustar00rootroot00000000000000name: sync # Controls when the workflow will run on: # Trigger the workflow on all pushes push: branches: - '**' tags: - '**' # Trigger the workflow when a branch or tag is deleted delete: ~ # Allow workflow to be dispatched on demand workflow_dispatch: ~ jobs: # Calls a reusable CI workflow to sync the current with a remote repository. # It will correctly handle addition of any new and removal of existing Git objects. sync: name: sync uses: ecmwf/reusable-workflows/.github/workflows/sync.yml@v2 secrets: target_repository: ecsdk/ecbuild target_username: ClonedDuck target_token: ${{ secrets.BITBUCKET_PAT }} ecbuild-3.13.1/.gitignore000066400000000000000000000001611513706760700152100ustar00rootroot00000000000000*sublime-workspace CMakeLists.txt.user* *.log *.py[cdo] *.swp *~ doc/contrib doc/find doc/macros build .DS_Store ecbuild-3.13.1/.readthedocs.yml000066400000000000000000000005341513706760700163120ustar00rootroot00000000000000 version: 2 # Set the OS, Python version and other tools you might need build: os: ubuntu-22.04 tools: python: "3.12" # Build documentation in the "doc/" directory with Sphinx sphinx: configuration: doc/conf.py # Define the requirements required to build the documentation python: install: - requirements: doc/requirements.txtecbuild-3.13.1/AUTHORS000066400000000000000000000004271513706760700142750ustar00rootroot00000000000000eckit Authors ============= eckit is mainly developed at the "European Centre for Medium-Range Weather Forecasts" (ECMWF, http://www.ecmwf.int). See attached LICENSE file for copyright. Developers: =========== Tiago Quintino Baudouin Raoult Willem Deconinck Florian Rathgeber ecbuild-3.13.1/CMakeLists.txt000066400000000000000000000045511513706760700157670ustar00rootroot00000000000000# (C) Copyright 2011- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation # nor does it submit to any jurisdiction. ############################################################################################ # cmake options: # # -DCMAKE_INSTALL_PREFIX=/path/to/install cmake_minimum_required( VERSION 3.18 FATAL_ERROR ) set( CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH} ) include( ecbuild ) project( ecbuild LANGUAGES C ) ############################################################################### # local project configure_file( cmake/ecbuild_version.h.in ${CMAKE_BINARY_DIR}/ecbuild_version.h ) # contents ecbuild_add_resources( TARGET ${PROJECT_NAME}_description_files SOURCES_PACK README.rst INSTALL.rst AUTHORS NOTICE LICENSE COPYING ) add_subdirectory( bin ) add_subdirectory( share ) add_subdirectory( cmake ) add_subdirectory( doc ) add_subdirectory( regressions ) add_subdirectory( tests ) install( DIRECTORY cmake DESTINATION ${INSTALL_DATA_DIR} PATTERN "CMakeLists.txt" EXCLUDE ) if( NOT CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR AND ECBUILD_2_COMPAT ) # Required for ecbuild-2 packages when ecbuild is added using `add_subdirectory( ecbuild ) [See ECBUILD-460]. # When adding ecbuild to your project using `add_subdirectory( ecbuild )`, and subsequently add a ecbuild-2 project # which by definition is not using `find_package( ecbuild )`, then the ecbuild-macros dir must be added to # the CMAKE_MODULE_PATH. # The `find_package( ecbuild ... )` works for the ecbuild-3-ported packages, as `ecbuild_DIR` gets defined in # `ecbuild_declare_project(ecbuild...)` of ecbuild during `add_subdirectory( ecbuild )` set( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} PARENT_SCOPE ) endif() ############################################################################################ # finalize ecbuild_install_project( NAME ${PROJECT_NAME} ) ecbuild_print_summary() ecbuild-3.13.1/COPYING000066400000000000000000000262001513706760700142550ustar00rootroot00000000000000 Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright 2007-2013 European Centre for Medium-Range Weather Forecasts (ECMWF) Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ecbuild-3.13.1/INSTALL.rst000066400000000000000000000014101513706760700150560ustar00rootroot00000000000000================== Installing ecBuild ================== Bootstrap and install ===================== :: git clone https://github.com/ecmwf/ecbuild cd ecbuild mkdir bootstrap cd bootstrap ../bin/ecbuild --prefix=/path/to/install/ecbuild .. ctest make install Generating documentation ======================== The documentation is generated using Sphinx. Make sure that ``sphinx-build`` can be located using ``PATH`` or ``CMAKE_PREFIX_PATH``. You can either add the ``-DSPHINX_HTML=ON`` option (as well as ``-DCMAKE_PREFIX_PATH=...`` if needed) to the above ``ecbuild`` command, or re-run ecBuild:: cd ecbuild/bootstrap ../bin/ecbuild -DSPHINX_HTML=ON .. make documentation The documentation tree will be available in ``doc/html``. ecbuild-3.13.1/LICENSE000066400000000000000000000247771513706760700142500ustar00rootroot00000000000000 Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS Copyright 2011- ECMWF Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ecbuild-3.13.1/NOTICE000066400000000000000000000013501513706760700141250ustar00rootroot00000000000000Notice ------ 1. The files FindLex and FindYacc are based on the FindBison and FindFlex macros from the original CMake code base. As requested, the License text has been preserved. The modifications are governed by the Apache License as described in COPYING. 2. FindEigen3 is based on a macro from Montel Laurent and others and distributed under the BSD 2-Clause License. 3. FindNetCDF4 is based on the macro FindNetCDF from project UCLALES from Max-Planck-Institut für Meteorologie and distributed under the Academic Free License v3.0. 4. GetGitRevisionDescription macros are based on the macro with smae name from Ryan Pavlik and Iowa State University, and distributed under Boost license. ecbuild-3.13.1/README.rst000066400000000000000000000027041513706760700147140ustar00rootroot00000000000000============================ ecbuild - ECMWF build system ============================ ecBuild is built on top of CMake and consists of a set of macros as well as a wrapper around CMake. Calling:: ecbuild $SRC_DIR is equivalent to:: cmake -DCMAKE_MODULE_PATH=$ECBUILD_DIR/cmake $SRC_DIR Prior knowledge of CMake is assumed. For a tutorial, see e.g. https://cmake.org/cmake/help/latest/guide/tutorial/index.html Quick start =========== ecBuild does not need to be compiled, and can be used directly from the source repository. If you want to install it, please refer to the ``_ file. 1. Retrieve the source code:: git clone https://github.com/ecmwf/ecbuild 2. Add ``ecbuild`` to your ``PATH``:: export PATH=$PWD/ecbuild/bin:$PATH Examples ======== The `examples/ `_ directory contains some sample projects that show how ecBuild can be used in various situations. For a quick introduction on how to write an ecBuild project, have a look at ``_. Building a project ================== Just like CMake, ecBuild uses out-of-source builds. We will assume that your project sources are in ``$SRC_DIR`` (e.g. ``examples/simple``), and that your build directory is ``$BUILD_DIR`` (e.g. ``$SRC_DIR/build``):: mkdir -p $BUILD_DIR cd $BUILD_DIR ecbuild $SRC_DIR # see `ecbuild --help`, you may pass CMake options as well make # add your favourite options, e.g. -j ecbuild-3.13.1/VERSION000077700000000000000000000000001513706760700164152cmake/VERSIONustar00rootroot00000000000000ecbuild-3.13.1/bamboo/000077500000000000000000000000001513706760700144615ustar00rootroot00000000000000ecbuild-3.13.1/bamboo/env.sh000077500000000000000000000003761513706760700156160ustar00rootroot00000000000000#!/bin/bash #[[ $(uname) == "Darwin" ]] && return # no module environment on the Mac # initialise module environment if it is not #if [[ ! $(command -v module > /dev/null 2>&1) ]]; then # . /usr/local/apps/module/init/bash #fi #module load cmake/new ecbuild-3.13.1/bamboo/flags.cmake000066400000000000000000000000001513706760700165450ustar00rootroot00000000000000ecbuild-3.13.1/bin/000077500000000000000000000000001513706760700137725ustar00rootroot00000000000000ecbuild-3.13.1/bin/CMakeLists.txt000066400000000000000000000000731513706760700165320ustar00rootroot00000000000000install( PROGRAMS ecbuild DESTINATION ${INSTALL_BIN_DIR} ) ecbuild-3.13.1/bin/ecbuild000077500000000000000000000316531513706760700153370ustar00rootroot00000000000000#!/bin/bash --noprofile # (C) Copyright 2011- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation nor # does it submit to any jurisdiction. set -eua CMAKE_MIN_REQUIRED=3.11 CMAKE_BUILD_VERSION=3.18.3 usage() { echo "Usage: ecbuild [--help] [--version]" exit $1 } help() { cat < ecbuild [option...] [--] [cmake-argument...] DESCRIPTION: ecbuild is a build system based on CMake, but providing a lot of macro's to make it easier to work with. Upon execution, the equivalent cmake command is printed. ecbuild/cmake must be called from an out-of-source build directory and forbids in-source builds. SYNOPSIS: --help Display this help --version Display ecbuild version Available values for "option": --cmakebin= Set which cmake binary to use. Default is 'cmake' --prefix= Set the install path to . Equivalent to cmake argument "-DCMAKE_INSTALL_PREFIX=" --build= Set the build-type to . Equivalent to cmake argument "-DCMAKE_BUILD_TYPE=" can be any of: - debug : Lowest optimization level, useful for debugging - release : Highest optimization level, for best performance - bit : Highest optimization level while staying bit-reproducible - ...others depending on project --log= Set the ecbuild log-level Equivalent to "-DECBUILD_LOG_LEVEL=" can be any of: - DEBUG - INFO - WARN - ERROR - CRITICAL - OFF Every choice outputs also the log-levels listed below itself --static Build static libraries. Equivalent to "-DBUILD_SHARED_LIBS=OFF" --dynamic, --shared Build dynamic libraries (usually the default). Equivalent to "-DBUILD_SHARED_LIBS=ON" --config= Configuration file using CMake syntax that gets included Equivalent to cmake argument "-DECBUILD_CONFIG=" --toolchain= Use a platform specific toolchain, containing settings such as compilation flags, locations of commonly used dependencies. should be the path to a custom toolchain file. Equivalent to cmake argument "-DCMAKE_TOOLCHAIN_FILE=" --cache= (advanced) A file called "ecbuild-cache.cmake" is generated during configuration. This file can be moved to a safe location, and specified for future builds to speed up checking of compiler/platform capabilities. Note that this is only accelerating fresh builds, as cmake internally caches also. Therefore this option is *not* recommended. --get-cmake[=] Automatically download CMake binaries from version $CMAKE_BUILD_VERSION. Requires an internet connection. If no prefix is given, install into $PWD/.local/. --build-cmake[=] Automatically download and build CMake version $CMAKE_BUILD_VERSION. Requires an internet connection and may take a while. If no prefix is given, install into $PWD/.local/. --dryrun Don't actually execute the cmake call, just print what would have been executed. Available values for "cmake-argument": Any value that can be usually passed to cmake to (re)configure the build. Typically these values start with "-D". example: -DENABLE_TESTS=ON -DENABLE_MPI=OFF -DECKIT_PATH=... They can be explicitly separated from [option...] with a "--", for the case there is a conflicting option with the "cmake" executable, and the latter's option is requested. ------------------------------------------------------------------------ NOTE: When reconfiguring a build, it is only necessary to change the relevant options, as everything stays cached. For example: > ecbuild --prefix=PREFIX . > ecbuild -DENABLE_TESTS=ON . ------------------------------------------------------------------------ Compiling: To compile the project with threads: > make -j To get verbose compilation/linking output: > make VERBOSE=1 Testing: To run the project's tests > ctest Also check the ctest manual/help for more options on running tests Installing: To install the project in location PREFIX with "--prefix=PREFIX" or "-DCMAKE_INSTALL_PREFIX=PREFIX" > make install ------------------------------------------------------------------------ ECMWF" EOF exit $1 } INSTALL_DIR="$( cd $( dirname "${BASH_SOURCE[0]}" ) && pwd -P )" export ecbuild_ROOT="$( cd "$INSTALL_DIR/.." && pwd -P )" export ecbuild_DIR=$ecbuild_ROOT # for versions of CMake < 3.12 ECBUILD_MODULE_PATH="" # If there is a directory share/ecbuild/cmake relative to the parent directory # (as in an install tree), add it to CMAKE_MODULE_PATH if [ -d $INSTALL_DIR/../share/ecbuild/cmake ]; then ECBUILD_MODULE_PATH="$( cd "$INSTALL_DIR/../share/ecbuild/cmake" && pwd -P )" # If there is a cmake subdirectory relative to the script directory (as in a # tarball), add it to CMAKE_MODULE_PATH elif [ -d $INSTALL_DIR/../cmake ]; then ECBUILD_MODULE_PATH="$( cd "$INSTALL_DIR/../cmake" && pwd -P )" fi # Fail if we couldn't find ecBuild modules if [ ! -f "$ECBUILD_MODULE_PATH/ecbuild_system.cmake" ]; then echo "FATAL: ecBuild modules could not be found in either $INSTALL_DIR/../share/ecbuild/cmake or $INSTALL_DIR/../cmake" >&2 exit 1 fi ADD_ECBUILD_OPTIONS="-DCMAKE_MODULE_PATH=$ECBUILD_MODULE_PATH" version() { ecbuild_version=$(cat ${ECBUILD_MODULE_PATH}/VERSION) echo "ecbuild version ${ecbuild_version}" command -v cmake >/dev/null 2>&1 || { exit 0; } cmake --version | head -1 exit 0 } log() { log_level=$(tr "[a-z]" "[A-Z]" <<< "$1") ADD_ECBUILD_OPTIONS="$ADD_ECBUILD_OPTIONS -DECBUILD_LOG_LEVEL=${log_level}" } prefix() { ADD_ECBUILD_OPTIONS="$ADD_ECBUILD_OPTIONS -DCMAKE_INSTALL_PREFIX=${1/#\~\//$HOME/}" } config() { arg=${1/#\~\//$HOME/} if [ -f $arg ]; then config_file=$arg config_file="$( cd $( dirname "${config_file}" ) && pwd -P )/$( basename ${config_file} )" else echo "Error:" echo " Config file [$arg] is not found or is not a file." exit 1 fi ADD_ECBUILD_OPTIONS="$ADD_ECBUILD_OPTIONS -DECBUILD_CONFIG=${config_file}" } toolchain() { arg=${1/#\~\//$HOME/} if [ -f $arg ]; then toolchain_file=$arg fi if [ -z ${toolchain_file+x} ]; then echo "Error toolchain $arg is not valid" exit 1 else ADD_ECBUILD_OPTIONS="$ADD_ECBUILD_OPTIONS -DCMAKE_TOOLCHAIN_FILE=${toolchain_file}" fi } cache() { arg=$1 if [ -f $arg ]; then cache_file=$arg cache_file="$( cd $( dirname "${cache_file}" ) && pwd -P )/$( basename ${cache_file} )" else echo "Error:" echo " Cache file [$arg] is not found or is not a file." exit 1 fi ADD_ECBUILD_OPTIONS="$ADD_ECBUILD_OPTIONS -DECBUILD_CACHE=${cache_file}" } if test $# -eq 0; then usage 1 fi while test $# -gt 0; do # Split --option=value in $opt="--option" and $val="value" opt="" val="" case "$1" in --*=*) opt=`echo "$1" | sed 's/=.*//'` val=`echo "$1" | sed 's/--[_a-zA-Z0-9-]*=//'` ;; --*) opt=$1 ;; # -D*) # ADD_ECBUILD_OPTIONS="$ADD_ECBUILD_OPTIONS $1" # ;; *) break ;; esac # echo "debug opt: $opt $val" # Parse options case "$opt" in --help) help 0 ;; --version) version ;; --dryrun) dryrun="yes" ;; --cmakebin) cmakebin="$val" ;; --prefix) prefix "$val" ;; --build) ADD_ECBUILD_OPTIONS="$ADD_ECBUILD_OPTIONS -DCMAKE_BUILD_TYPE=$val" ;; --log) log $val ;; --static) ADD_ECBUILD_OPTIONS="$ADD_ECBUILD_OPTIONS -DBUILD_SHARED_LIBS=OFF" ;; --dynamic) ADD_ECBUILD_OPTIONS="$ADD_ECBUILD_OPTIONS -DBUILD_SHARED_LIBS=ON" ;; --shared) ADD_ECBUILD_OPTIONS="$ADD_ECBUILD_OPTIONS -DBUILD_SHARED_LIBS=ON" ;; --toolchain) toolchain $val ;; --config) config $val ;; --cache) cache $val ;; --get-cmake) get_cmake="bin" if [[ -n $val ]]; then cmake_prefix="$val" fi ;; --build-cmake) get_cmake="src" if [[ -n $val ]]; then cmake_prefix="$val" fi ;; --) shift break ;; *) echo "unknown option: $opt" usage 1 ;; esac shift done # If no arguments remain, set srcARG to "." if [ $# -eq 0 ]; then srcARG="." fi if [ -z ${toolchain_file+x} ]; then if [ -z ${ECBUILD_TOOLCHAIN+x} ]; then : else toolchain ${ECBUILD_TOOLCHAIN} echo "ecbuild toolchain set using environment variable ECBUILD_TOOLCHAIN" fi fi src=${srcARG:=""} cmake=${cmakebin:=cmake} dryrun=${dryrun:=no} get_cmake=${get_cmake:=""} cmake_prefix=${cmake_prefix:=$PWD/.local} cmake_found="" cmake_version_sufficient="" # Check that version $1 satisfies $2 # CMake versions have no more than 4 fields # Version sort (sort -V) is not available on all platforms version_gte() { [ "$2" = "$(echo -e "$1\n$2" | sort -t '.' -k 1,1 -k 2,2 -k 3,3 -k 4,4 -g | head -n1)" ] } # Download a CMake tarball # $1: version # $2: suffix (optional) download_cmake() { tarball=cmake-$1${2:-""}.tar.gz if [[ ! -r $tarball ]]; then shortver=$(echo $1 | cut -d. -f1-2) url=http://www.cmake.org/files/v$shortver/$tarball # -N Download only if the remote version of the file is newer # --continue Continue an interrupted download # -T 60 Time out a download attempt after 60 seconds # -t 3 Only make 3 download attempts wget -N --continue -T 60 -t 3 $url || { echo "Failed to download CMake release $1." >&2 echo "Please download from $url" >&2 echo "and place $tarball in $PWD" >&2 exit 1 } fi echo $tarball } # Use already built CMake if any if [[ -x "${cmake_prefix}/bin/cmake" ]]; then echo "Using already built CMake in ${cmake_prefix}/bin/cmake" >&2 cmake="${cmake_prefix}/bin/cmake" # Get a CMake binary if requested and no sufficient version found elif [[ $get_cmake = "bin" ]]; then plat=$(uname -s) arch=$(uname -m) if [[ "${plat}" != "Linux" ]] && [[ "${plat}" != "Darwin" ]] ; then echo "Cannot download CMake binaries for this platform." >&2 echo "Please use --build-cmake to build from source." >&2 exit 1 fi if [[ "${arch}" != "x86_64" ]] ; then echo "Cannot download CMake binaries for this architecture." >&2 echo "Please use --build-cmake to build from source." >&2 exit 1 fi echo "Downloading CMake version ${CMAKE_BUILD_VERSION} binaries and installing into ${cmake_prefix} ..." >&2 tarball=$(download_cmake "${CMAKE_BUILD_VERSION}" "-${plat}-${arch}") mkdir -p "${cmake_prefix}" tar xzf $tarball -C "${cmake_prefix}" --strip-components=1 cmake="${cmake_prefix}/bin/cmake" # Build CMake from source if requested and no sufficient version found elif [[ $get_cmake = "src" ]]; then echo "Building CMake version ${CMAKE_BUILD_VERSION} and installing into ${cmake_prefix} ..." >&2 tarball=$(download_cmake "${CMAKE_BUILD_VERSION}") tar xzf $tarball ( mkdir -p build_cmake cd build_cmake ../cmake-${CMAKE_BUILD_VERSION}/bootstrap --prefix="${cmake_prefix}" && make && make install ) cmake="${cmake_prefix}/bin/cmake" fi # Check if the cmake version is sufficient if $(command -v $cmake >/dev/null 2>&1); then cmake_found="yes" cmake_version=$($cmake --version | head -n1 | awk '{ print $3 }') echo "Found CMake version $cmake_version" >& 2 if version_gte $cmake_version $CMAKE_MIN_REQUIRED; then cmake_version_sufficient="yes" fi fi # Fail if we don't have a sufficient CMake if [[ ! $cmake_version_sufficient ]]; then if [[ ! $cmake_found ]]; then echo "CMake is required and cannot be found in the PATH." >&2 else echo "CMake version $CMAKE_MIN_REQUIRED is required but only $cmake_version was found." >&2 fi echo "" >&2 echo " Try 'module load cmake', specify a CMake binary with --cmakebin=/path/to/cmake" >&2 echo " or let ecbuild download and build CMake with the --build-cmake option." >&2 exit 1 fi echo "" echo "$cmake ${ADD_ECBUILD_OPTIONS} $@ $src" echo "" if [ ${dryrun} == "yes" ]; then echo "[DRYRUN] -- not executing" exit 0 fi $cmake ${ADD_ECBUILD_OPTIONS} "$@" $src ecbuild-3.13.1/cmake/000077500000000000000000000000001513706760700143025ustar00rootroot00000000000000ecbuild-3.13.1/cmake/CMakeLists.txt000066400000000000000000000011621513706760700170420ustar00rootroot00000000000000# (C) Copyright 2011- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation # nor does it submit to any jurisdiction. file( GLOB_RECURSE ecbuild_support_files RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*" ) ecbuild_add_resources( TARGET ${PROJECT_NAME}_ecbuild_support_files SOURCES_PACK ${ecbuild_support_files} ) ecbuild-3.13.1/cmake/FindARMPL.cmake000066400000000000000000000040471513706760700167650ustar00rootroot00000000000000# (C) Copyright 2011- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation # nor does it submit to any jurisdiction. # - Try to find ARMPL # Once done this will define # # ARMPL_FOUND - system has ARM Performance Libraries # ARMPL_INCLUDE_DIRS - the ARMPL include directories # ARMPL_LIBRARIES - link these to use ARMPL # # The following paths will be searched with priority if set in CMake or env # # ARMPLROOT - root directory of the ARMPL installation # ARMPL_PATH - root directory of the ARMPL installation # ARMPL_ROOT - root directory of the ARMPL installation option( ARMPL_PARALLEL "if armpl shoudl be parallel" OFF ) if( ARMPL_PARALLEL ) set( __armpl_lib_suffix "_mp" ) find_package(Threads) else() set( __armpl_lib_suffix "" ) endif() # Search with priority for ARMPLROOT, ARMPL_PATH and ARMPL_ROOT if set in CMake or env find_path(ARMPL_INCLUDE_DIR armpl.h PATHS ${ARMPLROOT} ${ARMPL_PATH} ${ARMPL_ROOT} ${ARMPL_DIR} $ENV{ARMPLROOT} $ENV{ARMPL_PATH} $ENV{ARMPL_ROOT} $ENV{ARMPL_DIR} PATH_SUFFIXES include NO_DEFAULT_PATH) find_path(ARMPL_INCLUDE_DIR armpl.h PATH_SUFFIXES include) if( ARMPL_INCLUDE_DIR ) # use include dir to find libs set( ARMPL_INCLUDE_DIRS ${ARMPL_INCLUDE_DIR} ) find_library( ARMPL_LIB PATHS ${ARMPLROOT} ${ARMPL_PATH} ${ARMPL_ROOT} ${ARMPL_DIR} $ENV{ARMPLROOT} $ENV{ARMPL_PATH} $ENV{ARMPL_ROOT} $ENV{ARMPL_DIR} PATH_SUFFIXES "lib" NAMES armpl_lp64${__armpl_lib_suffix} ) if( ARMPL_LIB ) set( ARMPL_LIBRARIES ${ARMPL_LIB} ) endif() endif() include(FindPackageHandleStandardArgs) find_package_handle_standard_args( ARMPL DEFAULT_MSG ARMPL_LIBRARIES ARMPL_INCLUDE_DIRS ) mark_as_advanced( ARMPL_INCLUDE_DIR ARMPL_LIB ) ecbuild-3.13.1/cmake/FindCMath.cmake000066400000000000000000000016371513706760700171100ustar00rootroot00000000000000# (C) Copyright 2011- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation nor # does it submit to any jurisdiction. #Sets: # CMATH_LIBRARIES = the library to link against (RT etc) IF(UNIX) if( DEFINED CMATH_PATH ) find_library(CMATH_LIBRARIES m PATHS ${CMATH_PATH}/lib NO_DEFAULT_PATH ) endif() find_library(CMATH_LIBRARIES m ) include(FindPackageHandleStandardArgs) # handle the QUIET and REQUIRED arguments and set CMATH_FOUND to TRUE # if all listed variables are TRUE # Note: capitalisation of the package name must be the same as in the file name find_package_handle_standard_args(CMath DEFAULT_MSG CMATH_LIBRARIES ) ENDIF(UNIX) ecbuild-3.13.1/cmake/FindDl.cmake000066400000000000000000000015431513706760700164470ustar00rootroot00000000000000# (C) Copyright 2011- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation nor # does it submit to any jurisdiction. #Sets: # DL_LIBRARIES = the library to link against (RT etc) if( DEFINED DL_PATH ) find_library(DL_LIBRARIES dl PATHS ${DL_PATH}/lib NO_DEFAULT_PATH ) endif() find_library(DL_LIBRARIES dl ) include(FindPackageHandleStandardArgs) # handle the QUIET and REQUIRED arguments and set DL_FOUND to TRUE # if all listed variables are TRUE # Note: capitalisation of the package name must be the same as in the file name find_package_handle_standard_args(Dl DEFAULT_MSG DL_LIBRARIES ) ecbuild-3.13.1/cmake/FindFFTW.cmake000066400000000000000000000303311513706760700166530ustar00rootroot00000000000000# (C) Copyright 2011- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation nor # does it submit to any jurisdiction. ############################################################################## #.rst: # # FindFFTW # ======== # # Find the FFTW library. :: # # find_package(FFTW [REQUIRED] [QUIET] # [COMPONENTS [single] [double] [long_double] [quad]]) # # By default, search for the double precision library ``fftw3`` # # Search procedure # ---------------- # # * FFTW_LIBRARIES and FFTW_INCLUDE_DIRS set by user # # * Nothing is searched and these variables are used instead # # * Find MKL implementation via FFTW_ENABLE_MKL # # * If FFTW_ENABLE_MKL is explicitly set to ON, only MKL is considered # * If FFTW_ENABLE_MKL is explicitly set to OFF, MKL will not be considered # * If FFTW_ENABLE_MKL is undefined, MKL is preferred unless ENABLE_MKL is explicitly set to OFF # * Note: MKLROOT environment variable helps to detect MKL (See FindMKL.cmake) # # * Find ARMPL or NVPL implementations, via FFTW_ENABLE_ARMPL or FFTW_ENABLE_NVPL, with behaviour as for MKL # # * Find official FFTW implementation # # * FFTW_ROOT variable / environment variable helps to detect FFTW # # Components # ---------- # # If a different version or multiple versions of the library are required, # these need to be specified as ``COMPONENTS``. Note that double must be given # explicitly if any ``COMPONENTS`` are specified. # # The libraries corresponding to each of the ``COMPONENTS`` are: # # :single: ``FFTW::fftw3f`` # :double: ``FFTW::fftw3`` # :long_double: ``FFTW::fftw3l`` # :quad: ``FFTW::fftw3q`` # # Output variables # ---------------- # # The following CMake variables are set on completion: # # :FFTW_FOUND: true if FFTW is found on the system # :FFTW_LIBRARIES: full paths to requested FFTW libraries # :FFTW_INCLUDE_DIRS: FFTW include directory # # Input variables # --------------- # # The following CMake variables are checked by the function: # # :FFTW_USE_STATIC_LIBS: if true, only static libraries are found # :FFTW_ROOT: if set, this path is exclusively searched # :FFTW_DIR: equivalent to FFTW_ROOT (deprecated) # :FFTW_PATH: equivalent to FFTW_ROOT (deprecated) # :FFTW_LIBRARIES: User overriden FFTW libraries # :FFTW_INCLUDE_DIRS: User overriden FFTW includes directories # :FFTW_ENABLE_MKL: User requests use of MKL implementation # :FFTW_ENABLE_ARMPL: User requests use of ARMPL implementation # :FFTW_ENABLE_NVPL: User requests use of NVPL implementation # ############################################################################## list( APPEND _possible_components double single long_double quad ) if( NOT FFTW_FIND_COMPONENTS ) set( FFTW_FIND_COMPONENTS double ) endif() set( FFTW_double_LIBRARY_NAME fftw3 ) set( FFTW_single_LIBRARY_NAME fftw3f ) set( FFTW_long_double_LIBRARY_NAME fftw3l ) set( FFTW_quad_LIBRARY_NAME fftw3q ) macro( FFTW_CHECK_ALL_COMPONENTS ) set( FFTW_FOUND_ALL_COMPONENTS TRUE ) foreach( _component ${FFTW_FIND_COMPONENTS} ) if( NOT FFTW_${_component}_FOUND ) set( FFTW_FOUND_ALL_COMPONENTS false ) endif() endforeach() endmacro() # Command line override foreach( _component ${FFTW_FIND_COMPONENTS} ) if( NOT FFTW_${_component}_LIBRARIES AND FFTW_LIBRARIES ) set( FFTW_${_component}_LIBRARIES ${FFTW_LIBRARIES} ) endif() if( FFTW_${_component}_LIBRARIES ) set( FFTW_${_component}_FOUND TRUE ) endif() endforeach() ### Check MKL FFTW_CHECK_ALL_COMPONENTS() if( NOT FFTW_FOUND_ALL_COMPONENTS ) if( NOT DEFINED FFTW_ENABLE_MKL AND NOT DEFINED ENABLE_MKL ) set( FFTW_ENABLE_MKL ON ) set( FFTW_FindMKL_OPTIONS QUIET ) elseif( FFTW_ENABLE_MKL ) set( FFTW_MKL_REQUIRED TRUE ) elseif( ENABLE_MKL AND NOT DEFINED FFTW_ENABLE_MKL ) set( FFTW_ENABLE_MKL ON ) endif() if( FFTW_ENABLE_MKL ) if( NOT MKL_FOUND ) find_package( MKL ${FFTW_FindMKL_OPTIONS} ) endif() if( MKL_FOUND ) if( NOT FFTW_INCLUDE_DIRS ) set( FFTW_INCLUDE_DIRS ${MKL_INCLUDE_DIRS}/fftw ) endif() if( NOT FFTW_LIBRARIES ) set( FFTW_LIBRARIES ${MKL_LIBRARIES} ) endif() foreach( _component ${FFTW_FIND_COMPONENTS} ) set( FFTW_${_component}_FOUND TRUE ) set( FFTW_${_component}_LIBRARIES ${MKL_LIBRARIES} ) endforeach() else() if( FFTW_MKL_REQUIRED ) if( FFTW_FIND_REQUIRED ) message(CRITICAL "FindFFTW: MKL required, but MKL was not found" ) else() if( NOT FFTW_MKL_FIND_QUIETLY ) message(STATUS "FindFFTW: MKL required, but MKL was not found" ) endif() set( FFTW_FOUND FALSE ) return() endif() endif() endif() endif() endif() ### Check ARMPL FFTW_CHECK_ALL_COMPONENTS() if( NOT FFTW_FOUND_ALL_COMPONENTS ) if( NOT DEFINED FFTW_ENABLE_ARMPL AND NOT DEFINED ENABLE_ARMPL ) set( FFTW_ENABLE_ARMPL ON ) set( FFTW_FindARMPL_OPTIONS QUIET ) elseif( FFTW_ENABLE_ARMPL ) set( FFTW_ARMPL_REQUIRED TRUE ) elseif( ENABLE_ARMPL AND NOT DEFINED FFTW_ENABLE_ARMPL ) set( FFTW_ENABLE_ARMPL ON ) endif() if( FFTW_ENABLE_ARMPL ) if( NOT ARMPL_FOUND ) find_package( ARMPL ${FFTW_FindARMPL_OPTIONS} ) endif() if( ARMPL_FOUND ) if( NOT FFTW_INCLUDE_DIRS ) set( FFTW_INCLUDE_DIRS ${ARMPL_INCLUDE_DIRS} ) endif() if( NOT FFTW_LIBRARIES ) set( FFTW_LIBRARIES ${ARMPL_LIBRARIES} ) endif() foreach( _component ${FFTW_FIND_COMPONENTS} ) set( FFTW_${_component}_FOUND TRUE ) set( FFTW_${_component}_LIBRARIES ${ARMPL_LIBRARIES} ) endforeach() else() if( FFTW_ARMPL_REQUIRED ) if( FFTW_FIND_REQUIRED ) message(CRITICAL "FindFFTW: ARMPL required, but was not found" ) else() if( NOT FFTW_ARMPL_FIND_QUIETLY ) message(STATUS "FindFFTW: ARMPL required, but was not found" ) endif() set( FFTW_FOUND FALSE ) return() endif() endif() endif() endif() endif() ### Check NVPL FFTW_CHECK_ALL_COMPONENTS() if( NOT FFTW_FOUND_ALL_COMPONENTS ) if( NOT DEFINED FFTW_ENABLE_NVPL AND NOT DEFINED ENABLE_NVPL ) set( FFTW_ENABLE_NVPL ON ) set( FFTW_FindNVPL_OPTIONS QUIET ) elseif( FFTW_ENABLE_NVPL ) set( FFTW_NVPL_REQUIRED TRUE ) elseif( ENABLE_NVPL AND NOT DEFINED FFTW_ENABLE_NVPL ) set( FFTW_ENABLE_NVPL ON ) endif() if( FFTW_ENABLE_NVPL ) if( NOT NVPL_FOUND ) find_package( NVPL ${FFTW_FindNVPL_OPTIONS} ) endif() if( NVPL_FOUND ) if( NOT FFTW_INCLUDE_DIRS ) set( FFTW_INCLUDE_DIRS ${NVPL_INCLUDE_DIRS} ) endif() if( NOT FFTW_LIBRARIES ) set( FFTW_LIBRARIES ${NVPL_LIBRARIES} ) endif() foreach( _component ${FFTW_FIND_COMPONENTS} ) set( FFTW_${_component}_FOUND TRUE ) set( FFTW_${_component}_LIBRARIES ${NVPL_LIBRARIES} ) endforeach() else() if( FFTW_NVPL_REQUIRED ) if( FFTW_FIND_REQUIRED ) message(CRITICAL "FindFFTW: NVPL required, but NVPL was not found" ) else() if( NOT FFTW_NVPL_FIND_QUIETLY ) message(STATUS "FindFFTW: NVPL required, but NVPL was not found" ) endif() set( FFTW_FOUND FALSE ) return() endif() endif() endif() endif() endif() ### Standard FFTW if( (NOT FFTW_ROOT) AND EXISTS $ENV{FFTW_ROOT} ) set( FFTW_ROOT $ENV{FFTW_ROOT} ) endif() if( (NOT FFTW_ROOT) AND FFTW_DIR ) set( FFTW_ROOT ${FFTW_DIR} ) endif() if( (NOT FFTW_ROOT) AND EXISTS $ENV{FFTW_DIR} ) set( FFTW_ROOT $ENV{FFTW_DIR} ) endif() if( (NOT FFTW_ROOT) AND FFTWDIR ) set( FFTW_ROOT ${FFTWDIR} ) endif() if( (NOT FFTW_ROOT) AND EXISTS $ENV{FFTWDIR} ) set( FFTW_ROOT $ENV{FFTWDIR} ) endif() if( (NOT FFTW_ROOT) AND FFTW_PATH ) set( FFTW_ROOT ${FFTW_PATH} ) endif() if( (NOT FFTW_ROOT) AND EXISTS $ENV{FFTW_PATH}) set( FFTW_ROOT $ENV{FFTW_PATH} ) endif() if( FFTW_ROOT ) # On cc[a|b|t] FFTW_DIR is set to the lib directory :( get_filename_component(_dirname ${FFTW_ROOT} NAME) if( _dirname MATCHES "lib" ) set( FFTW_ROOT "${FFTW_ROOT}/.." ) endif() endif() if( NOT FFTW_ROOT ) # Check if we can use PkgConfig find_package(PkgConfig) #Determine from PKG if( PKG_CONFIG_FOUND AND NOT FFTW_ROOT ) pkg_check_modules( PKG_FFTW QUIET "fftw3" ) endif() endif() #Check whether to search static or dynamic libs set( CMAKE_FIND_LIBRARY_SUFFIXES_SAV ${CMAKE_FIND_LIBRARY_SUFFIXES} ) if( ${FFTW_USE_STATIC_LIBS} ) set( CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_STATIC_LIBRARY_SUFFIX} ) else() set( CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_SHARED_LIBRARY_SUFFIX} ) endif() if( FFTW_ROOT ) set( _default_paths NO_DEFAULT_PATH ) set( _lib_paths ${FFTW_ROOT} ) set( _include_paths ${FFTW_ROOT} ) else() set( _lib_paths ${PKG_FFTW_LIBRARY_DIRS} ${LIB_INSTALL_DIR} ) set( _include_paths ${PKG_FFTW_INCLUDE_DIRS} ${INCLUDE_INSTALL_DIR} ) endif() # find includes if( NOT FFTW_INCLUDE_DIRS ) find_path( FFTW_INCLUDE_DIR NAMES "fftw3.h" PATHS ${_include_paths} PATH_SUFFIXES "include" ${_default_paths} ) if( NOT FFTW_INCLUDE_DIR ) if( NOT FFTW_FIND_QUIETLY OR FFTW_FIND_REQUIRED ) message( STATUS "FindFFTW: fftw include headers not found") endif() endif() set( FFTW_INCLUDE_DIRS ${FFTW_INCLUDE_DIR} ) endif() # find libs foreach( _component ${FFTW_FIND_COMPONENTS} ) if( NOT FFTW_${_component}_LIBRARIES ) find_library( FFTW_${_component}_LIB NAMES ${FFTW_${_component}_LIBRARY_NAME} PATHS ${_lib_paths} PATH_SUFFIXES "lib" "lib64" ${_default_paths} ) set( FFTW_${_component}_LIBRARIES ${FFTW_${_component}_LIB} ) if( FFTW_${_component}_LIBRARIES ) set( FFTW_${_component}_FOUND TRUE ) else() if( NOT FFTW_FIND_QUIETLY OR FFTW_FIND_REQUIRED ) message(STATUS "FindFFTW: ${_component} precision required, but ${FFTW_${_component}_LIBRARY_NAME} was not found") endif() set( FFTW_${_component}_FOUND FALSE ) endif() endif() endforeach() # Assemble FFTW_LIBRARIES if( NOT FFTW_LIBRARIES ) foreach( _component ${FFTW_FIND_COMPONENTS} ) list( APPEND FFTW_LIBRARIES ${FFTW_${_component}_LIBRARIES} ) endforeach() list( REMOVE_DUPLICATES FFTW_LIBRARIES ) endif() # FFTW CREATE_INTERFACE_TARGETS foreach( _component ${FFTW_FIND_COMPONENTS} ) set( _target FFTW::${FFTW_${_component}_LIBRARY_NAME} ) if( FFTW_${_component}_FOUND AND NOT TARGET ${_target} ) add_library( ${_target} INTERFACE IMPORTED ) target_link_libraries( ${_target} INTERFACE ${FFTW_${_component}_LIBRARIES} ) target_include_directories( ${_target} INTERFACE ${FFTW_INCLUDE_DIRS} ) endif() endforeach() if( NOT FFTW_FIND_QUIETLY AND FFTW_LIBRARIES ) message( STATUS "FFTW targets:" ) foreach( _component ${FFTW_FIND_COMPONENTS} ) set( _target FFTW::${FFTW_${_component}_LIBRARY_NAME} ) message( STATUS " ${_target} (${_component} precision) [${FFTW_${_component}_LIBRARIES}]") endforeach() endif() set( CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES_SAV} ) include(FindPackageHandleStandardArgs) find_package_handle_standard_args( FFTW REQUIRED_VARS FFTW_INCLUDE_DIRS FFTW_LIBRARIES HANDLE_COMPONENTS ) set( FFTW_INCLUDES ${FFTW_INCLUDE_DIRS} ) # deprecated set( FFTW_LIB ${FFTW_double_LIBRARIES} ) # deprecated mark_as_advanced(FFTW_INCLUDE_DIRS FFTW_LIBRARIES FFTW_LIB) ecbuild-3.13.1/cmake/FindJemalloc.cmake000066400000000000000000000030031513706760700176270ustar00rootroot00000000000000# (C) Copyright 2011- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation nor # does it submit to any jurisdiction. ############################################################################## #.rst: # # FindJemalloc # ============ # # Find the Jemalloc library. :: # # find_package( Jemalloc [REQUIRED] [QUIET] ) # # Output variables # ---------------- # # The following CMake variables are set on completion: # # :Jemalloc_FOUND: true if Jemalloc is found on the system # :JEMALLOC_LIBRARIES: full paths to requested Jemalloc libraries # :JEMALLOC_INCLUDE_DIRS: Jemalloc include directory # # Input variables # --------------- # # The following CMake and environment variables are considered: # # :Jemalloc_ROOT: # ############################################################################## find_library( JEMALLOC_LIBRARIES NAMES jemalloc ) find_path( JEMALLOC_INCLUDE_DIRS NAMES jemalloc/jemalloc.h ) include(FindPackageHandleStandardArgs) find_package_handle_standard_args(Jemalloc DEFAULT_MSG JEMALLOC_LIBRARIES JEMALLOC_INCLUDE_DIRS ) if( JEMALLOC_LIBRARIES ) get_filename_component( JEMALLOC_LIBRARY_DIR ${JEMALLOC_LIBRARIES} DIRECTORY ) endif() mark_as_advanced( JEMALLOC_INCLUDE_DIRS JEMALLOC_LIBRARIES JEMALLOC_LIBRARY_DIR ) ecbuild-3.13.1/cmake/FindLEX.cmake000066400000000000000000000116011513706760700165340ustar00rootroot00000000000000# - Find lex executable and provides a macro to generate custom build rules # # The module defines the following variables: # LEX_FOUND - true is lex executable is found # LEX_EXECUTABLE - the path to the lex executable # LEX_LIBRARIES - The lex libraries # LEX_INCLUDE_DIRS - The path to the lex headers # # # If lex is found on the system, the module provides the macro: # LEX_TARGET(Name LexInput LexOutput [COMPILE_FLAGS ]) # which creates a custom command to generate the file from # the file. If COMPILE_FLAGS option is specified, the next # parameter is added to the lex command line. Name is an alias used to # get details of this custom command. Indeed the macro defines the # following variables: # LEX_${Name}_DEFINED - true is the macro ran successfully # LEX_${Name}_OUTPUTS - the source file generated by the custom rule, an # alias for LexOutput # LEX_${Name}_INPUT - the lex source file, an alias for ${LexInput} # # Lex scanners oftenly use tokens defined by Yacc: the code generated # by Lex depends of the header generated by Yacc. This module also # defines a macro: # ADD_LEX_YACC_DEPENDENCY(LexTarget YaccTarget) # which adds the required dependency between a scanner and a parser # where and are the first parameters of # respectively LEX_TARGET and YACC_TARGET macros. # # ==================================================================== #============================================================================= # Copyright 2009 Kitware, Inc. # Copyright 2006 Tristan Carel # # Distributed under the OSI-approved BSD License (the "License"); # see accompanying file Copyright.txt for details. # # This software is distributed WITHOUT ANY WARRANTY; without even the # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # See the License for more information. #============================================================================= # This file is based on the FindFLEX CMake macro, and adapted by ECMWF #============================================================================= # (C) Copyright 2011- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation nor # does it submit to any jurisdiction. FIND_PROGRAM(LEX_EXECUTABLE lex DOC "path to the lex executable") MARK_AS_ADVANCED(LEX_EXECUTABLE) FIND_LIBRARY(FL_LIBRARY NAMES fl DOC "Path to the fl library") FIND_PATH(LEX_INCLUDE_DIR LexLexer.h DOC "Path to the lex headers") MARK_AS_ADVANCED(FL_LIBRARY LEX_INCLUDE_DIR) SET(LEX_INCLUDE_DIRS ${LEX_INCLUDE_DIR}) SET(LEX_LIBRARIES ${FL_LIBRARY}) IF(LEX_EXECUTABLE) #============================================================ # LEX_TARGET (public macro) #============================================================ # MACRO(LEX_TARGET Name Input Output) SET(LEX_TARGET_usage "LEX_TARGET( [COMPILE_FLAGS ]") IF(${ARGC} GREATER 3) IF(${ARGC} EQUAL 5) IF("${ARGV3}" STREQUAL "COMPILE_FLAGS") SET(LEX_EXECUTABLE_opts "${ARGV4}") SEPARATE_ARGUMENTS(LEX_EXECUTABLE_opts) ELSE() MESSAGE(SEND_ERROR ${LEX_TARGET_usage}) ENDIF() ELSE() MESSAGE(SEND_ERROR ${LEX_TARGET_usage}) ENDIF() ENDIF() message( STATUS "${LEX_EXECUTABLE} ${LEX_EXECUTABLE_opts} -t ${Input} > ${Output}" ) ADD_CUSTOM_COMMAND(OUTPUT ${Output} COMMAND ${LEX_EXECUTABLE} ${LEX_EXECUTABLE_opts} -t ${Input} > ${Output} DEPENDS ${Input} COMMENT "[LEX][${Name}] Building scanner with lex ${LEX_VERSION}" WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) SET(LEX_${Name}_DEFINED TRUE) SET(LEX_${Name}_OUTPUTS ${Output}) SET(LEX_${Name}_INPUT ${Input}) SET(LEX_${Name}_COMPILE_FLAGS ${LEX_EXECUTABLE_opts}) ENDMACRO(LEX_TARGET) #============================================================ #============================================================ # ADD_LEX_YACC_DEPENDENCY (public macro) #============================================================ # MACRO(ADD_LEX_YACC_DEPENDENCY LexTarget YaccTarget) IF(NOT LEX_${LexTarget}_OUTPUTS) MESSAGE(SEND_ERROR "Lex target `${LexTarget}' does not exists.") ENDIF() IF(NOT YACC_${YaccTarget}_OUTPUT_HEADER) MESSAGE(SEND_ERROR "Yacc target `${YaccTarget}' does not exists.") ENDIF() SET_SOURCE_FILES_PROPERTIES(${LEX_${LexTarget}_OUTPUTS} PROPERTIES OBJECT_DEPENDS ${YACC_${YaccTarget}_OUTPUT_HEADER}) ENDMACRO(ADD_LEX_YACC_DEPENDENCY) #============================================================ ENDIF(LEX_EXECUTABLE) FIND_PACKAGE_HANDLE_STANDARD_ARGS(LEX REQUIRED_VARS LEX_EXECUTABLE) # FindLEX.cmake ends here ecbuild-3.13.1/cmake/FindMKL.cmake000066400000000000000000000060521513706760700165330ustar00rootroot00000000000000# (C) Copyright 2011- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation # nor does it submit to any jurisdiction. # - Try to find MKL # Once done this will define # # MKL_FOUND - system has Intel MKL # MKL_INCLUDE_DIRS - the MKL include directories # MKL_LIBRARIES - link these to use MKL # # The following paths will be searched with priority if set in CMake or env # # MKLROOT - root directory of the MKL installation # MKL_PATH - root directory of the MKL installation # MKL_ROOT - root directory of the MKL installation option( MKL_PARALLEL "if mkl shoudl be parallel" OFF ) if( MKL_PARALLEL ) set( __mkl_lib_par MKL_LIB_INTEL_THREAD ) set( __mkl_lib_name mkl_intel_thread ) find_package(Threads) else() set( __mkl_lib_par MKL_LIB_SEQUENTIAL ) set( __mkl_lib_name mkl_sequential ) endif() # Search with priority for MKLROOT, MKL_PATH and MKL_ROOT if set in CMake or env find_path(MKL_INCLUDE_DIR mkl.h PATHS ${MKLROOT} ${MKL_PATH} ${MKL_ROOT} $ENV{MKLROOT} $ENV{MKL_PATH} $ENV{MKL_ROOT} PATH_SUFFIXES include NO_DEFAULT_PATH) find_path(MKL_INCLUDE_DIR mkl.h PATH_SUFFIXES include) if( MKL_INCLUDE_DIR ) # use include dir to find libs set( MKL_INCLUDE_DIRS ${MKL_INCLUDE_DIR} ) if( CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" ) set( __pathsuffix "lib/intel64") set( __libsfx _lp64 ) else() set( __pathsuffix "lib/ia32") set( __libsfx "" ) endif() find_library( MKL_LIB_INTEL PATHS ${MKLROOT} ${MKL_PATH} ${MKL_ROOT} $ENV{MKLROOT} $ENV{MKL_PATH} $ENV{MKL_ROOT} PATH_SUFFIXES lib ${__pathsuffix} NAMES mkl_intel${__libsfx} ) find_library( ${__mkl_lib_par} PATHS ${MKLROOT} ${MKL_PATH} ${MKL_ROOT} $ENV{MKLROOT} $ENV{MKL_PATH} $ENV{MKL_ROOT} PATH_SUFFIXES lib ${__pathsuffix} NAMES ${__mkl_lib_name} ) find_library( MKL_LIB_CORE PATHS ${MKLROOT} ${MKL_PATH} ${MKL_ROOT} $ENV{MKLROOT} $ENV{MKL_PATH} $ENV{MKL_ROOT} PATH_SUFFIXES lib ${__pathsuffix} NAMES mkl_core ) if( MKL_PARALLEL ) find_library( MKL_LIB_IOMP5 PATHS ${MKLROOT} ${MKL_PATH} ${MKL_ROOT} $ENV{MKLROOT} $ENV{MKL_PATH} $ENV{MKL_ROOT} PATH_SUFFIXES lib ${__pathsuffix} NAMES iomp5 ) endif() if( MKL_LIB_INTEL AND ${__mkl_lib_par} AND MKL_LIB_CORE ) set( MKL_LIBRARIES ${MKL_LIB_INTEL} ${${__mkl_lib_par}} ${MKL_LIB_CORE} ${MKL_LIB_IOMP5} ${CMAKE_THREAD_LIBS_INIT} ) endif() endif() include(FindPackageHandleStandardArgs) find_package_handle_standard_args( MKL DEFAULT_MSG MKL_LIBRARIES MKL_INCLUDE_DIRS ) mark_as_advanced( MKL_INCLUDE_DIR MKL_LIB_LAPACK MKL_LIB_INTEL MKL_LIB_SEQUENTIAL MKL_LIB_CORE ) ecbuild-3.13.1/cmake/FindNVPL.cmake000066400000000000000000000051171513706760700166700ustar00rootroot00000000000000# (C) Copyright 2011- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation # nor does it submit to any jurisdiction. # - Try to find NVPL # Once done this will define # # NVPL_FOUND - system has Nvidia Performance Libraries # NVPL_INCLUDE_DIRS - the NVPL include directories # NVPL_LIBRARIES - link these to use NVPL # # The following paths will be searched with priority if set in CMake or env # # NVPLROOT - root directory of the NVPL installation # NVPL_PATH - root directory of the NVPL installation # NVPL_ROOT - root directory of the NVPL installation option( NVPL_PARALLEL "if nvpl shoudl be parallel" OFF ) if( NVPL_PARALLEL ) set( __nvpl_lib_suffix "_gomp" ) find_package(Threads) else() set( __nvpl_lib_suffix "_seq" ) endif() # Search with priority for NVPLROOT, NVPL_PATH and NVPL_ROOT if set in CMake or env find_path(NVPL_INCLUDE_DIR nvpl_blas.h PATHS ${NVPLROOT} ${NVPL_PATH} ${NVPL_ROOT} $ENV{NVPLROOT} $ENV{NVPL_PATH} $ENV{NVPL_ROOT} PATH_SUFFIXES include NO_DEFAULT_PATH) find_path(NVPL_INCLUDE_DIR_FFTW fftw3.h PATH_SUFFIXES include/nvpl_fftw) if( NVPL_INCLUDE_DIR ) # use include dir to find libs set( NVPL_INCLUDE_DIRS ${NVPL_INCLUDE_DIR} ${NVPL_INCLUDE_DIR_FFTW} ) # set(CMAKE_FIND_DEBUG_MODE TRUE) find_library( NVPL_LIB_BLAS_CORE PATHS ${NVPLROOT} ${NVPL_PATH} ${NVPL_ROOT} $ENV{NVPLROOT} $ENV{NVPL_PATH} $ENV{NVPL_ROOT} PATH_SUFFIXES "lib" NAMES nvpl_blas_core ) find_library( NVPL_LIB_BLAS PATHS ${NVPLROOT} ${NVPL_PATH} ${NVPL_ROOT} $ENV{NVPLROOT} $ENV{NVPL_PATH} $ENV{NVPL_ROOT} PATH_SUFFIXES "lib" NAMES nvpl_blas_lp64${__nvpl_lib_suffix} ) find_library( NVPL_LIB_FFTW PATHS ${NVPLROOT} ${NVPL_PATH} ${NVPL_ROOT} $ENV{NVPLROOT} $ENV{NVPL_PATH} $ENV{NVPL_ROOT} PATH_SUFFIXES "lib" NAMES nvpl_fftw ) # set(CMAKE_FIND_DEBUG_MODE FALSE) if( NVPL_LIB_BLAS_CORE AND NVPL_LIB_BLAS AND NVPL_LIB_FFTW ) set( NVPL_LIBRARIES ${NVPL_LIB_BLAS_CORE} ${NVPL_LIB_BLAS} ${NVPL_LIB_FFTW} ) endif() endif() include(FindPackageHandleStandardArgs) find_package_handle_standard_args( NVPL DEFAULT_MSG NVPL_LIBRARIES NVPL_INCLUDE_DIRS ) mark_as_advanced( NVPL_INCLUDE_DIR NVPL_LIB_BLAS NVPL_LIB_FFTW ) ecbuild-3.13.1/cmake/FindNetCDF.cmake000066400000000000000000000205201513706760700171470ustar00rootroot00000000000000# (C) Copyright 2011- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation nor # does it submit to any jurisdiction. # Try to find NetCDF includes and library # # This module defines # # - NetCDF_FOUND - System has NetCDF # - NetCDF_VERSION - the version of NetCDF # # Following components are available: # # - C - C interface to NetCDF (netcdf) # - CXX - CXX4 interface to NetCDF (netcdf_c++4) # - Fortran - Fortran interface to NetCDF (netcdff) # - CXX_LEGACY - Legacy C++ interface to NetCDF (netcdf_c++) # # For each component the following are defined: # # - NetCDF__FOUND - whether the component is found # - NetCDF::NetCDF_ - target of component to be used with target_link_libraries() # # Caveat: The targets might not link properly with static libraries, setting NetCDF__EXTRA_LIBRARIES may be required. # # The following paths will be searched in order if set in CMake (first priority) or environment (second priority) # # - NetCDF__ROOT # - NetCDF__DIR # - NetCDF__PATH # - The same variables with a NETCDF, NetCDF4, or NETCDF4 prefix instead of NetCDF # - NetCDF_ROOT # - NetCDF_DIR # - NetCDF_PATH # - The same variables with a NETCDF, NetCDF4, or NETCDF4 prefix instead of NetCDF # # The following variables affect the targets and NetCDF*_LIBRARIES variables: # # - NetCDF__EXTRA_LIBRARIES - added to NetCDF::NetCDF_ INTERFACE_LINK_LIBRARIES and NetCDF__LIBRARIES # # Notes: # # - If no components are defined, only the C component will be searched. # list( APPEND _possible_components C CXX Fortran CXX_LEGACY ) ## Header names for each component set( NetCDF_C_INCLUDE_NAME netcdf.h ) set( NetCDF_CXX_INCLUDE_NAME netcdf ) set( NetCDF_CXX_LEGACY_INCLUDE_NAME netcdfcpp.h ) set( NetCDF_Fortran_INCLUDE_NAME netcdf.mod NETCDF.mod ) ## Library names for each component set( NetCDF_C_LIBRARY_NAME netcdf ) set( NetCDF_CXX_LIBRARY_NAME netcdf_c++4 netcdf-cxx4 ) set( NetCDF_CXX_LEGACY_LIBRARY_NAME netcdf_c++ ) set( NetCDF_Fortran_LIBRARY_NAME netcdff ) foreach( _comp ${_possible_components} ) string( TOUPPER "${_comp}" _COMP ) set( _arg_${_COMP} ${_comp} ) set( _name_${_COMP} ${_comp} ) endforeach() unset( _search_components ) foreach( _comp ${${CMAKE_FIND_PACKAGE_NAME}_FIND_COMPONENTS} ) string( TOUPPER "${_comp}" _COMP ) set( _arg_${_COMP} ${_comp} ) list( APPEND _search_components ${_name_${_COMP}} ) if( NOT _name_${_COMP} ) message( FATAL_ERROR "Find${CMAKE_FIND_PACKAGE_NAME}: COMPONENT ${_comp} is not a valid component. Valid components: ${_possible_components}" ) endif() endforeach() if( NOT _search_components ) set( _search_components C ) endif() ## Search hints for finding include directories and libraries foreach( _comp IN ITEMS "" "C" "CXX" "Fortran" "CXX_LEGACY" ) set( __comp "_${_comp}" ) if( NOT _comp ) set( __comp "" ) endif() set( _search_hints${__comp} ) foreach( _name IN ITEMS NetCDF NETCDF NetCDF4 NETCDF4 ) foreach( _var IN ITEMS ROOT DIR PATH ) list( APPEND _search_hints${__comp} ${${_name}${__comp}_${_var}} ENV ${_name}${__comp}_${_var} ) endforeach() endforeach() ## Old-school HPC module env variable names foreach( _name IN ITEMS NetCDF NETCDF NetCDF4 NETCDF4 ) list(APPEND _search_hints${__comp} ${${_name}${__comp}} ENV ${_name}${__comp}) endforeach() endforeach() set( _found FALSE ) set( _req_vars ) foreach( _comp ${_search_components} ) list( APPEND _req_vars NetCDF_${_comp}_INCLUDE_DIR NetCDF_${_comp}_LIBRARY ) ## Find include directories find_path(NetCDF_${_comp}_INCLUDE_DIR NAMES ${NetCDF_${_comp}_INCLUDE_NAME} DOC "netcdf ${_comp} include directory" HINTS ${_search_hints_${_comp}} ${_search_hints} PATH_SUFFIXES include ../../include ) mark_as_advanced(NetCDF_${_comp}_INCLUDE_DIR) ## Find libraries for each component string( TOUPPER "${_comp}" _COMP ) find_library(NetCDF_${_comp}_LIBRARY NAMES ${NetCDF_${_comp}_LIBRARY_NAME} DOC "netcdf ${_comp} library" HINTS ${_search_hints_${_comp}} ${_search_hints} PATH_SUFFIXES lib ../../lib ) mark_as_advanced(NetCDF_${_comp}_LIBRARY) if( NetCDF_${_comp}_LIBRARY AND NOT (NetCDF_${_comp}_LIBRARY MATCHES ".a$") ) set( NetCDF_${_comp}_LIBRARY_SHARED TRUE ) endif() if( NetCDF_${_comp}_LIBRARY AND NetCDF_${_comp}_INCLUDE_DIR ) set( ${CMAKE_FIND_PACKAGE_NAME}_${_arg_${_COMP}}_FOUND TRUE ) set( _found TRUE ) if (NOT TARGET NetCDF::NetCDF_${_comp}) add_library(NetCDF::NetCDF_${_comp} UNKNOWN IMPORTED) set_target_properties(NetCDF::NetCDF_${_comp} PROPERTIES IMPORTED_LOCATION "${NetCDF_${_comp}_LIBRARY}" INTERFACE_INCLUDE_DIRECTORIES "${NetCDF_${_comp}_INCLUDE_DIR}") if( DEFINED NetCDF_${_comp}_EXTRA_LIBRARIES ) target_link_libraries(NetCDF::NetCDF_${_comp} INTERFACE ${NetCDF_${_comp}_EXTRA_LIBRARIES}) endif() endif() endif() endforeach() ## Find version if (_found) set( _config_search_hints ${_search_hints} ) set( _include_dirs ) foreach( _comp ${_search_components} ) if( DEFINED _search_hints_${_comp} ) list( APPEND _config_search_hints ${_search_hints_${_comp}} ) endif() if( DEFINED NetCDF_${_comp}_INCLUDE_DIR ) list( APPEND _include_dirs ${NetCDF_${_comp}_INCLUDE_DIR} ) endif() endforeach() if( _config_search_hints ) list( REMOVE_DUPLICATES _config_search_hints ) endif() if( _include_dirs ) list( REMOVE_DUPLICATES _include_dirs ) endif() find_program( NETCDF_CONFIG_EXECUTABLE NAMES nc-config HINTS ${_config_search_hints} PATH_SUFFIXES bin Bin ../../bin DOC "NetCDF nc-config helper" ) mark_as_advanced( NETCDF_CONFIG_EXECUTABLE ) find_file( NETCDF_META_H NAMES netcdf_meta.h HINTS ${_include_dirs} NO_DEFAULT_PATH DOC "NetCDF path to netcdf_meta.h" ) mark_as_advanced( NETCDF_META_H ) if( NETCDF_CONFIG_EXECUTABLE ) execute_process( COMMAND ${NETCDF_CONFIG_EXECUTABLE} --version RESULT_VARIABLE _netcdf_config_result OUTPUT_VARIABLE _netcdf_config_version) if( _netcdf_config_result EQUAL 0 ) string(REGEX REPLACE ".* ((([0-9]+)\\.)+([0-9]+)).*" "\\1" NetCDF_VERSION "${_netcdf_config_version}" ) endif() elseif( NETCDF_META_H ) file(STRINGS ${NETCDF_META_H} _netcdf_version_lines REGEX "#define[ \t]+NC_VERSION_(MAJOR|MINOR|PATCH|NOTE)") string(REGEX REPLACE ".*NC_VERSION_MAJOR *\([0-9]*\).*" "\\1" _netcdf_version_major "${_netcdf_version_lines}") string(REGEX REPLACE ".*NC_VERSION_MINOR *\([0-9]*\).*" "\\1" _netcdf_version_minor "${_netcdf_version_lines}") string(REGEX REPLACE ".*NC_VERSION_PATCH *\([0-9]*\).*" "\\1" _netcdf_version_patch "${_netcdf_version_lines}") string(REGEX REPLACE ".*NC_VERSION_NOTE *\"\([^\"]*\)\".*" "\\1" _netcdf_version_note "${_netcdf_version_lines}") set(NetCDF_VERSION "${_netcdf_version_major}.${_netcdf_version_minor}.${_netcdf_version_patch}${_netcdf_version_note}") unset(_netcdf_version_major) unset(_netcdf_version_minor) unset(_netcdf_version_patch) unset(_netcdf_version_note) unset(_netcdf_version_lines) endif() endif () ## Finalize find_package include(FindPackageHandleStandardArgs) find_package_handle_standard_args( ${CMAKE_FIND_PACKAGE_NAME} REQUIRED_VARS ${_req_vars} VERSION_VAR NetCDF_VERSION HANDLE_COMPONENTS ) if( ${CMAKE_FIND_PACKAGE_NAME}_FOUND AND NOT ${CMAKE_FIND_PACKAGE_NAME}_FIND_QUIETLY ) message( STATUS "Find${CMAKE_FIND_PACKAGE_NAME} defines targets:" ) foreach( _comp ${_search_components} ) string( TOUPPER "${_comp}" _COMP ) if( ${CMAKE_FIND_PACKAGE_NAME}_${_arg_${_COMP}}_FOUND ) message( STATUS " - NetCDF::NetCDF_${_comp} [${NetCDF_${_comp}_LIBRARY}]") endif() endforeach() endif() ## Backwards compatibility, only reachable if ECBUILD_2_COMPAT is ON # Assumes the following internal variables are defined: # - _search_components # - _arg_ # - NetCDF__INCLUDE_DIR # - NetCDF__LIBRARY include( netcdf_compat OPTIONAL ) ecbuild-3.13.1/cmake/FindTcmalloc.cmake000066400000000000000000000031731513706760700176470ustar00rootroot00000000000000# (C) Copyright 2011- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation nor # does it submit to any jurisdiction. ############################################################################## #.rst: # # FindTcmalloc # ============ # # Find the Tcmalloc library. :: # # find_package( Tcmalloc [REQUIRED] [QUIET] ) # # Output variables # ---------------- # # The following CMake variables are set on completion: # # :Tcmalloc_FOUND: true if Tcmalloc is found on the system # :TCMALLOC_LIBRARIES: full paths to requested Tcmalloc libraries # :TCMALLOC_LIBRARY_DIR: Directory containing the TCMALLOC_LIBRARIES # :TCMALLOC_INCLUDE_DIRS: Tcmalloc include directories # # Input variables # --------------- # # The following CMake / Environment variables are considered in order: # # :Tcmalloc_ROOT: CMake variable / Environment variable # ############################################################################## find_library( TCMALLOC_LIBRARIES NAMES tcmalloc ) find_path( TCMALLOC_INCLUDE_DIRS NAMES gperftools/tcmalloc.h ) if( TCMALLOC_LIBRARIES ) get_filename_component( TCMALLOC_LIBRARY_DIR ${TCMALLOC_LIBRARIES} DIRECTORY ) endif() include(FindPackageHandleStandardArgs) find_package_handle_standard_args(Tcmalloc DEFAULT_MSG TCMALLOC_LIBRARIES TCMALLOC_INCLUDE_DIRS ) mark_as_advanced( TCMALLOC_LIBRARIES TCMALLOC_INCLUDE_DIRS TCMALLOC_LIBRARY_DIR ) ecbuild-3.13.1/cmake/FindYACC.cmake000066400000000000000000000155351513706760700166350ustar00rootroot00000000000000# - Find yacc executable and provides macros to generate custom build rules # The module defines the following variables: # # YACC_EXECUTABLE - path to the yacc program # YACC_FOUND - true if the program was found # # The minimum required version of yacc can be specified using the # standard CMake syntax, e.g. find_package(YACC 2.1.3) # # If yacc is found, the module defines the macros: # YACC_TARGET( [VERBOSE ] # [COMPILE_FLAGS ]) # which will create a custom rule to generate a parser. is # the path to a yacc file. is the name of the source file # generated by yacc. A header file is also be generated, and contains # the token list. If COMPILE_FLAGS option is specified, the next # parameter is added in the yacc command line. if VERBOSE option is # specified, is created and contains verbose descriptions of the # grammar and parser. The macro defines a set of variables: # YACC_${Name}_DEFINED - true is the macro ran successfully # YACC_${Name}_INPUT - The input source file, an alias for # YACC_${Name}_OUTPUT_SOURCE - The source file generated by yacc # YACC_${Name}_OUTPUT_HEADER - The header file generated by yacc # YACC_${Name}_OUTPUTS - The sources files generated by yacc # YACC_${Name}_COMPILE_FLAGS - Options used in the yacc command line # # ==================================================================== #============================================================================= # Copyright 2009 Kitware, Inc. # Copyright 2006 Tristan Carel # # Distributed under the OSI-approved BSD License (the "License"); # see accompanying file Copyright.txt for details. # # This software is distributed WITHOUT ANY WARRANTY; without even the # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # See the License for more information. #============================================================================= # This file is based on the FindFLEX CMake macro, and adapted by ECMWF #============================================================================= # (C) Copyright 2011- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation nor # does it submit to any jurisdiction. FIND_PROGRAM(YACC_EXECUTABLE yacc DOC "path to the yacc/yacc executable") MARK_AS_ADVANCED(YACC_EXECUTABLE) IF(YACC_EXECUTABLE) # the yacc commands should be executed with the C locale, otherwise # the message (which are parsed) may be translated SET(_Yacc_SAVED_LC_ALL "$ENV{LC_ALL}") SET(ENV{LC_ALL} C) SET(ENV{LC_ALL} ${_Yacc_SAVED_LC_ALL}) # internal macro MACRO(YACC_TARGET_option_verbose Name YaccOutput filename) LIST(APPEND YACC_TARGET_cmdopt "--verbose") GET_FILENAME_COMPONENT(YACC_TARGET_output_path "${YaccOutput}" PATH) GET_FILENAME_COMPONENT(YACC_TARGET_output_name "${YaccOutput}" NAME_WE) ADD_CUSTOM_COMMAND(OUTPUT ${filename} COMMAND ${CMAKE_COMMAND} ARGS -E copy "${YACC_TARGET_output_path}/${YACC_TARGET_output_name}.output" "${filename}" DEPENDS "${YACC_TARGET_output_path}/${YACC_TARGET_output_name}.output" COMMENT "[YACC][${Name}] Copying yacc verbose table to ${filename}" WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) SET(YACC_${Name}_VERBOSE_FILE ${filename}) LIST(APPEND YACC_TARGET_extraoutputs "${YACC_TARGET_output_path}/${YACC_TARGET_output_name}.output") ENDMACRO(YACC_TARGET_option_verbose) # internal macro MACRO(YACC_TARGET_option_extraopts Options) SET(YACC_TARGET_extraopts "${Options}") SEPARATE_ARGUMENTS(YACC_TARGET_extraopts) LIST(APPEND YACC_TARGET_cmdopt ${YACC_TARGET_extraopts}) ENDMACRO(YACC_TARGET_option_extraopts) #============================================================ # YACC_TARGET (public macro) #============================================================ # MACRO(YACC_TARGET Name YaccInput YaccOutput) SET(YACC_TARGET_output_header "") SET(YACC_TARGET_cmdopt "") SET(YACC_TARGET_outputs "${YaccOutput}") IF(NOT ${ARGC} EQUAL 3 AND NOT ${ARGC} EQUAL 5 AND NOT ${ARGC} EQUAL 7) MESSAGE(SEND_ERROR "Usage") ELSE() # Parsing parameters IF(${ARGC} GREATER 5 OR ${ARGC} EQUAL 5) IF("${ARGV3}" STREQUAL "VERBOSE") YACC_TARGET_option_verbose(${Name} ${YaccOutput} "${ARGV4}") ENDIF() IF("${ARGV3}" STREQUAL "COMPILE_FLAGS") YACC_TARGET_option_extraopts("${ARGV4}") ENDIF() ENDIF() IF(${ARGC} EQUAL 7) IF("${ARGV5}" STREQUAL "VERBOSE") YACC_TARGET_option_verbose(${Name} ${YaccOutput} "${ARGV6}") ENDIF() IF("${ARGV5}" STREQUAL "COMPILE_FLAGS") YACC_TARGET_option_extraopts("${ARGV6}") ENDIF() ENDIF() # Header's name generated by yacc (see option -d) LIST(APPEND YACC_TARGET_cmdopt "-d") STRING(REGEX REPLACE "^(.*)(\\.[^.]*)$" "\\2" _fileext "${ARGV2}") STRING(REPLACE "c" "h" _fileext ${_fileext}) STRING(REGEX REPLACE "^(.*)(\\.[^.]*)$" "\\1${_fileext}" YACC_${Name}_OUTPUT_HEADER "${ARGV2}") LIST(APPEND YACC_TARGET_outputs "${YACC_${Name}_OUTPUT_HEADER}") # message ( STATUS "${YACC_EXECUTABLE} ${YACC_TARGET_cmdopt} ${CMAKE_CURRENT_BINARY_DIR}/${ARGV1}" ) # message ( STATUS "${CMAKE_COMMAND} -E rename ${CMAKE_CURRENT_BINARY_DIR}/y.tab.h ${YACC_${Name}_OUTPUT_HEADER}" ) # message ( STATUS "${CMAKE_COMMAND} -E rename ${CMAKE_CURRENT_BINARY_DIR}/y.tab.c ${ARGV2}" ) ADD_CUSTOM_COMMAND(OUTPUT ${YACC_TARGET_outputs} ${YACC_TARGET_extraoutputs} COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/${ARGV1} ${CMAKE_CURRENT_BINARY_DIR} COMMAND ${YACC_EXECUTABLE} ${YACC_TARGET_cmdopt} ${CMAKE_CURRENT_BINARY_DIR}/${ARGV1} COMMAND ${CMAKE_COMMAND} -E rename ${CMAKE_CURRENT_BINARY_DIR}/y.tab.h ${YACC_${Name}_OUTPUT_HEADER} COMMAND ${CMAKE_COMMAND} -E rename ${CMAKE_CURRENT_BINARY_DIR}/y.tab.c ${ARGV2} DEPENDS ${ARGV1} COMMENT "[YACC][${Name}] Building parser with yacc" WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) # define target variables SET(YACC_${Name}_DEFINED TRUE) SET(YACC_${Name}_INPUT ${ARGV1}) SET(YACC_${Name}_OUTPUTS ${YACC_TARGET_outputs}) SET(YACC_${Name}_COMPILE_FLAGS ${YACC_TARGET_cmdopt}) SET(YACC_${Name}_OUTPUT_SOURCE "${YaccOutput}") ENDIF(NOT ${ARGC} EQUAL 3 AND NOT ${ARGC} EQUAL 5 AND NOT ${ARGC} EQUAL 7) ENDMACRO(YACC_TARGET) # #============================================================ ENDIF(YACC_EXECUTABLE) FIND_PACKAGE_HANDLE_STANDARD_ARGS(YACC REQUIRED_VARS YACC_EXECUTABLE ) # FindYACC.cmake ends here ecbuild-3.13.1/cmake/Findecbuild.cmake000066400000000000000000000024671513706760700175250ustar00rootroot00000000000000# (C) Copyright 2019- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation nor # does it submit to any jurisdiction. find_path(ecbuild_MACROS_DIR ecbuild.cmake HINTS ${CMAKE_CURRENT_LIST_DIR} PATH_SUFFIXES cmake share/cmake share/ecbuild/cmake NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH) if(ecbuild_MACROS_DIR) include(${ecbuild_MACROS_DIR}/ecbuild_parse_version.cmake) ecbuild_parse_version_file(${ecbuild_MACROS_DIR}/VERSION PREFIX ecbuild) endif() include(FindPackageHandleStandardArgs) find_package_handle_standard_args(ecbuild REQUIRED_VARS ecbuild_MACROS_DIR VERSION_VAR ecbuild_VERSION) if(ecbuild_FOUND) include(ecbuild) find_path(ecbuild_DIR ecbuild-config.cmake HINTS ${CMAKE_CURRENT_LIST_DIR}/../ ${CMAKE_CURRENT_LIST_DIR}/../../../ PATH_SUFFIXES lib/cmake/ecbuild lib64/cmake/ecbuild lib/${CMAKE_LIBRARY_ARCHITECTURE}/cmake/ecbuild NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH) endif() ecbuild-3.13.1/cmake/VERSION000066400000000000000000000000071513706760700153470ustar00rootroot000000000000003.13.1 ecbuild-3.13.1/cmake/compat/000077500000000000000000000000001513706760700155655ustar00rootroot00000000000000ecbuild-3.13.1/cmake/compat/FindNAG.cmake000066400000000000000000000030241513706760700177740ustar00rootroot00000000000000# (C) Copyright 2011- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation # nor does it submit to any jurisdiction. # - Try to find the NAG includes and library # This module defines # # NAG_FOUND - System has NAG # NAG_INCLUDE_DIRS - the NAG include directories # NAG_LIBRARIES - the libraries needed to use NAG # # The following paths will be searched with priority if set in CMake or env # # NAG_DIR - root folder of the NAG installation # NAG_PATH - root folder of the NAG installation find_path( NAG_INCLUDE_DIR nag_precisions.mod PATHS ${NAG_PATH} ENV NAG_PATH ${NAG_DIR} ENV NAG_DIR PATH_SUFFIXES include NO_DEFAULT_PATH ) find_library( NAG_LIBRARY NAMES nag PATHS ${NAG_PATH} ENV NAG_PATH ${NAG_DIR} ENV NAG_DIR PATH_SUFFIXES lib lib64 NO_DEFAULT_PATH ) set( NAG_LIBRARIES ${NAG_LIBRARY} ) set( NAG_INCLUDE_DIRS ${NAG_INCLUDE_DIR} ) include(FindPackageHandleStandardArgs) # handle the QUIETLY and REQUIRED arguments and set NAG_FOUND to TRUE # if all listed variables are TRUE find_package_handle_standard_args( NAG DEFAULT_MSG NAG_LIBRARY NAG_INCLUDE_DIR ) mark_as_advanced( NAG_INCLUDE_DIR NAG_LIBRARY ) ecbuild-3.13.1/cmake/compat/FindNetCDF3.cmake000066400000000000000000000106601513706760700205210ustar00rootroot00000000000000# (C) Copyright 2011- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation nor # does it submit to any jurisdiction. # Try to find NetCDF # # Input: # * NETCDF_PATH - user defined path where to search for the library first # (CMake or environment variable) # * NETCDF_DIR - user defined path where to search for the library first # (CMake or environment variable) # * NETCDF_CXX - search also for netcdf_c++ wrapper library # * NETCDF_Fortran - search also for netcdff wrapper library # # Output: # NETCDF_FOUND - System has NetCDF # NETCDF_INCLUDE_DIRS - The NetCDF include directories # NETCDF_LIBRARIES - The libraries needed to use NetCDF ecbuild_deprecate("The FindNetCDF3.cmake module is deprecated and will be removed from ecbuild") ### TODO: generalize this into a macro for all ecbuild if( DEFINED NETCDF_PATH ) list( APPEND _netcdf_incs ${NETCDF_PATH} ${NETCDF_PATH}/include ) list( APPEND _netcdf_libs ${NETCDF_PATH} ${NETCDF_PATH}/lib ) endif() if( DEFINED NETCDF_DIR ) list( APPEND _netcdf_incs ${NETCDF_DIR} ${NETCDF_DIR}/include ) list( APPEND _netcdf_libs ${NETCDF_DIR} ${NETCDF_DIR}/lib ) endif() # Honour environment variables NETCDF_DIR, NETCDF_PATH list( APPEND _netcdf_incs ENV NETCDF_DIR ENV NETCDF_PATH ) list( APPEND _netcdf_libs ENV NETCDF_DIR ENV NETCDF_PATH ) ### set( _inc_sfx netcdf include ) set( _lib_sfx netcdf lib64 lib ) find_path( NETCDF_INCLUDE_DIR netcdf.h PATHS ${_netcdf_incs} PATH_SUFFIXES ${_inc_sfx} NO_DEFAULT_PATH ) find_path( NETCDF_INCLUDE_DIR netcdf.h PATHS ${_netcdf_incs} PATH_SUFFIXES ${_inc_sfx} ) find_library( NETCDF_LIBRARY netcdf PATHS ${_netcdf_libs} PATH_SUFFIXES ${_lib_sfx} NO_DEFAULT_PATH ) find_library( NETCDF_LIBRARY netcdf PATHS ${_netcdf_libs} PATH_SUFFIXES ${_lib_sfx} ) set( NETCDF_LIBRARIES ${NETCDF_LIBRARY} ) set( NETCDF_INCLUDE_DIRS ${NETCDF_INCLUDE_DIR} ) mark_as_advanced(NETCDF_INCLUDE_DIR NETCDF_LIBRARY ) list( APPEND NETCDF_REQUIRED_VARS NETCDF_LIBRARY NETCDF_INCLUDE_DIR ) if( NETCDF_CXX ) find_path( NETCDF_CXX_INCLUDE_DIR netcdfcpp.h PATHS ${_netcdf_incs} PATH_SUFFIXES ${_inc_sfx} NO_DEFAULT_PATH) find_path( NETCDF_CXX_INCLUDE_DIR netcdfcpp.h PATHS ${_netcdf_incs} PATH_SUFFIXES ${_inc_sfx} ) set( _ncdf_cxx netcdf_c++ netcdf_c++ netcdf_c++4 ) find_library( NETCDF_CXX_LIBRARY NAMES ${_ncdf_cxx} PATHS ${_netcdf_libs} PATH_SUFFIXES ${_lib_sfx} NO_DEFAULT_PATH ) find_library( NETCDF_CXX_LIBRARY NAMES ${_ncdf_cxx} PATHS ${_netcdf_libs} PATH_SUFFIXES ${_lib_sfx} ) list( APPEND NETCDF_INCLUDE_DIRS ${NETCDF_CXX_INCLUDE_DIR} ) list( APPEND NETCDF_LIBRARIES ${NETCDF_CXX_LIBRARY} ) list( APPEND NETCDF_REQUIRED_VARS NETCDF_CXX_INCLUDE_DIR NETCDF_CXX_LIBRARY ) mark_as_advanced(NETCDF_CXX_INCLUDE_DIR NETCDF_CXX_LIBRARY ) endif() if( NETCDF_Fortran ) find_path( NETCDF_Fortran_INCLUDE_DIR netcdf.mod PATHS ${_netcdf_incs} PATH_SUFFIXES ${_inc_sfx} NO_DEFAULT_PATH) find_path( NETCDF_Fortran_INCLUDE_DIR netcdf.mod PATHS ${_netcdf_incs} PATH_SUFFIXES ${_inc_sfx} ) set( _ncdf_fortran netcdff ) find_library( NETCDF_Fortran_LIBRARY NAMES ${_ncdf_fortran} PATHS ${_netcdf_libs} PATH_SUFFIXES ${_lib_sfx} NO_DEFAULT_PATH ) find_library( NETCDF_Fortran_LIBRARY NAMES ${_ncdf_fortran} PATHS ${_netcdf_libs} PATH_SUFFIXES ${_lib_sfx} ) list( APPEND NETCDF_INCLUDE_DIRS ${NETCDF_Fortran_INCLUDE_DIR} ) list( APPEND NETCDF_LIBRARIES ${NETCDF_Fortran_LIBRARY} ) list( APPEND NETCDF_REQUIRED_VARS NETCDF_Fortran_INCLUDE_DIR NETCDF_Fortran_LIBRARY ) mark_as_advanced(NETCDF_Fortran_INCLUDE_DIR NETCDF_Fortran_LIBRARY ) endif() list( REMOVE_DUPLICATES NETCDF_INCLUDE_DIRS ) include(FindPackageHandleStandardArgs) if( NETCDF_FIND_QUIETLY ) set( NETCDF3_FIND_QUIETLY ${NETCDF_FIND_QUIETLY} ) endif() if( NETCDF_FIND_REQUIRED ) set( NETCDF3_FIND_REQUIRED ${NETCDF_FIND_REQUIRED} ) endif() # Handle the QUIET and REQUIRED arguments and set NETCDF3_FOUND to TRUE # if all listed variables are TRUE # Note: capitalisation of the package name must be the same as in the file name find_package_handle_standard_args( NetCDF3 DEFAULT_MSG ${NETCDF_REQUIRED_VARS} ) set( NETCDF_FOUND ${NETCDF3_FOUND} ) ecbuild-3.13.1/cmake/compat/README.rst000066400000000000000000000007201513706760700172530ustar00rootroot00000000000000============================= ecbuild 2 compatibility layer ============================= The files in this directory here emulate the behaviour of ecbuild 2.x in order to ensure smooth transition to ecbuild 3. As such, they are deprecated by definition. The compatibility layer is enabled by default. To disable it, set the ``ECBUILD_2_COMPAT`` option to ``OFF``. To output deprecation warnings instead, set the ``ECBUILD_2_COMPAT_DEPRECATE`` option to ``ON``. ecbuild-3.13.1/cmake/compat/ecbuild_add_cxx11_flags.cmake000066400000000000000000000023511513706760700232070ustar00rootroot00000000000000# (C) Copyright 2011- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation nor # does it submit to any jurisdiction. ############################################################################## #.rst: # # ecbuild_add_cxx11_flags # ======================= # # Add cxx11 flags to CXX compilation flags. :: # # ecbuild_add_cxx11_flags() # # DEPRECATED. Please set CMAKE_CXX_STANDARD or use target_compile_features # instead. # ############################################################################## macro( ecbuild_add_cxx11_flags ) if( ECBUILD_2_COMPAT_DEPRECATE ) ecbuild_deprecate("ecbuild_add_cxx11_flags is deprecated and will be " "removed in a future version. Please set CMAKE_CXX_STANDARD or use " "target_compile_features instead.") endif() if( NOT CMAKE_CXX_STANDARD OR CMAKE_CXX_STANDARD LESS 11 ) set( CMAKE_CXX_STANDARD 11 ) set( CMAKE_CXX_STANDARD_REQUIRED ON ) endif() endmacro( ecbuild_add_cxx11_flags ) ecbuild-3.13.1/cmake/compat/ecbuild_add_extra_search_paths.cmake000066400000000000000000000024661513706760700247450ustar00rootroot00000000000000# (C) Copyright 2011- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation nor # does it submit to any jurisdiction. ############################################################################### # # macro for adding search paths to CMAKE_PREFIX_PATH # for example the ECMWF /usr/local/apps paths # # usage: ecbuild_add_extra_search_paths( netcdf4 ) function( ecbuild_add_extra_search_paths pkg ) ecbuild_deprecate( " ecbuild_add_extra_search_paths modifies CMAKE_PREFIX_PATH," " which can affect future package discovery if not undone by the caller." " The current CMAKE_PREFIX_PATH is being backed up as _CMAKE_PREFIX_PATH" " so it can later be restored." ) # Back up current CMAKE_PREFIX_PATH so the caller can reset it set( _CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} PARENT_SCOPE ) string( TOUPPER ${pkg} _PKG ) ecbuild_list_extra_search_paths( ${pkg} CMAKE_PREFIX_PATH ) set( CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} PARENT_SCOPE ) # ecbuild_debug_var( CMAKE_PREFIX_PATH ) endfunction() ecbuild-3.13.1/cmake/compat/ecbuild_check_cxx11.cmake000066400000000000000000000015001513706760700223530ustar00rootroot00000000000000# (C) Copyright 2011- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation nor # does it submit to any jurisdiction. ############################################################################## #.rst: # # ecbuild_check_cxx11 # =================== # # REMOVED ############################################################################## function(ecbuild_check_cxx11) if(ECBUILD_COMPAT_DEPRECATE) ecbuild_deprecate("The ecbuild_check_cxx11 has been removed. Please use " "CMake facilities for C++11 features") endif() endfunction(ecbuild_check_cxx11) ecbuild-3.13.1/cmake/compat/ecbuild_compat.cmake000066400000000000000000000044431513706760700215460ustar00rootroot00000000000000# (C) Copyright 2019- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation nor # does it submit to any jurisdiction. #################################################################################################### # include our cmake macros, but only do so if this is the top project if(ECBUILD_2_COMPAT AND NOT ECBUILD_SYSTEM_INITIALISED ) if(ECBUILD_2_COMPAT_DEPRECATE) ecbuild_deprecate("The ecbuild 2 compatibility layer is deprecated. " "Please upgrade the build system and unset `ECBUILD_2_COMPAT`.") endif() function( __ecbuild_deprecated_watcher VAR ACCESS) if( ACCESS STREQUAL "READ_ACCESS" AND NOT DISABLE_ECBUILD_DEPRECATION_WARNINGS ) message(DEPRECATION "The Variable '${VAR}' is deprecated! Please use '${ECBUILD_${VAR}_REPLACEMENT}' instead.") endif() endfunction() function(ecbuild_mark_compat OLD_VAR NEW_VAR) if(ECBUILD_2_COMPAT_DEPRECATE) if(NOT OLD_VAR STREQUAL NEW_VAR) set(ECBUILD_${OLD_VAR}_REPLACEMENT "${NEW_VAR}" CACHE INTERNAL "${OLD_VAR} is deprecated and was replaced by ${NEW_VAR}" FORCE) variable_watch(${OLD_VAR} __ecbuild_deprecated_watcher) endif() endif() endfunction() # use macro to acces value of NEW_VAR macro(ecbuild_declare_compat OLD_VAR NEW_VAR) cmake_parse_arguments(_p "PARENT_SCOPE" "" "" ${ARGN}) if(_p_UNPARSED_ARGUMENTS) ecbuild_critical("Unknown keywords given to ecbuild_declare_compat(): \"${_p_UNPARSED_ARGUMENTS}\"") endif() if(ECBUILD_2_COMPAT_DEPRECATE) ecbuild_mark_compat(${OLD_VAR} ${NEW_VAR}) endif() if(_p_PARENT_SCOPE) set(${OLD_VAR} ${${NEW_VAR}} PARENT_SCOPE) else() set(${OLD_VAR} ${${NEW_VAR}}) endif() endmacro() include(ecbuild_compat_require) include(ecbuild_compat_setversion) include(ecbuild_compat_tplconfig) include(ecbuild_add_cxx11_flags) include(ecbuild_add_extra_search_paths) include(ecbuild_list_extra_search_paths) include(ecbuild_generate_rpc) include(ecbuild_use_package) include(ecmwf_git) include(ecbuild_check_cxx11) endif() ecbuild-3.13.1/cmake/compat/ecbuild_compat_require.cmake000066400000000000000000000144521513706760700233030ustar00rootroot00000000000000# (C) Copyright 2019- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation nor # does it submit to any jurisdiction. ############################################################################## #.rst: # # ecbuild_compat_require # ====================== # # Emulate the behaviour of the REQUIRED_PACKAGES option of ecbuild_add_option :: # # ecbuild_compat_require( # [FEATURE ] # [DESCRIPTION ]) # # Options # ------- # : required # variable to retrieve the name of the package # # : required # string describing the package to be imported # # FEATURE : optional # name of the feature / option requiring the package # # DESCRIPTION : optional # string describing the feature (used if the package has none) # # Usage # ----- # # This function is primarily for use in ecbuild_add_option. Do NOT use it in # new code. The specification should be a string containing valid # arguments to either ecbuild_use_package or find_package. # # Output variables # ---------------- # # * will be set to the required package name , # * _FOUND will be set if the package has been found, # * _HELP_MSG will contain some help if the package has not been found. # ############################################################################## macro(ecbuild_compat_require out_name pkg) set(options NO_TPL) set(single_value_args FEATURE DESCRIPTION) cmake_parse_arguments(_p "${options}" "${single_value_args}" "" ${ARGN}) if( _p_UNPARSED_ARGUMENTS ) ecbuild_critical("Unknown keywords given to ecbuild_compat_require(): \"${_p_UNPARSED_ARGUMENTS}\"") endif() string(REPLACE " " ";" pkglist ${pkg}) # string to list list(GET pkglist 0 pkgname) if(pkgname STREQUAL "PROJECT") # if 1st entry is PROJECT, then we are looking for an ecbuild project set(pkgproject 1) list(GET pkglist 1 pkgname) list(FIND pkglist DESCRIPTION __description) if( __description LESS 0 ) ecbuild_debug("ecbuild_compat_require(${pkgname}): no package description found, using provided description '${_p_DESCRIPTION}'") list(APPEND pkglist DESCRIPTION "${_p_DESCRIPTION}") endif() elseif( pkgname STREQUAL "NAME" ) list(GET pkglist 1 pkgname) else() # else 1st entry is the package name set(pkgproject 0) endif() string(TOUPPER ${pkgname} pkgUPPER) string(TOLOWER ${pkgname} pkgLOWER) # export the package name set(${out_name} ${pkgname}) set(${pkgname}_HELP_MSG "Provide ${pkgname} location with -D${pkgUPPER}_PATH=/...") if(${pkgname}_FOUND OR ${pkgUPPER}_FOUND OR ${pkgLOWER}_FOUND) ecbuild_debug("ecbuild_compat_require(${pkgname}): ${pkgname} has already been found") else() if(pkgproject) ecbuild_debug("ecbuild_compat_require(${pkgname}): calling ecbuild_use_package(${pkglist})") ecbuild_use_package(${pkglist}) else() if(pkgname STREQUAL "LAPACK") ecbuild_debug("ecbuild_compat_require(${pkgname}): searching for LAPACK - ecbuild_find_package(NAME ${pkglist})") ecbuild_find_package(NAME ${pkglist}) if(HAVE_LAPACK AND TARGET lapack) ecbuild_debug("LAPACK found as CMake target lapack") set(LAPACK_LIBRARIES lapack) endif() elseif(pkgname STREQUAL "MPI") set(_find_args ${pkglist}) list(REMOVE_ITEM _find_args "MPI") ecbuild_debug("ecbuild_compat_require(${pkgname}): searching for MPI - ecbuild_find_mpi(${_find_args})") ecbuild_find_mpi(${_find_args}) elseif(pkgname STREQUAL "OMP") set(_find_args ${pkglist}) list(REMOVE_ITEM _find_args "OMP") if(NOT ENABLE_${_p_FEATURE}) list(APPEND _find_args STUBS) endif() ecbuild_debug("ecbuild_compat_require(${pkgname}): searching for OpenMP - ecbuild_find_omp(${_find_args})") ecbuild_find_omp(${_find_args}) elseif(pkgname STREQUAL "Python" OR pkgname STREQUAL "PYTHON") set(_find_args ${pkglist}) list(REMOVE_ITEM _find_args ${pkgname}) ecbuild_debug("ecbuild_compat_require(${pkgname}): searching for Python - ecbuild_find_python(${_find_args})") ecbuild_find_python(${_find_args}) set(${pkgname}_HELP_MSG "Specify the location of the Python interpreter with -DPYTHON_EXECUTABLE=/...") elseif(pkgname STREQUAL "LEXYACC") set(_find_args ${pkglist}) list(REMOVE_ITEM _find_args ${pkgname}) ecbuild_debug("ecbuild_compat_require(${pkgname}): searching for lex-yacc - ecbuild_find_lexyacc(${_find_args})") ecbuild_find_lexyacc(${_find_args}) else() ecbuild_debug("ecbuild_compat_require(${pkgname}): searching for package ${pkgname} - find_package(${pkglist})") list(FIND pkglist "VERSION" _ver_found) if(NOT _ver_found EQUAL -1) # XXX: This is an invalid syntax used in IFS (that gets short-circuited with ecbuild 2.x # because the packages are already found) set(_pkglist_old ${pkglist}) list(REMOVE_ITEM pkglist "VERSION") string(REPLACE ";" " " _pkglist_old "${_pkglist_old}") string(REPLACE ";" " " _pkglist_new "${pkglist}") ecbuild_warn("Removing unexpected VERSION keyword from REQUIRED_PACKAGES: \ either use 'PROJECT ${_pkglist_old}' or '${_pkglist_new}'") endif() list(REMOVE_ITEM pkglist "NAME") find_package(${pkglist}) endif() endif() endif() if(${pkgname}_FOUND OR ${pkgUPPER}_FOUND OR ${pkgLOWER}_FOUND) set(${pkgname}_FOUND 1) # make sure this one is defined for consistency # append to list of third-party libraries (to be forward to other packages ) # unless the NO_TPL option was given if(NOT _p_NO_TPL) string( TOUPPER ${PROJECT_NAME} PROJECT_NAME_CAPS ) ecbuild_debug("ecbuild_compat_require(${pkgname}): appending ${pkgname} to ${PROJECT_NAME_CAPS}_TPLS") list(APPEND ${PROJECT_NAME_CAPS}_TPLS ${pkgname}) list(REMOVE_DUPLICATES ${PROJECT_NAME_CAPS}_TPLS) endif() endif() endmacro() ecbuild-3.13.1/cmake/compat/ecbuild_compat_setversion.cmake000066400000000000000000000027231513706760700240260ustar00rootroot00000000000000# (C) Copyright 2019- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation nor # does it submit to any jurisdiction. ############################################################################## #.rst: # # ecbuild_compat_setversion # ====================== # # Read a VERSION.cmake file and set the project variables. # # ecbuild_compat_setversion() # # Output variables # ---------------- # # * _VERSION_MAJOR # * _VERSION_MINOR # * _VERSION_PATCH # * _VERSION_TWEAK # * _VERSION # * _VERSION_STR # * _VERSION_SUFFIX # ############################################################################## macro(ecbuild_compat_setversion) # read and parse project version file if( EXISTS ${PROJECT_SOURCE_DIR}/VERSION.cmake ) include( ${PROJECT_SOURCE_DIR}/VERSION.cmake ) set( __version ${${PROJECT_NAME}_VERSION_STR} ) else() set( __version "0.0.0" ) endif() ecbuild_parse_version("${__version}" PREFIX ${PROJECT_NAME}) set( ${PROJECT_NAME}_VERSION "${${PROJECT_NAME}_VERSION}" CACHE INTERNAL "package ${PROJECT_NAME} version" ) set( ${PROJECT_NAME}_VERSION_STR "${${PROJECT_NAME}_VERSION}" CACHE INTERNAL "package ${PROJECT_NAME} version" ) endmacro() ecbuild-3.13.1/cmake/compat/ecbuild_compat_tplconfig.cmake000066400000000000000000000067271513706760700236220ustar00rootroot00000000000000# (C) Copyright 2019- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation nor # does it submit to any jurisdiction. ############################################################################## #.rst: # # ecbuild_compat_tplconfig # ====================== # # Generate a config file to import the third-party libraries (TPL) automatically :: # # ecbuild_compat_tplconfig( # TPLS tpl1 tpl2 ...) # # Options # ------- # : required # name of the output file # # TPLS : optional # list of third-party dependencies # # Usage # ----- # # This function is intended for use in ecbuild_install_project only. Do NOT use # it in new code. function(ecbuild_compat_tplconfig cfile) set(options) set(single_value_args) set(multi_value_args TPLS) cmake_parse_arguments( _PAR "${options}" "${single_value_args}" "${multi_value_args}" ${_FIRST_ARG} ${ARGN} ) if(_PAR_UNPARSED_ARGUMENTS) ecbuild_critical("Unknown keywords given to ecbuild_compat_tplconfig(): \"${_PAR_UNPARSED_ARGUMENTS}\"") endif() if(_PAR_TPLS) file(REMOVE ${cfile}.in) file(APPEND "${cfile}.in" "include(CMakeFindDependencyMacro)\n") foreach(_tpl ${_PAR_TPLS}) string(TOUPPER ${_tpl} TPL) if(${TPL}_IMPORT_FILE) # ecBuild packages should trigger this if they export themselves ecbuild_debug("Adding find_dependency call for TPL ${_tpl} to ${cfile}.in") get_filename_component(__import_dir "${${TPL}_IMPORT_FILE}" DIRECTORY) file(RELATIVE_PATH __import_dir_rel "${${PROJECT_NAME}_FULL_INSTALL_CMAKE_DIR}" "${__import_dir}") set(__import_dir_rel "\${CMAKE_CURRENT_LIST_DIR}/${__import_dir_rel}") file(APPEND "${cfile}.in" "if(NOT ${TPL}_IMPORT_FILE)\n") file(APPEND "${cfile}.in" " find_dependency(${_tpl} REQUIRED HINTS \"${__import_dir_rel}\" \"${__import_dir}\")\n") file(APPEND "${cfile}.in" "endif()\n") elseif(${_tpl}_CONFIG) # cmake built packages (e.g. CGAL) may have exported their targets ecbuild_debug("Adding TPL ${_tpl} import file to ${cfile}.in") set(__import_file "${${_tpl}_CONFIG}") get_filename_component(__import_dir "${__import_file}" DIRECTORY) file(APPEND "${cfile}.in" "if(NOT ${_tpl}_CONFIG)\n") file(APPEND "${cfile}.in" " find_dependency(${_tpl} REQUIRED HINTS \"${__import_dir}\")\n") file(APPEND "${cfile}.in" " set(${_tpl}_CONFIG \"${__import_file}\")\n") file(APPEND "${cfile}.in" "endif()\n") elseif(${_tpl}_FULL_INSTALL_CMAKE_DIR) # This variable is only available for a ecbuild exported TPL in a bundle. It is therefore safe to use # relative install paths between this project and the TPL ecbuild_debug("Adding find_dependency call for TPL ${_tpl} to ${cfile}.in") file(RELATIVE_PATH __import_dir "${${PROJECT_NAME}_FULL_INSTALL_CMAKE_DIR}" "${${_tpl}_FULL_INSTALL_CMAKE_DIR}") set(__import_dir "\${CMAKE_CURRENT_LIST_DIR}/${__import_dir}") file(APPEND "${cfile}.in" "find_dependency(${_tpl} REQUIRED HINTS \"${__import_dir}\")\n") endif() endforeach() configure_file("${cfile}.in" "${cfile}" @ONLY) install(FILES "${cfile}" DESTINATION "${INSTALL_CMAKE_DIR}") endif() endfunction() ecbuild-3.13.1/cmake/compat/ecbuild_generate_rpc.cmake000066400000000000000000000075201513706760700227200ustar00rootroot00000000000000# (C) Copyright 2011- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation # nor does it submit to any jurisdiction. ############################################################################## #.rst: # # ecbuild_generate_rpc # ==================== # # Process RPC (Remote Procedure Call) Language files using rpcgen. :: # # ecbuild_generate_rpc( SOURCE # [ TARGET_H ] # [ TARGET_C ] # [ DEPENDANT [ ... ] ] ) # # DEPRECATED. # # Options # ------- # # SOURCE : required # RPC source file # # TARGET_H : optional (required if TARGET_C not given) # name of header file to be generated # # TARGET_C : optional (required if TARGET_H not given) # name of source file to be generated # # DEPENDANT : optional # list of files which depend on the generated source and header files # ############################################################################## macro( ecbuild_generate_rpc ) if( ECBUILD_2_COMPAT_DEPRECATE ) ecbuild_deprecate("ecbuild_generate_rpc is deprecated and will be " "removed in a future version.") endif() set( options ) set( single_value_args SOURCE TARGET_H TARGET_C ) set( multi_value_args DEPENDANT ) cmake_parse_arguments( _PAR "${options}" "${single_value_args}" "${multi_value_args}" ${_FIRST_ARG} ${ARGN} ) if(_PAR_UNPARSED_ARGUMENTS) ecbuild_critical("Unknown keywords given to ecbuild_generate_rpc(): \"${_PAR_UNPARSED_ARGUMENTS}\"") endif() if( NOT _PAR_SOURCE ) ecbuild_critical("The call to ecbuild_generate_rpc() doesn't specify the SOURCE file.") endif() # optional # if( NOT _PAR_DEPENDANT ) # ecbuild_critical("The call to ecbuild_generate_rpc() doesn't specify the DEPENDANT files.") # endif() if( NOT DEFINED _PAR_TARGET_H AND NOT DEFINED _PAR_TARGET_C ) ecbuild_critical("The call to ecbuild_generate_rpc() doesn't specify the _PAR_TARGET_H or _PAR_TARGET_C files.") endif() if( DEFINED RPCGEN_PATH ) find_program( RPCGEN_EXECUTABLE NAMES rpcgen PATHS ${RPCGEN_PATH} PATH_SUFFIXES bin NO_DEFAULT_PATH ) endif() find_program( RPCGEN_EXECUTABLE NAMES rpcgen ) if( NOT RPCGEN_EXECUTABLE ) ecbuild_critical("Could not find rpcgen. Please provide RPCGEN_PATH.") endif() if( DEFINED _PAR_TARGET_H ) add_custom_command( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_PAR_TARGET_H} COMMAND ${CMAKE_COMMAND} -E remove ${CMAKE_CURRENT_BINARY_DIR}/${_PAR_TARGET_H} COMMAND ${RPCGEN_EXECUTABLE} -h -o ${CMAKE_CURRENT_BINARY_DIR}/${_PAR_TARGET_H} ${_PAR_SOURCE} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${_PAR_SOURCE} ) if( DEFINED _PAR_DEPENDANT ) foreach( file ${_PAR_DEPENDANT} ) set_source_files_properties( ${file} PROPERTIES OBJECT_DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/${_PAR_TARGET_H}" ) endforeach() endif() endif() if( DEFINED _PAR_TARGET_C ) add_custom_command( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_PAR_TARGET_C} COMMAND ${CMAKE_COMMAND} -E remove ${CMAKE_CURRENT_BINARY_DIR}/${_PAR_TARGET_C} COMMAND ${RPCGEN_EXECUTABLE} -c -o ${CMAKE_CURRENT_BINARY_DIR}/${_PAR_TARGET_C} ${_PAR_SOURCE} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${_PAR_SOURCE} ) if( DEFINED _PAR_DEPENDANT ) foreach( file ${_PAR_DEPENDANT} ) set_source_files_properties( ${file} PROPERTIES OBJECT_DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/${_PAR_TARGET_C}" ) endforeach() endif() endif() endmacro( ecbuild_generate_rpc ) ecbuild-3.13.1/cmake/compat/ecbuild_list_extra_search_paths.cmake000066400000000000000000000054231513706760700251640ustar00rootroot00000000000000# (C) Copyright 2011- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation nor # does it submit to any jurisdiction. ############################################################################################ # # macro for adding search paths for a package to a given CMake variable # # usage: ecbuild_list_extra_search_paths( netcdf4 VARIABLE ) function( ecbuild_list_extra_search_paths pkg var ) ecbuild_deprecate( " ecbuild_list_extra_search_paths should no longer be" " used and is going to be removed in a future version of ecBuild." ) # ecbuild_debug_var( pkg ) # ecbuild_debug_var( var ) string( TOUPPER ${pkg} _PKG ) # PKG_PATH (upper case) if( DEFINED ${_PKG}_PATH AND EXISTS ${${_PKG}_PATH} ) ecbuild_debug("ecbuild_list_extra_search_paths(${pkg}): appending ${_PKG}_PATH = ${${_PKG}_PATH} to ${var}") list( APPEND ${var} ${${_PKG}_PATH} ) endif() # ENV PKG_PATH (upper case) if( DEFINED ENV{${_PKG}_PATH} AND EXISTS $ENV{${_PKG}_PATH} ) ecbuild_debug("ecbuild_list_extra_search_paths(${pkg}): appending \$${_PKG}_PATH = $ENV{${_PKG}_PATH} to ${var}") list( APPEND ${var} $ENV{${_PKG}_PATH} ) endif() # pkg_PATH (lower case) if( DEFINED ${pkg}_PATH AND EXISTS ${${pkg}_PATH} ) ecbuild_debug("ecbuild_list_extra_search_paths(${pkg}): appending ${pkg}_PATH = ${${pkg}_PATH} to ${var}") list( APPEND ${var} ${${pkg}_PATH} ) endif() # ENV pkg_PATH (lower case) if( DEFINED ${pkg}_PATH AND EXISTS $ENV{${pkg}_PATH} ) ecbuild_debug("ecbuild_list_extra_search_paths(${pkg}): appending \$${pkg}_PATH = $ENV{${pkg}_PATH} to ${var}") list( APPEND ${var} $ENV{${pkg}_PATH} ) endif() # ENV PKG_DIR (upper case) if( DEFINED ENV{${_PKG}_DIR} AND EXISTS $ENV{${_PKG}_DIR} ) ecbuild_debug("ecbuild_list_extra_search_paths(${pkg}): appending \$${_PKG}_DIR = $ENV{${_PKG}_DIR} to ${var}") list( APPEND ${var} $ENV{${_PKG}_DIR} ) endif() # ENV pkg_DIR (lower case) if( DEFINED ENV{${pkg}_DIR} AND EXISTS $ENV{${pkg}_DIR} ) ecbuild_debug("ecbuild_list_extra_search_paths(${pkg}): appending \$${pkg}_DIR = $ENV{${pkg}_DIR} to ${var}") list( APPEND ${var} $ENV{${pkg}_DIR} ) endif() # sanitize the list if( ${var} ) list( REMOVE_DUPLICATES ${var} ) endif() # define it out of the function ecbuild_debug("ecbuild_list_extra_search_paths(${pkg}): setting ${var} to ${${var}}") set( ${var} ${${var}} PARENT_SCOPE ) # ecbuild_debug_var( ${var} ) endfunction() ecbuild-3.13.1/cmake/compat/ecbuild_use_package.cmake000066400000000000000000000320211513706760700225230ustar00rootroot00000000000000# (C) Copyright 2011- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation nor # does it submit to any jurisdiction. ############################################################################## #.rst: # # ecbuild_use_package # =================== # # Add a project from a source directory, a subdirectory or search for it. :: # # ecbuild_use_package( PROJECT # [ VERSION [ EXACT ] ] # [ COMPONENTS [ ... ] ] # [ URL ] # [ DESCRIPTION ] # [ TYPE ] # [ PURPOSE ] # [ FAILURE_MSG ] # [ REQUIRED ] # [ QUIET ] ) # # Options # ------- # # NAME : required # package name (used as ``Find.cmake`` and ``-config.cmake``) # # VERSION : optional # minimum required package version # # COMPONENTS : optional # list of package components to find (behaviour depends on the package) # # EXACT : optional, requires VERSION # require the exact version rather than a minimum version # # URL : optional # homepage of the package (shown in summary and stored in the cache) # # DESCRIPTION : optional # string describing the package (shown in summary and stored in the cache) # # TYPE : optional, one of RUNTIME|OPTIONAL|RECOMMENDED|REQUIRED # type of dependency of the project on this package (defaults to OPTIONAL) # # PURPOSE : optional # string describing which functionality this package enables in the project # # FAILURE_MSG : optional # string to be appended to the failure message if the package is not found # # REQUIRED : optional # fail if package cannot be found # # QUIET : optional # do not output package information if found # # Input variables # --------------- # # The following CMake variables influence the behaviour if set (```` # is the package name as given, ```` is the capitalised version): # # :_SOURCE: path to source directory for package # :SUBPROJECT_DIRS: list of additional paths to search for package source # # See also ``ecbuild_find_package`` for additional CMake variables relevant # when search for the package (step 6 below). # # Usage # ----- # # Use another CMake project as a dependency by either building it from source # i.e. adding its source directory as a subdirectory or searching for it. This # transparently deals with the case where the project has already been included # e.g. because multiple projects with shared dependencies are built together. # # The search proceeds as follows: # # 1. If ``SUBPROJECT_DIRS`` is set, each directory in the list is searched # for a subdirectory and ``_SOURCE`` is set to the first one # found (if any). # # 2. If ``_SOURCE`` is set, check if this directory is a CMake project # (contains ``CMakeLists.txt`` and fail if not. # # 3. Otherwise, check if the current directory has a ```` subdirectory. # # 4. If the project has not been previously marked as found or added as a # subdirectory and a project source directory has been found in steps 1-3 # add this subdirectory. # # 5. If the project has been marked as found, check the version. # # 6. Otherwise, search for the project using ``ecbuild_find_package``. # ############################################################################## macro( ecbuild_use_package ) set( options REQUIRED QUIET EXACT ) set( single_value_args PROJECT VERSION URL DESCRIPTION TYPE PURPOSE FAILURE_MSG ) set( multi_value_args COMPONENTS ) cmake_parse_arguments( _p "${options}" "${single_value_args}" "${multi_value_args}" ${_FIRST_ARG} ${ARGN} ) if(_p_UNPARSED_ARGUMENTS) ecbuild_critical("Unknown keywords given to ecbuild_use_package(): \"${_p_UNPARSED_ARGUMENTS}\"") endif() if( NOT _p_PROJECT ) ecbuild_critical("The call to ecbuild_use_package() doesn't specify the PROJECT.") endif() if( _p_EXACT AND NOT _p_VERSION ) ecbuild_critical("Call to ecbuild_use_package() requests EXACT but doesn't specify VERSION.") endif() # If the package is required, set TYPE to REQUIRED # Due to shortcomings in CMake's argument parser, passing TYPE REQUIRED has no effect if( _p_REQUIRED ) set( _p_TYPE REQUIRED ) endif() if(ECBUILD_2_COMPAT_DEPRECATE) ecbuild_deprecate("ecbuild_use_package is deprecated, please use add_subdirectory or ecbuild_find_package instead.") endif() # try to find the package as a subproject and build it string( TOUPPER ${_p_PROJECT} pkgUPPER ) # user defined dir with subprojects if(ECBUILD_2_COMPAT AND DEFINED ${pkgUPPER}_SOURCE AND NOT pkgUPPER STREQUAL _p_PROJECT ) if(ECBUILD_2_COMPAT_DEPRECATE) ecbuild_deprecate("${pkgUPPER}_SOURCE is deprecated, please use ${_p_PROJECT}_SOURCE instead") endif() set(${_p_PROJECT}_SOURCE ${${pkgUPPER}_SOURCE}) endif() if( NOT DEFINED ${_p_PROJECT}_SOURCE AND DEFINED SUBPROJECT_DIRS ) ecbuild_warn("ecbuild_use_package(): setting SUBPROJECT_DIRS is deprecated") ecbuild_debug("ecbuild_use_package(${_p_PROJECT}): scanning subproject directories ${SUBPROJECT_DIRS}") foreach( dir ${SUBPROJECT_DIRS} ) if( EXISTS ${dir}/${_p_PROJECT} AND EXISTS ${dir}/${_p_PROJECT}/CMakeLists.txt ) ecbuild_debug("ecbuild_use_package(${_p_PROJECT}): setting ${_p_PROJECT}_SOURCE to ${dir}/${_p_PROJECT}") set( ${_p_PROJECT}_SOURCE "${dir}/${_p_PROJECT}" ) endif() endforeach() endif() # user defined path to subproject if( DEFINED ${_p_PROJECT}_SOURCE ) if( NOT EXISTS ${${_p_PROJECT}_SOURCE} OR NOT EXISTS ${${_p_PROJECT}_SOURCE}/CMakeLists.txt ) ecbuild_critical("User defined source directory '${${_p_PROJECT}_SOURCE}' for project '${_p_PROJECT}' does not exist or does not contain a CMakeLists.txt file.") endif() set( ${_p_PROJECT}_subproj_dir_ "${${_p_PROJECT}_SOURCE}" ) else() # default is 'dropped in' subdirectory named as project if( EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${_p_PROJECT} AND EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${_p_PROJECT}/CMakeLists.txt ) ecbuild_debug("ecbuild_use_package(${_p_PROJECT}): found ${_p_PROJECT} in subdirectory ${CMAKE_CURRENT_SOURCE_DIR}/${_p_PROJECT}") set( ${_p_PROJECT}_subproj_dir_ "${CMAKE_CURRENT_SOURCE_DIR}/${_p_PROJECT}" ) endif() endif() # check if was already added as subproject ... set( _do_compat_check 0 ) set( _source_description "" ) list( FIND ECBUILD_PROJECTS ${_p_PROJECT} _ecbuild_project_${_p_PROJECT} ) if( NOT _ecbuild_project_${_p_PROJECT} EQUAL "-1" ) ecbuild_debug("ecbuild_use_package(${_p_PROJECT}): ${_p_PROJECT} was previously added as a subproject") else() ecbuild_debug("ecbuild_use_package(${_p_PROJECT}): ${_p_PROJECT} was not previously added as a subproject") endif() if( ECBUILD_2_COMPAT ) # Disable deprecation warnings until ecbuild_mark_compat, because "_FOUND" may already have been # marked with "ecbuild_mark_compat()" in a bundle. set( DISABLE_ECBUILD_DEPRECATION_WARNINGS_orig ${DISABLE_ECBUILD_DEPRECATION_WARNINGS} ) set( DISABLE_ECBUILD_DEPRECATION_WARNINGS ON ) endif() # solve capitalization issues if( ${_p_PROJECT}_FOUND AND NOT ${pkgUPPER}_FOUND ) set( ${pkgUPPER}_FOUND 1 ) endif() if( ${pkgUPPER}_FOUND AND NOT ${_p_PROJECT}_FOUND ) set( ${_p_PROJECT}_FOUND 1 ) endif() if( ECBUILD_2_COMPAT ) ecbuild_mark_compat(${pkgUPPER}_FOUND ${_p_PROJECT}_FOUND) endif() if( ECBUILD_2_COMPAT ) set( DISABLE_ECBUILD_DEPRECATION_WARNINGS ${DISABLE_ECBUILD_DEPRECATION_WARNINGS_orig} ) endif() # Case 1) project exists as subproject if( DEFINED ${_p_PROJECT}_subproj_dir_ ) # check version and components are acceptable set( _do_compat_check 1 ) # Case 1a) project was already found if( ${_p_PROJECT}_FOUND ) ecbuild_debug("ecbuild_use_package(${_p_PROJECT}): 1a) project was already added as subproject, check version is acceptable") set( _source_description "already existing sub-project ${_p_PROJECT} (sources)" ) # Case 1b) project was not already found else() ecbuild_debug("ecbuild_use_package(${_p_PROJECT}): 1b) project is NOT already FOUND and exists as subproject") set( _source_description "sub-project ${_p_PROJECT} (sources)" ) # add as a subproject set( ECBUILD_PROJECTS ${ECBUILD_PROJECTS} ${_p_PROJECT} CACHE INTERNAL "" ) ecbuild_debug("ecbuild_use_package(${_p_PROJECT}): ${_p_PROJECT} found in subdirectory ${${_p_PROJECT}_subproj_dir_}") add_subdirectory( ${${_p_PROJECT}_subproj_dir_} ${_p_PROJECT} ) endif() endif() # Case 2) project does NOT exist as subproject, but is FOUND # it was previously found as a binary ( either build or install tree ) if( ${_p_PROJECT}_FOUND AND NOT ${_p_PROJECT}_subproj_dir_ ) ecbuild_debug("ecbuild_use_package(${_p_PROJECT}): 2) project does NOT exist as subproject, but is FOUND") # check version and components are acceptable set( _do_compat_check 1 ) set( _source_description "previously found package ${_p_PROJECT} (binaries)" ) endif() # test version for Cases 1,2,3 # ecbuild_debug_var( _p_PROJECT ) # ecbuild_debug_var( _p_VERSION ) # ecbuild_debug_var( ${_p_PROJECT}_VERSION ) # ecbuild_debug_var( ${_p_PROJECT}_VERSION ) # ecbuild_debug_var( _do_compat_check ) # ecbuild_debug_var( _source_description ) # ecbuild_debug_var( ${_p_PROJECT}_FOUND ) # ecbuild_debug_var( ${_p_PROJECT}_previous_subproj_ ) if( _p_VERSION AND _do_compat_check ) if( _p_EXACT ) if( NOT ${_p_PROJECT}_VERSION VERSION_EQUAL _p_VERSION ) ecbuild_critical( "${PROJECT_NAME} requires (exactly) ${_p_PROJECT} = ${_p_VERSION} -- detected as ${_source_description} ${${_p_PROJECT}_VERSION}" ) endif() else() if( _p_VERSION VERSION_LESS ${_p_PROJECT}_VERSION OR _p_VERSION VERSION_EQUAL ${_p_PROJECT}_VERSION ) ecbuild_info( "${PROJECT_NAME} requires ${_p_PROJECT} >= ${_p_VERSION} -- detected as ${_source_description} ${${_p_PROJECT}_VERSION}" ) else() ecbuild_critical( "${PROJECT_NAME} requires ${_p_PROJECT} >= ${_p_VERSION} -- detected only ${_source_description} ${${_p_PROJECT}_VERSION}" ) endif() endif() endif() if( _p_COMPONENTS AND _do_compat_check ) foreach( comp ${_p_COMPONENTS} ) if( NOT ${_p_PROJECT}_${comp}_FOUND ) ecbuild_critical( "${PROJECT_NAME} requires component ${comp} of ${_p_PROJECT} -- not found" ) endif() endforeach() endif() # Case 3) is NOT FOUND so far, NOT as sub-project (now or before), and NOT as binary neither # so try to find precompiled binaries or a build tree if( ${_p_PROJECT}_FOUND ) # Only set package properties if ecbuild_find_package, which itself calls # set_package_properties, is not subsequently called since doing so would # duplicate the purpose set_package_properties( ${_p_PROJECT} PROPERTIES URL "${_p_URL}" DESCRIPTION "${_p_DESCRIPTION}" TYPE "${_p_TYPE}" PURPOSE "${_p_PURPOSE}" ) else() ecbuild_debug("ecbuild_use_package(${_p_PROJECT}): 3) project does NOT exist as subproject and is NOT already FOUND") set( _opts ) if( _p_VERSION ) list( APPEND _opts VERSION ${_p_VERSION} ) endif() if( _p_COMPONENTS ) list( APPEND _opts COMPONENTS ${_p_COMPONENTS} ) endif() if( _p_EXACT ) list( APPEND _opts EXACT ) endif() if( _p_REQUIRED ) list( APPEND _opts REQUIRED ) endif() if( _p_URL ) list( APPEND _opts URL ${_p_URL} ) endif() if( _p_DESCRIPTION ) list( APPEND _opts DESCRIPTION "${_p_DESCRIPTION}" ) endif() if( _p_TYPE ) list( APPEND _opts TYPE ${_p_TYPE} ) endif() if( _p_PURPOSE ) list( APPEND _opts PURPOSE "${_p_PURPOSE}" ) endif() if( _p_FAILURE_MSG ) ecbuild_debug_var( _p_FAILURE_MSG ) list( APPEND _opts FAILURE_MSG "${_p_FAILURE_MSG}" ) endif() if (_p_QUIET) list( APPEND _opts QUIET) endif() ecbuild_find_package( NAME ${_p_PROJECT} ${_opts} ) if( ${_p_PROJECT}_FOUND ) set( ${pkgUPPER}_FOUND ${${_p_PROJECT}_FOUND} ) endif() endif() if( ECBUILD_2_COMPAT AND ${_p_PROJECT}_FOUND ) ecbuild_declare_compat(${pkgUPPER}_FOUND ${_p_PROJECT}_FOUND) string( TOUPPER ${PROJECT_NAME} PROJECT_NAME_CAPS ) list( APPEND ${PROJECT_NAME_CAPS}_TPLS ${_p_PROJECT} ) list( REMOVE_DUPLICATES ${PROJECT_NAME_CAPS}_TPLS ) endif() ### for when we change this macro to a function() # set_parent_scope( ${_p_PROJECT}_FOUND ) # set_parent_scope( ${_p_PROJECT}_FOUND ) # set_parent_scope( ${_p_PROJECT}_VERSION ) # set_parent_scope( ${_p_PROJECT}_VERSION ) # set_parent_scope( ${_p_PROJECT}_BINARY_DIR ) endmacro() ecbuild-3.13.1/cmake/compat/ecmwf_git.cmake000066400000000000000000000040071513706760700205340ustar00rootroot00000000000000 set( ECMWF_USER $ENV{USER} CACHE STRING "ECMWF git user" ) set( ECMWF_GIT SSH CACHE STRING "ECMWF git protocol" ) set( ECMWF_GIT_SSH "ssh://git@git.ecmwf.int" CACHE INTERNAL "ECMWF ssh address" ) set( ECMWF_GIT_HTTPS "https://${ECMWF_USER}@git.ecmwf.int/scm" CACHE INTERNAL "ECMWF https address" ) if( ECMWF_GIT MATCHES "[Ss][Ss][Hh]" ) set( ECMWF_GIT_ADDRESS ${ECMWF_GIT_SSH} CACHE INTERNAL "" ) else() set( ECMWF_GIT_ADDRESS ${ECMWF_GIT_HTTPS} CACHE INTERNAL "" ) endif() ############################################################################## #.rst: # # ecmwf_stash # ============= # # Manages an external Git repository on ECMWF Stash. :: # # ecmwf_stash( PROJECT # DIR # STASH # [ BRANCH | TAG ] # [ UPDATE | NOREMOTE ] ) # [ MANUAL ] ) # # Options # ------- # # PROJECT : required # project name for the Git repository to be managed # # DIR : required # directory to clone the repository into (can be relative) # # STASH : required # Stash repository in the form / # # BRANCH : optional, cannot be combined with TAG # Git branch to check out # # TAG : optional, cannot be combined with BRANCH # Git tag or commit id to check out # # UPDATE : optional, requires BRANCH, cannot be combined with NOREMOTE # Create a CMake target update to fetch changes from the remote repository # # NOREMOTE : optional, cannot be combined with UPDATE # Do not fetch changes from the remote repository # # MANUAL : optional # Do not automatically switch branches or tags # ############################################################################## macro( ecmwf_stash ) set( options ) set( single_value_args STASH ) set( multi_value_args ) cmake_parse_arguments( _PAR "${options}" "${single_value_args}" "${multi_value_args}" ${_FIRST_ARG} ${ARGN} ) ecbuild_git( URL "${ECMWF_GIT_ADDRESS}/${_PAR_STASH}.git" ${_PAR_UNPARSED_ARGUMENTS} ) endmacro() ecbuild-3.13.1/cmake/compat/netcdf_compat.cmake000066400000000000000000000062651513706760700214060ustar00rootroot00000000000000# (C) Copyright 2020- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation nor # does it submit to any jurisdiction. # Extra exports for FindNetCDF.cmake for backwards compatibility # # This module defines # # - NetCDF_INCLUDE_DIRS - the NetCDF include directories # - NetCDF_LIBRARIES - the libraries needed to use NetCDF # # For each component the following are defined: # # - NetCDF__LIBRARIES - the libraries for the component # - NetCDF__INCLUDE_DIRS - the include directories for specfied component # # Notes: # # - Capitalisation of COMPONENT arguments does not matter: The part of variables will be defined with # * capitalisation as defined above # * Uppercase capitalisation # * capitalisation as used in find_package() arguments # - Each variable is also available in fully uppercased version # - In each variable (not in targets), the "NetCDF" prefix may be interchanged with # * NetCDF4 # * NETCDF # * NETCDF4 # * The part "" in current filename Find.cmake set(__args) foreach( _comp ${_search_components} ) string( TOUPPER "${_comp}" _COMP ) list(APPEND __args ${_arg_${_COMP}} ) endforeach() foreach( _comp ${_search_components} ) if( NetCDF_${_comp}_FOUND ) list( APPEND NetCDF_INCLUDE_DIRS ${NetCDF_${_comp}_INCLUDE_DIR} ) list( APPEND NetCDF_${_comp}_INCLUDE_DIRS ${NetCDF_${_comp}_INCLUDE_DIR} ) list( APPEND NetCDF_${_comp}_LIBRARIES ${NetCDF_${_comp}_LIBRARY} ) if( DEFINED NetCDF_${_comp}_EXTRA_LIBRARIES ) list( APPEND NetCDF_${_comp}_LIBRARIES ${NetCDF_${_comp}_EXTRA_LIBRARIES}) endif() list( APPEND NetCDF_LIBRARIES ${NetCDF_${_comp}_LIBRARIES} ) endif() endforeach() if( NetCDF_INCLUDE_DIRS ) list( REMOVE_DUPLICATES NetCDF_INCLUDE_DIRS ) endif() foreach( _prefix NetCDF NetCDF4 NETCDF NETCDF4 ${CMAKE_FIND_PACKAGE_NAME} ) set( ${_prefix}_INCLUDE_DIRS ${NetCDF_INCLUDE_DIRS} ) set( ${_prefix}_LIBRARIES ${NetCDF_LIBRARIES}) set( ${_prefix}_VERSION ${NetCDF_VERSION} ) set( ${_prefix}_FOUND ${${CMAKE_FIND_PACKAGE_NAME}_FOUND} ) foreach( _comp ${_search_components} ) string( TOUPPER "${_comp}" _COMP ) set( _arg_comp ${_arg_${_COMP}} ) set( ${_prefix}_${_comp}_FOUND ${${CMAKE_FIND_PACKAGE_NAME}_${_arg_comp}_FOUND} ) set( ${_prefix}_${_COMP}_FOUND ${${CMAKE_FIND_PACKAGE_NAME}_${_arg_comp}_FOUND} ) set( ${_prefix}_${_arg_comp}_FOUND ${${CMAKE_FIND_PACKAGE_NAME}_${_arg_comp}_FOUND} ) set( ${_prefix}_${_comp}_LIBRARIES ${NetCDF_${_comp}_LIBRARIES} ) set( ${_prefix}_${_COMP}_LIBRARIES ${NetCDF_${_comp}_LIBRARIES} ) set( ${_prefix}_${_arg_comp}_LIBRARIES ${NetCDF_${_comp}_LIBRARIES} ) set( ${_prefix}_${_comp}_INCLUDE_DIRS ${NetCDF_INCLUDE_DIRS} ) set( ${_prefix}_${_COMP}_INCLUDE_DIRS ${NetCDF_INCLUDE_DIRS} ) set( ${_prefix}_${_arg_comp}_INCLUDE_DIRS ${NetCDF_INCLUDE_DIRS} ) endforeach() endforeach() ecbuild-3.13.1/cmake/compiler_flags/000077500000000000000000000000001513706760700172705ustar00rootroot00000000000000ecbuild-3.13.1/cmake/compiler_flags/Clang_C.cmake000066400000000000000000000017231513706760700215630ustar00rootroot00000000000000# (C) Copyright 2011- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation # nor does it submit to any jurisdiction. set( CMAKE_C_FLAGS_RELEASE "-O3 -DNDEBUG" CACHE STRING "C compiler flags for Release builds" FORCE ) set( CMAKE_C_FLAGS_BIT "-O2 -DNDEBUG" CACHE STRING "C compiler flags for Bit-reproducible builds" FORCE ) set( CMAKE_C_FLAGS_DEBUG "-O0 -g" CACHE STRING "C compiler flags for Debug builds" FORCE ) set( CMAKE_C_FLAGS_PRODUCTION "-O3 -g" CACHE STRING "C compiler flags for Production builds." FORCE ) set( CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -g -DNDEBUG" CACHE STRING "C compiler flags for RelWithDebInfo builds." FORCE ) ecbuild-3.13.1/cmake/compiler_flags/Clang_CXX.cmake000066400000000000000000000017471513706760700220510ustar00rootroot00000000000000# (C) Copyright 2011- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation # nor does it submit to any jurisdiction. set( CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG" CACHE STRING "C++ compiler flags for Release builds" FORCE ) set( CMAKE_CXX_FLAGS_BIT "-O2 -DNDEBUG" CACHE STRING "C++ compiler flags for Bit-reproducible builds" FORCE ) set( CMAKE_CXX_FLAGS_DEBUG "-O0 -g" CACHE STRING "C++ compiler flags for Debug builds" FORCE ) set( CMAKE_CXX_FLAGS_PRODUCTION "-O3 -g" CACHE STRING "C++ compiler flags for Production builds." FORCE ) set( CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g -DNDEBUG" CACHE STRING "C++ compiler flags for RelWithDebInfo builds." FORCE ) ecbuild-3.13.1/cmake/compiler_flags/CrayClang_C.cmake000066400000000000000000000017231513706760700224020ustar00rootroot00000000000000# (C) Copyright 2011- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation # nor does it submit to any jurisdiction. set( CMAKE_C_FLAGS_RELEASE "-O3 -DNDEBUG" CACHE STRING "C compiler flags for Release builds" FORCE ) set( CMAKE_C_FLAGS_BIT "-O2 -DNDEBUG" CACHE STRING "C compiler flags for Bit-reproducible builds" FORCE ) set( CMAKE_C_FLAGS_DEBUG "-O0 -g" CACHE STRING "C compiler flags for Debug builds" FORCE ) set( CMAKE_C_FLAGS_PRODUCTION "-O3 -g" CACHE STRING "C compiler flags for Production builds." FORCE ) set( CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -g -DNDEBUG" CACHE STRING "C compiler flags for RelWithDebInfo builds." FORCE ) ecbuild-3.13.1/cmake/compiler_flags/CrayClang_CXX.cmake000066400000000000000000000017471513706760700226700ustar00rootroot00000000000000# (C) Copyright 2011- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation # nor does it submit to any jurisdiction. set( CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG" CACHE STRING "C++ compiler flags for Release builds" FORCE ) set( CMAKE_CXX_FLAGS_BIT "-O2 -DNDEBUG" CACHE STRING "C++ compiler flags for Bit-reproducible builds" FORCE ) set( CMAKE_CXX_FLAGS_DEBUG "-O0 -g" CACHE STRING "C++ compiler flags for Debug builds" FORCE ) set( CMAKE_CXX_FLAGS_PRODUCTION "-O3 -g" CACHE STRING "C++ compiler flags for Production builds." FORCE ) set( CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g -DNDEBUG" CACHE STRING "C++ compiler flags for RelWithDebInfo builds." FORCE ) ecbuild-3.13.1/cmake/compiler_flags/Cray_C.cmake000066400000000000000000000020551513706760700214340ustar00rootroot00000000000000# (C) Copyright 2011- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation # nor does it submit to any jurisdiction. set( CMAKE_C_FLAGS_RELEASE "-O3 -hfp3 -hscalar3 -hvector3 -DNDEBUG" CACHE STRING "Release C flags" FORCE ) set( CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -hfp1 -G2 -DNDEBUG" CACHE STRING "Release-with-debug-info C flags" FORCE ) set( CMAKE_C_FLAGS_PRODUCTION "-O2 -hfp1 -G2" CACHE STRING "Production C flags" FORCE ) set( CMAKE_C_FLAGS_BIT "-O2 -hfp1 -G2 -hflex_mp=conservative -DNDEBUG" CACHE STRING "Bit-reproducible C flags" FORCE ) set( CMAKE_C_FLAGS_DEBUG "-O0 -G0" CACHE STRING "Debug Cflags" FORCE ) ecbuild-3.13.1/cmake/compiler_flags/Cray_CXX.cmake000066400000000000000000000020501513706760700217070ustar00rootroot00000000000000# (C) Copyright 2011- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation # nor does it submit to any jurisdiction. set( CMAKE_CXX_FLAGS_RELEASE "-O3 -hfp3 -hscalar3 -hvector3 -DNDEBUG" CACHE STRING "Release C++ flags" FORCE ) set( CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -hfp1 -G2 -DNDEBUG" CACHE STRING "Release-with-debug-info C++ flags" FORCE ) set( CMAKE_CXX_FLAGS_PRODUCTION "-O2 -hfp1" CACHE STRING "Production C++ flags" FORCE ) set( CMAKE_CXX_FLAGS_BIT "-O2 -hfp1 -hflex_mp=conservative -DNDEBUG" CACHE STRING "Bit-reproducible C++ flags" FORCE ) set( CMAKE_CXX_FLAGS_DEBUG "-G0 -O0" CACHE STRING "Debug CXX flags" FORCE ) ecbuild-3.13.1/cmake/compiler_flags/Cray_Fortran.cmake000066400000000000000000000025201513706760700226620ustar00rootroot00000000000000# (C) Copyright 2011- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation # nor does it submit to any jurisdiction. # -emf activates .mods and uses lower case # -rmoid produces a listing file set( CMAKE_Fortran_FLAGS_RELEASE "-emf -rmoid -N 1023 -O3 -hfp3 -hscalar3 -hvector3 -DNDEBUG" CACHE STRING "Release Fortran flags" FORCE ) set( CMAKE_Fortran_FLAGS_RELWITHDEBINFO "-emf -rmoid -N 1023 -O2 -hfp1 -g -DNDEBUG" CACHE STRING "Release-with-debug-info Fortran flags" FORCE ) set( CMAKE_Fortran_FLAGS_PRODUCTION "-emf -rmoid -N 1023 -O2 -hfp1 -g" CACHE STRING "Production Fortran flags" FORCE ) set( CMAKE_Fortran_FLAGS_BIT "-emf -rmoid -N 1023 -O2 -hfp1 -g -hflex_mp=conservative -hadd_paren -DNDEBUG" CACHE STRING "Bit-reproducible Fortran flags" FORCE ) set( CMAKE_Fortran_FLAGS_DEBUG "-emf -rmoid -N 1023 -O0 -g" CACHE STRING "Debug Fortran flags" FORCE ) ecbuild-3.13.1/cmake/compiler_flags/GNU_C.cmake000066400000000000000000000024241513706760700211670ustar00rootroot00000000000000# (C) Copyright 2011- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation # nor does it submit to any jurisdiction. set( CMAKE_C_FLAGS_RELEASE "-O3 -DNDEBUG" CACHE STRING "C compiler flags for Release builds" FORCE ) set( CMAKE_C_FLAGS_BIT "-O2 -DNDEBUG" CACHE STRING "C compiler flags for Bit-reproducible builds" FORCE ) set( CMAKE_C_FLAGS_DEBUG "-O0 -g" CACHE STRING "C compiler flags for Debug builds" FORCE ) set( CMAKE_C_FLAGS_PRODUCTION "-O2 -g" CACHE STRING "C compiler flags for Production builds." FORCE ) set( CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -g -DNDEBUG" CACHE STRING "C compiler flags for RelWithDebInfo builds." FORCE ) # NOTE: gcc does not guarrante that -O3 performs better than -O2 # -- it can perform worse due to assembly code bloating. # Moreover for gcc 4.1.2 we found that -O3 remove the parser code generated from Lex/Yacc # and therefore in production mode we downgrade to -O2 if the compiler is GCC (for all versions). ecbuild-3.13.1/cmake/compiler_flags/GNU_CXX.cmake000066400000000000000000000024501513706760700214460ustar00rootroot00000000000000# (C) Copyright 2011- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation # nor does it submit to any jurisdiction. set( CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG" CACHE STRING "C++ compiler flags for Release builds" FORCE ) set( CMAKE_CXX_FLAGS_BIT "-O2 -DNDEBUG" CACHE STRING "C++ compiler flags for Bit-reproducible builds" FORCE ) set( CMAKE_CXX_FLAGS_DEBUG "-O0 -g" CACHE STRING "C++ compiler flags for Debug builds" FORCE ) set( CMAKE_CXX_FLAGS_PRODUCTION "-O2 -g" CACHE STRING "C++ compiler flags for Production builds." FORCE ) set( CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g -DNDEBUG" CACHE STRING "C++ compiler flags for RelWithDebInfo builds." FORCE ) # NOTE: gcc does not guarrante that -O3 performs better than -O2 # -- it can perform worse due to assembly code bloating. # Moreover for gcc 4.1.2 we found that -O3 remove the parser code generated from Lex/Yacc # and therefore in production mode we downgrade to -O2 if the compiler is GCC (for all versions). ecbuild-3.13.1/cmake/compiler_flags/GNU_Fortran.cmake000066400000000000000000000030061513706760700224150ustar00rootroot00000000000000# (C) Copyright 2011- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation # nor does it submit to any jurisdiction. set( CMAKE_Fortran_FLAGS_RELEASE "-O3 -DNDEBUG -funroll-all-loops -finline-functions" CACHE STRING "Fortran compiler flags for Release builds" FORCE ) set( CMAKE_Fortran_FLAGS_BIT "-O2 -DNDEBUG -fno-range-check" CACHE STRING "Fortran compiler flags for Bit-reproducible builds" FORCE ) set( CMAKE_Fortran_FLAGS_DEBUG "-O0 -g -fcheck=bounds -fbacktrace -finit-real=snan" CACHE STRING "Fortran compiler flags for Debug builds" FORCE ) set( CMAKE_Fortran_FLAGS_PRODUCTION "-O2 -g" CACHE STRING "Fortran compiler flags for Production builds." FORCE ) set( CMAKE_Fortran_FLAGS_RELWITHDEBINFO "-O2 -g -DNDEBUG" CACHE STRING "Fortran compiler flags for RelWithDebInfo builds." FORCE ) set( Fortran_FLAG_STACK_ARRAYS "-fstack-arrays" ) #################################################################### # Meaning of flags # ---------------- # -fstack-arrays : Allocate automatic arrays on the stack (needs large stacksize!!!) # -funroll-all-loops : Unroll all loops # -fcheck=bounds : Bounds checking ecbuild-3.13.1/cmake/compiler_flags/Intel_C.cmake000066400000000000000000000017161513706760700216140ustar00rootroot00000000000000# (C) Copyright 2011- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation # nor does it submit to any jurisdiction. set( CMAKE_C_FLAGS_RELEASE "-O3 -DNDEBUG" CACHE STRING "Release C compiler flags" FORCE ) set( CMAKE_C_FLAGS_BIT "-O2 -DNDEBUG" CACHE STRING "Bit-reproducible C compiler flags" FORCE ) set( CMAKE_C_FLAGS_DEBUG "-O0 -g -traceback" CACHE STRING "Debug C compiler flags" FORCE ) set( CMAKE_C_FLAGS_PRODUCTION "-O3 -g" CACHE STRING "Production C compiler flags" FORCE ) set( CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -g -DNDEBUG" CACHE STRING "Release-with-debug-info C compiler flags" FORCE ) ecbuild-3.13.1/cmake/compiler_flags/Intel_CXX.cmake000066400000000000000000000017351513706760700220750ustar00rootroot00000000000000# (C) Copyright 2011- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation # nor does it submit to any jurisdiction. set( CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG" CACHE STRING "Release C++ compiler flags" FORCE ) set( CMAKE_CXX_FLAGS_BIT "-O2 -DNDEBUG" CACHE STRING "Bit-reproducible C++ compiler flags" FORCE ) set( CMAKE_CXX_FLAGS_DEBUG "-O0 -g -traceback" CACHE STRING "Debug C++ compiler flags" FORCE ) set( CMAKE_CXX_FLAGS_PRODUCTION "-O3 -g" CACHE STRING "Production C++ compiler flags" FORCE ) set( CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g -DNDEBUG" CACHE STRING "Release-with-debug-info C++ compiler flags" FORCE ) ecbuild-3.13.1/cmake/compiler_flags/Intel_Fortran.cmake000066400000000000000000000027751513706760700230530ustar00rootroot00000000000000# (C) Copyright 2011- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation # nor does it submit to any jurisdiction. set( Fortran_AUTOMATIC_ARRAYS_LIMIT 32768 ) # (32 kb) math( EXPR Fortran_AUTOMATIC_ARRAYS_LIMIT_KB "${Fortran_AUTOMATIC_ARRAYS_LIMIT}/1024" ) set( Fortran_FLAG_STACK_ARRAYS "-no-heap-arrays" ) set( Fortran_FLAG_AUTOMATIC_ARRAYS "-heap-arrays ${Fortran_AUTOMATIC_ARRAYS_LIMIT_KB}" ) set( CMAKE_Fortran_FLAGS_RELEASE "-O3 -DNDEBUG -unroll -inline ${Fortran_FLAG_AUTOMATIC_ARRAYS}" CACHE STRING "Release Fortran flags" FORCE ) set( CMAKE_Fortran_FLAGS_RELWITHDEBINFO "-O2 -g -DNDEBUG ${Fortran_FLAG_AUTOMATIC_ARRAYS}" CACHE STRING "Release-with-debug-info Fortran flags" FORCE ) set( CMAKE_Fortran_FLAGS_BIT "-O2 -DNDEBUG -unroll -inline ${Fortran_FLAG_AUTOMATIC_ARRAYS}" CACHE STRING "Bit-reproducible Fortran flags" FORCE ) set( CMAKE_Fortran_FLAGS_DEBUG "-O0 -g -traceback ${Fortran_FLAG_AUTOMATIC_ARRAYS} -check all" CACHE STRING "Debug Fortran flags" FORCE ) set( CMAKE_Fortran_FLAGS_PRODUCTION "-O3 -g ${Fortran_FLAG_AUTOMATIC_ARRAYS}" CACHE STRING "Production Fortran compiler flags" FORCE ) # "-check all" implies "-check bounds" ecbuild-3.13.1/cmake/compiler_flags/PGI_C.cmake000066400000000000000000000010111513706760700211440ustar00rootroot00000000000000# (C) Copyright 2011- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation nor # does it submit to any jurisdiction. set( CMAKE_C_FLAGS_RELEASE "-fast -O3 -DNDEBUG" CACHE STRING "Release C compiler flags" FORCE ) set( CMAKE_C_LINK_FLAGS "" CACHE STRING "" ) ecbuild-3.13.1/cmake/compiler_flags/PGI_CXX.cmake000066400000000000000000000010171513706760700214320ustar00rootroot00000000000000# (C) Copyright 2011- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation nor # does it submit to any jurisdiction. set( CMAKE_CXX_FLAGS_RELEASE "-fast -O3 -DNDEBUG" CACHE STRING "Release C++ compiler flags" FORCE ) set( CMAKE_CXX_LINK_FLAGS "" CACHE STRING "" ) ecbuild-3.13.1/cmake/compiler_flags/PGI_Fortran.cmake000066400000000000000000000010221513706760700223770ustar00rootroot00000000000000# (C) Copyright 2011- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation nor # does it submit to any jurisdiction. set( CMAKE_Fortran_FLAGS_RELEASE "-fast -O3" CACHE STRING "Release Fortran compiler flags" FORCE ) set( CMAKE_Fortran_LINK_FLAGS "" CACHE STRING "" ) ecbuild-3.13.1/cmake/contrib/000077500000000000000000000000001513706760700157425ustar00rootroot00000000000000ecbuild-3.13.1/cmake/contrib/FindEigen3.cmake000066400000000000000000000073121513706760700206620ustar00rootroot00000000000000# - Try to find Eigen3 lib # # This module supports requiring a minimum version, e.g. you can do # find_package(Eigen3 3.1.2) # to require version 3.1.2 or newer of Eigen3. # # Once done this will define # # EIGEN3_FOUND - system has eigen lib with correct version # EIGEN3_INCLUDE_DIRS - the eigen include directory # EIGEN3_VERSION - eigen version # # First a find_package( Eigen3 NO_MODULE ) is invoked which will also define target Eigen3::Eigen # If this is not found, a fallback mechanism is used which searches for include dirs and defines # above variables without the target. # To force definition of the target, set the variable `Eigen3_NO_MODULE` ON. # To skip the find_package( Eigen3 NO_MODULE ), set the variable `Eigen3_NO_MODULE` OFF # # Copyright (c) 2006, 2007 Montel Laurent, # Copyright (c) 2008, 2009 Gael Guennebaud, # Copyright (c) 2009 Benoit Jacob # Copyright (c) 2013- ECMWF # Redistribution and use is allowed according to the terms of the 2-clause BSD license. macro(_eigen3_check_version) file(READ "${EIGEN3_INCLUDE_DIR}/Eigen/src/Core/util/Macros.h" _eigen3_version_header) string(REGEX MATCH "define[ \t]+EIGEN_WORLD_VERSION[ \t]+([0-9]+)" _eigen3_world_version_match "${_eigen3_version_header}") set(EIGEN3_WORLD_VERSION "${CMAKE_MATCH_1}") string(REGEX MATCH "define[ \t]+EIGEN_MAJOR_VERSION[ \t]+([0-9]+)" _eigen3_major_version_match "${_eigen3_version_header}") set(EIGEN3_MAJOR_VERSION "${CMAKE_MATCH_1}") string(REGEX MATCH "define[ \t]+EIGEN_MINOR_VERSION[ \t]+([0-9]+)" _eigen3_minor_version_match "${_eigen3_version_header}") set(EIGEN3_MINOR_VERSION "${CMAKE_MATCH_1}") set(EIGEN3_VERSION ${EIGEN3_WORLD_VERSION}.${EIGEN3_MAJOR_VERSION}.${EIGEN3_MINOR_VERSION}) if( Eigen3_FIND_VERSION ) if(${EIGEN3_VERSION} VERSION_LESS ${Eigen3_FIND_VERSION}) set(EIGEN3_VERSION_OK FALSE) else(${EIGEN3_VERSION} VERSION_LESS ${Eigen3_FIND_VERSION}) set(EIGEN3_VERSION_OK TRUE) endif(${EIGEN3_VERSION} VERSION_LESS ${Eigen3_FIND_VERSION}) else() set( EIGEN3_VERSION_OK TRUE ) endif() if(NOT EIGEN3_VERSION_OK) message(STATUS "Eigen3 version ${EIGEN3_VERSION} found in ${EIGEN3_INCLUDE_DIR}, " "but at least version ${Eigen3_FIND_VERSION} is required") else() set( EIGEN3_VERSION ${EIGEN3_VERSION} CACHE INTERNAL "Eigen3 version" ) endif() endmacro(_eigen3_check_version) if( NOT DEFINED Eigen3_NO_MODULE OR Eigen3_NO_MODULE ) find_package( Eigen3 NO_MODULE ) set( EIGEN3_VERSION ${Eigen3_VERSION} ) set( EIGEN3_FOUND ${Eigen3_FOUND} ) if( Eigen3_FOUND OR Eigen3_NO_MODULE ) include( FindPackageHandleStandardArgs ) find_package_handle_standard_args( Eigen3 CONFIG_MODE ) return() endif() endif() if(EIGEN3_INCLUDE_DIR) # in cache already _eigen3_check_version() set(EIGEN3_FOUND ${EIGEN3_VERSION_OK}) else(EIGEN3_INCLUDE_DIR) find_path(EIGEN3_INCLUDE_DIR NAMES signature_of_eigen3_matrix_library PATHS ${CMAKE_INSTALL_PREFIX}/include ${KDE4_INCLUDE_DIR} ${EIGEN3_PATH}/include ${EIGEN3_DIR}/include ${EIGEN3_ROOT}/include ${EIGEN_PATH}/include ${EIGEN_DIR}/include ${EIGEN_ROOT}/include ENV EIGEN3_PATH ENV EIGEN3_DIR ENV EIGEN3_ROOT ENV EIGEN_PATH ENV EIGEN_DIR ENV EIGEN_ROOT PATH_SUFFIXES eigen3 eigen include/eigen3 include/eigen ) if(EIGEN3_INCLUDE_DIR) _eigen3_check_version() endif(EIGEN3_INCLUDE_DIR) mark_as_advanced(EIGEN3_INCLUDE_DIR) endif(EIGEN3_INCLUDE_DIR) include(FindPackageHandleStandardArgs) find_package_handle_standard_args(Eigen3 DEFAULT_MSG EIGEN3_INCLUDE_DIR EIGEN3_VERSION_OK) set( EIGEN3_INCLUDE_DIRS ${EIGEN3_INCLUDE_DIR} ) ecbuild-3.13.1/cmake/contrib/FindNetCDF4.cmake000066400000000000000000000356201513706760700207020ustar00rootroot00000000000000# Project uclales # http://gitorious.org/uclales # License: Academic Free License v3.0 # # - Find NETCDF, a library for reading and writing self describing array data. # # This module invokes the NETCDF wrapper compiler that should be installed # alongside NETCDF. Depending upon the NETCDF Configuration, the wrapper compiler # is called either h5cc or h5pcc. If this succeeds, the module will then call # the compiler with the -show argument to see what flags are used when compiling # an NETCDF client application. # # The module will optionally accept the COMPONENTS argument. If no COMPONENTS # are specified, then the find module will default to finding only the NETCDF C # library. If one or more COMPONENTS are specified, the module will attempt to # find the language bindings for the specified components. Currently, the only # valid components are C, CXX, FORTRAN and F90. # # On UNIX systems, this module will read the variable NETCDF_USE_STATIC_LIBRARIES # to determine whether or not to prefer a static link to a dynamic link for NETCDF # and all of it's dependencies. To use this feature, make sure that the # NETCDF_USE_STATIC_LIBRARIES variable is set before the call to find_package. # # To provide the module with a hint about where to find your NETCDF installation, # set the CMake or environment variable NETCDF_ROOT, NETCDF_DIR, NETCDF_PATH or # NETCDF4_DIR. The Find module will then look in this path when searching for # NETCDF executables, paths, and libraries. # # In addition to finding the includes and libraries required to compile an NETCDF # client application, this module also makes an effort to find tools that come # with the NETCDF distribution that may be useful for regression testing. # # This module will define the following variables: # NETCDF_INCLUDE_DIRS - Location of the NETCDF includes # NETCDF_INCLUDE_DIR - Location of the NETCDF includes (deprecated) # NETCDF_DEFINITIONS - Required compiler definitions for NETCDF # NETCDF_C_LIBRARIES - Required libraries for the NETCDF C bindings. # NETCDF_CXX_LIBRARIES - Required libraries for the NETCDF C++ bindings # NETCDF_FORTRAN_LIBRARIES - Required libraries for the NETCDF FORTRAN bindings # NETCDF_F90_LIBRARIES - Required libraries for the NETCDF FORTRAN 90 bindings # NETCDF_LIBRARIES - Required libraries for all requested bindings # NETCDF_FOUND - true if NETCDF was found on the system # NETCDF_LIBRARY_DIRS - the full set of library directories # NETCDF_IS_PARALLEL - Whether or not NETCDF was found with parallel IO support # NETCDF_CONFIG_EXECUTABLE - the path to the NC-CONFIG tool #============================================================================= # Copyright 2009 Kitware, Inc. # # Distributed under the OSI-approved BSD License (the "License"); # see accompanying file Copyright.txt for details. # # This software is distributed WITHOUT ANY WARRANTY; without even the # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # See the License for more information. #============================================================================= # (To distribute this file outside of CMake, substitute the full # License text for the above reference.) # This module is maintained by Thijs Heus . include(SelectLibraryConfigurations) include(FindPackageHandleStandardArgs) # List of the valid NETCDF components set( NETCDF_VALID_COMPONENTS FORTRAN F90 CXX C ) # Invoke the NETCDF wrapper compiler. The compiler return value is stored to the # return_value argument, the text output is stored to the output variable. macro( _NETCDF_CONFIG flag output return_value ) if( NETCDF_CONFIG_EXECUTABLE ) exec_program( ${NETCDF_CONFIG_EXECUTABLE} ARGS ${flag} OUTPUT_VARIABLE ${output} RETURN_VALUE ${return_value} ) if( ${${return_value}} EQUAL 0 ) # do nothing else() message( STATUS "Unable to determine ${flag} from NC-CONFIG." ) endif() endif() endmacro() # # try to find the NETCDF wrapper compilers find_program( NETCDF_CONFIG_EXECUTABLE NAMES nc-config HINTS ${NETCDF_ROOT} ${NETCDF_DIR} ${NETCDF_PATH} ${NETCDF4_DIR} ENV NETCDF_ROOT ENV NETCDF_DIR ENV NETCDF_PATH ENV NETCDF4_DIR PATH_SUFFIXES bin Bin DOC "NETCDF CONFIG PROGRAM. Used only to detect NETCDF compile flags." ) mark_as_advanced( NETCDF_CONFIG_EXECUTABLE ) ecbuild_debug("FindNetCDF4: nc-config executable = ${NETCDF_CONFIG_EXECUTABLE}") set(output "no") _NETCDF_CONFIG (--has-hdf5 output return) set(HAS_HDF5 FALSE) if(${output} STREQUAL yes) set(HAS_HDF5 TRUE) set(HDF5_FIND_QUIETLY ${NETCDF_FIND_QUIETLY}) set(HDF5_FIND_REQUIRED ${NETCDF_FIND_REQUIRED}) find_package(HDF5) # list( APPEND NETCDF_LIBRARIES_DEBUG # ${HDF5_LIBRARIES_DEBUG} ) # list( APPEND NETCDF_LIBRARIES_RELEASE # ${HDF5_LIBRARIES_RELEASE} ) set (NETCDF_IS_PARALLEL ${HDF5_IS_PARALLEL}) endif() _NETCDF_CONFIG (--has-pnetcdf output return) if(${output} STREQUAL yes) set (NETCDF_IS_PARALLEL TRUE) else() # set(NETCDF_IS_PARALLEL FALSE) endif() set( NETCDF_IS_PARALLEL TRUE CACHE BOOL "NETCDF library compiled with parallel IO support" ) if( NETCDF_INCLUDE_DIRS AND NETCDF_LIBRARIES ) # Do nothing: we already have NETCDF_INCLUDE_PATH and NETCDF_LIBRARIES in the # cache, it would be a shame to override them else() if( NOT NETCDF_FIND_COMPONENTS ) set( NETCDF_LANGUAGE_BINDINGS "C" ) else() # add the extra specified components, ensuring that they are valid. foreach( component ${NETCDF_FIND_COMPONENTS} ) list( FIND NETCDF_VALID_COMPONENTS ${component} component_location ) if( ${component_location} EQUAL -1 ) message( FATAL_ERROR "\"${component}\" is not a valid NETCDF component." ) else() list( APPEND NETCDF_LANGUAGE_BINDINGS ${component} ) endif() endforeach() endif() # seed the initial lists of libraries to find with items we know we need set( NETCDF_C_INCLUDE_NAMES netcdf.h ) set( NETCDF_CXX_INCLUDE_NAMES netcdfcpp.h ${NETCDF_C_INCLUDE_NAMES} ) set( NETCDF_FORTRAN_INCLUDE_NAMES ${NETCDF_C_INCLUDE_NAMES} ) set( NETCDF_F90_INCLUDE_NAMES netcdf.mod typesizes.mod ${NETCDF_C_INCLUDE_NAMES} ) set( NETCDF_C_LIBRARY_NAMES netcdf) set( NETCDF_CXX_LIBRARY_NAMES netcdf_c++ netcdf_c++4 ${NETCDF_C_LIBRARY_NAMES} ) set( NETCDF_FORTRAN_LIBRARY_NAMES netcdff ${NETCDF_C_LIBRARY_NAMES}) set( NETCDF_F90_LIBRARY_NAMES ${NETCDF_FORTRAN_LIBRARY_NAMES} ) set( NETCDF_REQUIRED netcdf.h netcdfcpp.h netcdf.mod typesizes.mod netcdf netcdff netcdf_c++ netcdf_c++4) foreach( LANGUAGE ${NETCDF_LANGUAGE_BINDINGS} ) ecbuild_debug("FindNetCDF4: looking for ${LANGUAGE} language bindings") set( NETCDF_${LANGUAGE}_FOUND 1 ) # disable this in following if necessary # find the NETCDF includes foreach( INC ${NETCDF_${LANGUAGE}_INCLUDE_NAMES} ) #ecbuild_debug( "FindNetCDF4: looking for include file ${INC}") find_path( NETCDF_${INC}_INCLUDE_DIR ${INC} HINTS ${NETCDF_${LANGUAGE}_INCLUDE_FLAGS} ${NETCDF_ROOT} ${NETCDF_DIR} ${NETCDF_PATH} ${NETCDF4_DIR} ENV NETCDF_ROOT ENV NETCDF_DIR ENV NETCDF_PATH ENV NETCDF4_DIR PATH_SUFFIXES include Include ) if( NOT NETCDF_${INC}_INCLUDE_DIR ) #ecbuild_debug( "FindNetCDF4: ${INC} not found" ) GET_FILENAME_COMPONENT( _basename ${INC} NAME_WE ) GET_FILENAME_COMPONENT( _ext ${INC} EXT ) string( TOUPPER ${_basename} _BASENAME ) set( INC_MOD "${_BASENAME}${_ext}") #ecbuild_debug( "FindNetCDF4: try ${INC_MOD}" ) find_path( NETCDF_${INC}_INCLUDE_DIR ${INC_MOD} HINTS ${NETCDF_${LANGUAGE}_INCLUDE_FLAGS} ${NETCDF_ROOT} ${NETCDF_DIR} ${NETCDF_PATH} ${NETCDF4_DIR} ENV NETCDF_ROOT ENV NETCDF_DIR ENV NETCDF_PATH ENV NETCDF4_DIR PATH_SUFFIXES include Include ) endif() mark_as_advanced( NETCDF_${INC}_INCLUDE_DIR ) #ecbuild_debug_var( NETCDF_${INC}_INCLUDE_DIR) if (NETCDF_${INC}_INCLUDE_DIR) list( APPEND NETCDF_INCLUDE_DIRS ${NETCDF_${INC}_INCLUDE_DIR} ) else() list( FIND NETCDF_REQUIRED ${INC} location ) if( ${location} GREATER -1 ) if(NETCDF_FIND_REQUIRED) ecbuild_error( "\"${INC}\" is not found for NetCDF component ${LANGUAGE}" ) elseif( NOT NETCDF_FIND_QUIETLY ) message( STATUS "\"${INC}\" is not found for NetCDF component ${LANGUAGE}" ) endif() set( NETCDF_${LANGUAGE}_FOUND 0 ) endif() endif() endforeach() # find the NETCDF libraries foreach( LIB ${NETCDF_${LANGUAGE}_LIBRARY_NAMES} ) if( UNIX AND NETCDF_USE_STATIC_LIBRARIES ) # According to bug 1643 on the CMake bug tracker, this is the # preferred method for searching for a static library. # See http://www.cmake.org/Bug/view.php?id=1643. We search # first for the full static library name, but fall back to a # generic search on the name if the static search fails. set( THIS_LIBRARY_SEARCH_DEBUG lib${LIB}d.a ${LIB}d ) set( THIS_LIBRARY_SEARCH_RELEASE lib${LIB}.a ${LIB} ) else() set( THIS_LIBRARY_SEARCH_DEBUG ${LIB}d ) set( THIS_LIBRARY_SEARCH_RELEASE ${LIB} ) endif() find_library( NETCDF_${LIB}_LIBRARY_DEBUG NAMES ${THIS_LIBRARY_SEARCH_DEBUG} HINTS ${NETCDF_${LANGUAGE}_LIBRARY_DIRS} ${NETCDF_ROOT} ${NETCDF_DIR} ${NETCDF_PATH} ${NETCDF4_DIR} ENV NETCDF_ROOT ENV NETCDF_DIR ENV NETCDF_PATH ENV NETCDF4_DIR PATH_SUFFIXES lib64 Lib64 lib Lib) find_library( NETCDF_${LIB}_LIBRARY_RELEASE NAMES ${THIS_LIBRARY_SEARCH_RELEASE} HINTS ${NETCDF_${LANGUAGE}_LIBRARY_DIRS} ${NETCDF_ROOT} ${NETCDF_DIR} ${NETCDF_PATH} ${NETCDF4_DIR} ENV NETCDF_ROOT ENV NETCDF_DIR ENV NETCDF_PATH ENV NETCDF4_DIR PATH_SUFFIXES lib64 Lib64 lib Lib ) select_library_configurations( NETCDF_${LIB} ) # even though we adjusted the individual library names in # select_library_configurations, we still need to distinguish # between debug and release variants because NETCDF_LIBRARIES will # need to specify different lists for debug and optimized builds. # We can't just use the NETCDF_${LIB}_LIBRARY variable (which was set # up by the selection macro above) because it may specify debug and # optimized variants for a particular library, but a list of # libraries is allowed to specify debug and optimized only once. if (NETCDF_${LIB}_LIBRARY_RELEASE) list( APPEND NETCDF_LIBRARIES_RELEASE ${NETCDF_${LIB}_LIBRARY_RELEASE} ) list( APPEND NETCDF_${LANGUAGE}_LIBRARIES_RELEASE ${NETCDF_${LIB}_LIBRARY_RELEASE} ) endif() if (NETCDF_${LIB}_LIBRARY_DEBUG) list( APPEND NETCDF_LIBRARIES_DEBUG ${NETCDF_${LIB}_LIBRARY_DEBUG} ) list( APPEND NETCDF_${LANGUAGE}_LIBRARIES_DEBUG ${NETCDF_${LIB}_LIBRARY_DEBUG} ) endif() if (NETCDF_${LIB}_LIBRARY_RELEASE OR NETCDF_${LIB}_LIBRARY_DEBUG ) else() list( FIND NETCDF_REQUIRED ${LIB} location ) if( ${location} EQUAL -1 ) else() if(NETCDF_FIND_REQUIRED) message( SEND_ERROR "\"${LIB}\" is not found for NetCDF component ${LANGUAGE}." ) elseif( NOT NETCDF_FIND_QUIETLY ) message( STATUS "\"${LIB}\" is not found for NetCDF component ${LANGUAGE}." ) else() set( NETCDF_${LANGUAGE}_FOUND 0 ) endif() endif() endif() endforeach() list( APPEND NETCDF_LIBRARY_DIRS ${NETCDF_${LANGUAGE}_LIBRARY_DIRS} ) # Append the libraries for this language binding to the list of all # required libraries. if( NETCDF_${LANGUAGE}_FOUND ) ecbuild_debug( "FindNetCDF4: ${LANGUAGE} language bindings found" ) if( CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE ) list( APPEND NETCDF_${LANGUAGE}_LIBRARIES debug ${NETCDF_${LANGUAGE}_LIBRARIES_DEBUG} optimized ${NETCDF_${LANGUAGE}_LIBRARIES_RELEASE} ) else() list( APPEND NETCDF_${LANGUAGE}_LIBRARIES ${NETCDF_${LANGUAGE}_LIBRARIES_RELEASE} ) endif() endif() # ecbuild_debug_var( NETCDF_${LANGUAGE}_LIBRARIES ) list( APPEND NETCDF_FOUND_REQUIRED_VARS NETCDF_${LANGUAGE}_FOUND ) endforeach() # We may have picked up some duplicates in various lists during the above # process for the language bindings (both the C and C++ bindings depend on # libz for example). Remove the duplicates. if( NETCDF_INCLUDE_DIRS ) list( REMOVE_DUPLICATES NETCDF_INCLUDE_DIRS ) endif() if( NETCDF_LIBRARIES_DEBUG ) list( REMOVE_DUPLICATES NETCDF_LIBRARIES_DEBUG ) endif() if( NETCDF_LIBRARIES_RELEASE ) list( REMOVE_DUPLICATES NETCDF_LIBRARIES_RELEASE ) endif() if( NETCDF_LIBRARY_DIRS ) list( REMOVE_DUPLICATES NETCDF_LIBRARY_DIRS ) endif() # Construct the complete list of NETCDF libraries with debug and optimized # variants when the generator supports them. if( CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE ) if( NOT NETCDF_LIBRARIES_DEBUG ) set( NETCDF_LIBRARIES_DEBUG ${NETCDF_LIBRARIES_RELEASE} ) endif() set( NETCDF_LIBRARIES debug ${NETCDF_LIBRARIES_DEBUG} optimized ${NETCDF_LIBRARIES_RELEASE} ) else() set( NETCDF_LIBRARIES ${NETCDF_LIBRARIES_RELEASE} ) endif() endif() set( NETCDF4_FIND_QUIETLY ${NETCDF_FIND_QUIETLY} ) set( NETCDF4_FIND_REQUIRED ${NETCDF_FIND_REQUIRED} ) # handle the QUIET and REQUIRED arguments and set NETCDF4_FOUND to TRUE # if all listed variables are valid # Note: capitalisation of the package name must be the same as in the file name find_package_handle_standard_args( NetCDF4 DEFAULT_MSG ${NETCDF_FOUND_REQUIRED_VARS} NETCDF_LIBRARIES NETCDF_INCLUDE_DIRS ) mark_as_advanced( NETCDF_INCLUDE_DIRS NETCDF_LIBRARIES NETCDF_LIBRARY_DIRS ) set( NETCDF_FOUND ${NETCDF4_FOUND} ) set( NetCDF_FOUND ${NETCDF4_FOUND} ) set( NetCDF4_FOUND ${NETCDF4_FOUND} ) # For backwards compatibility we set NETCDF_INCLUDE_DIR to the value of # NETCDF_INCLUDE_DIRS set( NETCDF_INCLUDE_DIR "${NETCDF_INCLUDE_DIRS}" ) ecbuild-3.13.1/cmake/contrib/GetGitRevisionDescription.cmake000066400000000000000000000100141513706760700240460ustar00rootroot00000000000000# - Returns a version string from Git # # These functions force a re-configure on each git commit so that you can # trust the values of the variables in your build system. # # get_git_head_revision( [ ...]) # # Returns the refspec and sha hash of the current head revision # # git_describe( [ ...]) # # Returns the results of git describe on the source tree, and adjusting # the output so that it tests false if an error occurs. # # git_get_exact_tag( [ ...]) # # Returns the results of git describe --exact-match on the source tree, # and adjusting the output so that it tests false if there was no exact # matching tag. # # Requires CMake 2.6 or newer (uses the 'function' command) # # Original Author: # 2009-2010 Ryan Pavlik # http://academic.cleardefinition.com # Iowa State University HCI Graduate Program/VRAC # # Copyright Iowa State University 2009-2010. # Distributed under the Boost Software License, Version 1.0. # (See accompanying file LICENSE_1_0.txt or copy at # http://www.boost.org/LICENSE_1_0.txt) if(__get_git_revision_description) return() endif() set(__get_git_revision_description YES) # We must run the following at "include" time, not at function call time, # to find the path to this module rather than the path to a calling list file get_filename_component(_gitdescmoddir ${CMAKE_CURRENT_LIST_FILE} PATH) function(get_git_head_revision _refspecvar _hashvar) set(GIT_PARENT_DIR "${PROJECT_SOURCE_DIR}") set(GIT_DIR "${GIT_PARENT_DIR}/.git") while(NOT EXISTS "${GIT_DIR}") # .git dir not found, search parent directories set(GIT_PREVIOUS_PARENT "${GIT_PARENT_DIR}") get_filename_component(GIT_PARENT_DIR ${GIT_PARENT_DIR} PATH) if(GIT_PARENT_DIR STREQUAL GIT_PREVIOUS_PARENT) # We have reached the root directory, we are not in git set(${_refspecvar} "GITDIR-NOTFOUND" PARENT_SCOPE) set(${_hashvar} "GITDIR-NOTFOUND" PARENT_SCOPE) return() endif() set(GIT_DIR "${GIT_PARENT_DIR}/.git") endwhile() set(GIT_DATA "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/git-data") if(NOT EXISTS "${GIT_DATA}") file(MAKE_DIRECTORY "${GIT_DATA}") endif() if(NOT EXISTS "${GIT_DIR}/HEAD") return() endif() set(HEAD_FILE "${GIT_DATA}/HEAD") configure_file("${GIT_DIR}/HEAD" "${HEAD_FILE}" COPYONLY) configure_file("${_gitdescmoddir}/GetGitRevisionDescription.cmake.in" "${GIT_DATA}/grabRef.cmake" @ONLY) include("${GIT_DATA}/grabRef.cmake") set(${_refspecvar} "${HEAD_REF}" PARENT_SCOPE) set(${_hashvar} "${HEAD_HASH}" PARENT_SCOPE) endfunction() function(git_describe _var) if(NOT GIT_FOUND) find_package(Git QUIET) endif() get_git_head_revision(refspec hash) if(NOT GIT_FOUND) set(${_var} "GIT-NOTFOUND" PARENT_SCOPE) return() endif() if(NOT hash) set(${_var} "HEAD-HASH-NOTFOUND" PARENT_SCOPE) return() endif() # TODO sanitize #if((${ARGN}" MATCHES "&&") OR # (ARGN MATCHES "||") OR # (ARGN MATCHES "\\;")) # message("Please report the following error to the project!") # message(FATAL_ERROR "Looks like someone's doing something nefarious with git_describe! Passed arguments ${ARGN}") #endif() #message(STATUS "Arguments to execute_process: ${ARGN}") execute_process(COMMAND "${GIT_EXECUTABLE}" describe ${hash} ${ARGN} WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" RESULT_VARIABLE res OUTPUT_VARIABLE out ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) if(NOT res EQUAL 0) set(out "${out}-${res}-NOTFOUND") endif() set(${_var} "${out}" PARENT_SCOPE) endfunction() function(git_get_exact_tag _var) git_describe(out --exact-match ${ARGN}) set(${_var} "${out}" PARENT_SCOPE) endfunction() ecbuild-3.13.1/cmake/contrib/GetGitRevisionDescription.cmake.in000066400000000000000000000024611513706760700244620ustar00rootroot00000000000000# # Internal file for GetGitRevisionDescription.cmake # # Requires CMake 2.6 or newer (uses the 'function' command) # # Original Author: # 2009-2010 Ryan Pavlik # http://academic.cleardefinition.com # Iowa State University HCI Graduate Program/VRAC # # Copyright Iowa State University 2009-2010. # Distributed under the Boost Software License, Version 1.0. # (See accompanying file LICENSE_1_0.txt or copy at # http://www.boost.org/LICENSE_1_0.txt) set(HEAD_HASH) file(READ "@HEAD_FILE@" HEAD_CONTENTS LIMIT 1024) string(STRIP "${HEAD_CONTENTS}" HEAD_CONTENTS) if(HEAD_CONTENTS MATCHES "ref") # named branch string(REPLACE "ref: " "" HEAD_REF "${HEAD_CONTENTS}") if(EXISTS "@GIT_DIR@/${HEAD_REF}") configure_file("@GIT_DIR@/${HEAD_REF}" "@GIT_DATA@/head-ref" COPYONLY) elseif(EXISTS "@GIT_DIR@/logs/${HEAD_REF}") configure_file("@GIT_DIR@/logs/${HEAD_REF}" "@GIT_DATA@/head-ref" COPYONLY) set(HEAD_HASH "${HEAD_REF}") endif() else() # detached HEAD configure_file("@GIT_DIR@/HEAD" "@GIT_DATA@/head-ref" COPYONLY) endif() if(NOT HEAD_HASH) if(EXISTS "@GIT_DATA@/head-ref") file(READ "@GIT_DATA@/head-ref" HEAD_HASH LIMIT 1024) string(STRIP "${HEAD_HASH}" HEAD_HASH) else() set(HEAD_HASH "unknown") endif() endif() ecbuild-3.13.1/cmake/determine-nec.F90000066400000000000000000000001261513706760700173000ustar00rootroot00000000000000#ifndef __NEC__ #error Not the NEC compiler #endif program determine_nec end program ecbuild-3.13.1/cmake/ecbuild-config-version.cmake000066400000000000000000000006031513706760700216400ustar00rootroot00000000000000include(${CMAKE_CURRENT_LIST_DIR}/ecbuild_parse_version.cmake) ecbuild_parse_version_file(${CMAKE_CURRENT_LIST_DIR}/VERSION PREFIX PACKAGE) if(PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION) set(PACKAGE_VERSION_COMPATIBLE FALSE) else() set(PACKAGE_VERSION_COMPATIBLE TRUE) if(PACKAGE_FIND_VERSION STREQUAL PACKAGE_VERSION) set(PACKAGE_VERSION_EXACT TRUE) endif() endif() ecbuild-3.13.1/cmake/ecbuild-config.cmake000066400000000000000000000012371513706760700201610ustar00rootroot00000000000000# (C) Copyright 2019- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation nor # does it submit to any jurisdiction. get_filename_component(ecbuild_MACROS_DIR ${CMAKE_CURRENT_LIST_DIR} ABSOLUTE) cmake_policy( PUSH ) cmake_policy( SET CMP0057 NEW ) if(NOT ${ecbuild_MACROS_DIR} IN_LIST CMAKE_MODULE_PATH) list(INSERT CMAKE_MODULE_PATH 0 ${ecbuild_MACROS_DIR}) endif() cmake_policy( POP ) include(ecbuild) ecbuild-3.13.1/cmake/ecbuild.cmake000066400000000000000000000025271513706760700167210ustar00rootroot00000000000000# (C) Copyright 2019- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation nor # does it submit to any jurisdiction. if( NOT ECBUILD_PROJECT_${CMAKE_CURRENT_SOURCE_DIR} ) set( ECBUILD_PROJECT_${CMAKE_CURRENT_SOURCE_DIR} TRUE ) ######################################################################################################## # compatibility with ecbuild 2 if ( NOT DEFINED ECBUILD_2_COMPAT_VALUE ) set( ECBUILD_2_COMPAT_VALUE OFF ) endif() if ( NOT DEFINED ECBUILD_2_COMPAT_DEPRECATE_VALUE ) set( ECBUILD_2_COMPAT_DEPRECATE_VALUE ON ) endif() option( ECBUILD_2_COMPAT "Keep compatibility with ecbuild 2" ${ECBUILD_2_COMPAT_VALUE} ) option( ECBUILD_2_COMPAT_DEPRECATE "Emit deprecation warnings in the compatibility layer" ${ECBUILD_2_COMPAT_DEPRECATE_VALUE} ) if( ECBUILD_2_COMPAT_DEPRECATE ) set( CMAKE_WARN_DEPRECATED ON ) endif() ######################################################################################################## include( ecbuild_project ) ######################################################################################################## endif() ecbuild-3.13.1/cmake/ecbuild_add_c_flags.cmake000066400000000000000000000026541513706760700212100ustar00rootroot00000000000000# (C) Copyright 2011- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation # nor does it submit to any jurisdiction. ############################################################################## #.rst: # # ecbuild_add_c_flags # =================== # # Add C compiler flags to CMAKE_C_FLAGS only if supported by the compiler. :: # # ecbuild_add_c_flags( [ ... ] # [ BUILD ] # [ NAME ] # [ NO_FAIL ] ) # # Options # ------- # # BUILD : optional # add flags to ``CMAKE_C_FLAGS_`` instead of ``CMAKE_C_FLAGS`` # # NAME : optional # name of the check (if omitted, checks are enumerated) # # NO_FAIL : optional # do not fail if the flag cannot be added # ############################################################################## include(ecbuild_add_lang_flags) macro( ecbuild_add_c_flags ) ecbuild_debug("call ecbuild_add_c_flags( ${ARGV} )") ecbuild_add_lang_flags( FLAGS ${ARGV} LANG C ) endmacro() macro( cmake_add_c_flags ) ecbuild_deprecate( " cmake_add_c_flags is deprecated, use ecbuild_add_c_flags instead." ) ecbuild_add_c_flags( ${ARGV} ) endmacro() ecbuild-3.13.1/cmake/ecbuild_add_cxx_flags.cmake000066400000000000000000000027121513706760700215630ustar00rootroot00000000000000# (C) Copyright 2011- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation # nor does it submit to any jurisdiction. ############################################################################## #.rst: # # ecbuild_add_cxx_flags # ===================== # # Add C++ compiler flags to CMAKE_CXX_FLAGS only if supported by compiler. :: # # ecbuild_add_cxx_flags( [ ... ] # [ BUILD ] # [ NAME ] # [ NO_FAIL ] ) # # Options # ------- # # BUILD : optional # add flags to ``CMAKE_CXX_FLAGS_`` instead of ``CMAKE_CXX_FLAGS`` # # NAME : optional # name of the check (if omitted, checks are enumerated) # # NO_FAIL : optional # do not fail if the flag cannot be added # ############################################################################## include(ecbuild_add_lang_flags) macro( ecbuild_add_cxx_flags ) ecbuild_debug("call ecbuild_add_cxx_flags( ${ARGV} )") ecbuild_add_lang_flags( FLAGS ${ARGV} LANG CXX ) endmacro() macro( cmake_add_cxx_flags ) ecbuild_deprecate( " cmake_add_cxx_flags is deprecated, use ecbuild_add_cxx_flags instead." ) ecbuild_add_cxx_flags( ${ARGV} ) endmacro() ecbuild-3.13.1/cmake/ecbuild_add_executable.cmake000066400000000000000000000323211513706760700217250ustar00rootroot00000000000000# (C) Copyright 2011- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation nor # does it submit to any jurisdiction. ############################################################################## #.rst: # # ecbuild_add_executable # ====================== # # Add an executable with a given list of source files. :: # # ecbuild_add_executable( TARGET # SOURCES [ ...] # [ SOURCES_GLOB [ ...] ] # [ SOURCES_EXCLUDE_REGEX [ ...] ] # [ OBJECTS [ ...] ] # [ TEMPLATES [ ...] ] # [ LIBS [ ...] ] # [ NO_AS_NEEDED ] # [ INCLUDES [ ...] ] # [ DEFINITIONS [ ...] ] # [ PERSISTENT [ ...] ] # [ GENERATED [ ...] ] # [ DEPENDS [ ...] ] # [ CONDITION ] # [ PROPERTIES [ ...] ] # [ NOINSTALL ] # [ VERSION | AUTO_VERSION ] # [ CFLAGS [ ...] ] # [ CXXFLAGS [ ...] ] # [ FFLAGS [ ...] ] # [ LINKER_LANGUAGE ] # [ OUTPUT_NAME ] ) # # Options # ------- # # TARGET : required # target name # # SOURCES : required # list of source files # # SOURCES_GLOB : optional # search pattern to find source files to compile (note: not recommend according to CMake guidelines) # it is usually better to explicitly list the source files in the CMakeList.txt # # SOURCES_EXCLUDE_REGEX : optional # search pattern to exclude source files from compilation, applies o the results of SOURCES_GLOB # # OBJECTS : optional # list of object libraries to add to this target # # TEMPLATES : optional # list of files specified as SOURCES which are not to be compiled separately # (these are commonly template implementation files included in a header) # # LIBS : optional # list of libraries to link against (CMake targets or external libraries) # # NO_AS_NEEDED: optional # add --no-as-needed linker flag, to prevent stripping libraries that looks like are not used # # INCLUDES : optional # list of paths to add to include directories # # DEFINITIONS : optional # list of definitions to add to preprocessor defines # # PERSISTENT : optional # list of persistent layer object files # # GENERATED : optional # list of files to mark as generated (sets GENERATED source file property) # # DEPENDS : optional # list of targets to be built before this target # # CONDITION : optional # conditional expression which must evaluate to true for this target to be # built (must be valid in a CMake ``if`` statement) # # PROPERTIES : optional # custom properties to set on the target # # NOINSTALL : optional # do not install the executable # # VERSION : optional, AUTO_VERSION or LIBS_VERSION is used if not specified # version to use as executable version # # AUTO_VERSION : optional, ignored if VERSION is specified # automatically version the executable with the package version # # CFLAGS : optional # list of C compiler flags to use for all C source files # # See usage note below. # # CXXFLAGS : optional # list of C++ compiler flags to use for all C++ source files # # See usage note below. # # FFLAGS : optional # list of Fortran compiler flags to use for all Fortran source files # # See usage note below. # # LINKER_LANGUAGE : optional # sets the LINKER_LANGUAGE property on the target # # OUTPUT_NAME : optional # sets the OUTPUT_NAME property on the target # # Usage # ----- # # The ``CFLAGS``, ``CXXFLAGS`` and ``FFLAGS`` options apply the given compiler # flags to all C, C++ and Fortran sources passed to this command, respectively. # If any two ``ecbuild_add_executable``, ``ecbuild_add_library`` or # ``ecbuild_add_test`` commands are passed the *same* source file and each sets # a different value for the compiler flags to be applied to that file (including # when one command adds flags and another adds none), then the two commands # will be in conflict and the result may not be as expected. # # For this reason it is recommended not to use the ``*FLAGS`` options when # multiple targets share the same source files, unless the exact same flags are # applied to those sources by each relevant command. # # Care should also be taken to ensure that these commands are not passed source # files which are not required to build the target, if those sources are also # passed to other commands which set different compiler flags. # ############################################################################## function( ecbuild_add_executable ) set( options NOINSTALL AUTO_VERSION NO_AS_NEEDED ) set( single_value_args TARGET COMPONENT LINKER_LANGUAGE VERSION OUTPUT_NAME ) set( multi_value_args SOURCES SOURCES_GLOB SOURCES_EXCLUDE_REGEX OBJECTS TEMPLATES LIBS INCLUDES DEPENDS PERSISTENT DEFINITIONS CFLAGS CXXFLAGS FFLAGS GENERATED CONDITION PROPERTIES ) cmake_parse_arguments( _PAR "${options}" "${single_value_args}" "${multi_value_args}" ${_FIRST_ARG} ${ARGN} ) if(_PAR_UNPARSED_ARGUMENTS) ecbuild_critical("Unknown keywords given to ecbuild_add_executable(): \"${_PAR_UNPARSED_ARGUMENTS}\"") endif() if( NOT _PAR_TARGET ) ecbuild_critical("The call to ecbuild_add_executable() doesn't specify the TARGET.") endif() if( NOT _PAR_SOURCES AND NOT _PAR_OBJECTS AND NOT _PAR_SOURCES_GLOB ) ecbuild_critical("The call to ecbuild_add_executable() specifies neither SOURCES nor OBJECTS nor SOURCES_GLOB.") endif() ### conditional build ecbuild_evaluate_dynamic_condition( _PAR_CONDITION _${_PAR_TARGET}_condition ) if( _${_PAR_TARGET}_condition ) # insert already compiled objects (from OBJECT libraries) unset( _all_objects ) foreach( _obj ${_PAR_OBJECTS} ) list( APPEND _all_objects $ ) endforeach() # glob sources unset( _glob_srcs ) foreach( pattern ${_PAR_SOURCES_GLOB} ) ecbuild_list_add_pattern( LIST _glob_srcs GLOB "${pattern}" ) endforeach() foreach( pattern ${_PAR_SOURCES_EXCLUDE_REGEX} ) ecbuild_list_exclude_pattern( LIST _glob_srcs REGEX "${pattern}" ) endforeach() list( APPEND _PAR_SOURCES ${_glob_srcs} ) if( ECBUILD_LIST_SOURCES ) ecbuild_debug("ecbuild_add_library(${_PAR_TARGET}): sources ${_PAR_SOURCES}") endif() # add persistent layer files ecbuild_add_persistent( SRC_LIST _PAR_SOURCES FILES ${_PAR_PERSISTENT} NAMESPACE "${PERSISTENT_NAMESPACE}" ) # remove templates from compilation sources if( DEFINED _PAR_TEMPLATES ) ecbuild_debug("ecbuild_add_executable(${_PAR_TARGET}): removing ${_PAR_TEMPLATES} from sources") list( REMOVE_ITEM _PAR_SOURCES ${_PAR_TEMPLATES} ) add_custom_target( ${_PAR_TARGET}_templates SOURCES ${_PAR_TEMPLATES} ) endif() # Separate sources if( _PAR_SOURCES ) ecbuild_separate_sources( TARGET ${_PAR_TARGET} SOURCES ${_PAR_SOURCES} ) endif() if( ${_PAR_TARGET}_cuda_srcs AND CUDA_FOUND ) cuda_add_executable( ${_PAR_TARGET} ${_PAR_SOURCES} ${_all_objects} ) else() add_executable( ${_PAR_TARGET} ${_PAR_SOURCES} ${_all_objects} ) endif() # Set custom properties if( ${_PAR_PROPERTIES} ) set_target_properties( ${_PAR_TARGET} PROPERTIES ${_PAR_PROPERTIES} ) endif() # ecbuild_echo_target( ${_PAR_TARGET} ) # add include dirs if defined if( DEFINED _PAR_INCLUDES ) ecbuild_filter_list(INCLUDES LIST ${_PAR_INCLUDES} LIST_INCLUDE path LIST_EXCLUDE skipped_path) ecbuild_debug("ecbuild_add_executable(${_PAR_TARGET}): add [${path}] to include_directories") target_include_directories( ${_PAR_TARGET} PRIVATE ${path} ) ecbuild_debug("ecbuild_add_executable(${_PAR_TARGET}): [${skipped_path}] not found - not adding to include_directories") endif() # set OUTPUT_NAME if( DEFINED _PAR_OUTPUT_NAME ) ecbuild_debug("ecbuild_add_executable(${_PAR_TARGET}): set OUTPUT_NAME to ${_PAR_OUTPUT_NAME}") set_target_properties( ${_PAR_TARGET} PROPERTIES OUTPUT_NAME ${_PAR_OUTPUT_NAME} ) endif() # add extra dependencies if( DEFINED _PAR_DEPENDS) ecbuild_debug("ecbuild_add_executable(${_PAR_TARGET}): add dependency on ${_PAR_DEPENDS}") add_dependencies( ${_PAR_TARGET} ${_PAR_DEPENDS} ) endif() # add the link libraries if( DEFINED _PAR_LIBS ) list(REMOVE_ITEM _PAR_LIBS debug) list(REMOVE_ITEM _PAR_LIBS optimized) ecbuild_filter_list(LIBS LIST ${_PAR_LIBS} LIST_INCLUDE lib LIST_EXCLUDE skipped_lib) if ( _PAR_NO_AS_NEEDED AND CMAKE_SYSTEM_NAME MATCHES "Linux" AND CMAKE_CXX_COMPILER_ID MATCHES "GNU" ) target_link_libraries( ${_PAR_TARGET} -Wl,--no-as-needed ${lib} ) else() target_link_libraries( ${_PAR_TARGET} ${lib} ) endif() ecbuild_debug("ecbuild_add_executable(${_PAR_TARGET}): linking with [${lib}]") ecbuild_debug("ecbuild_add_executable(${_PAR_TARGET}): [${skipped_lib}] not found - not linking") endif() # Override compilation flags on a per source file basis ecbuild_target_flags( ${_PAR_TARGET} "${_PAR_CFLAGS}" "${_PAR_CXXFLAGS}" "${_PAR_FFLAGS}" ) # define VERSION if requested if( DEFINED _PAR_VERSION ) ecbuild_debug("ecbuild_add_executable(${_PAR_TARGET}): set version to ${_PAR_VERSION}") set_target_properties( ${_PAR_TARGET} PROPERTIES VERSION "${_PAR_VERSION}" ) else() if( _PAR_AUTO_VERSION ) ecbuild_debug("ecbuild_add_executable(${_PAR_TARGET}): set version to ${${PROJECT_NAME}_VERSION_MAJOR}.${${PROJECT_NAME}_VERSION_MINOR}") set_target_properties( ${_PAR_TARGET} PROPERTIES VERSION "${${PROJECT_NAME}_VERSION_MAJOR}.${${PROJECT_NAME}_VERSION_MINOR}" ) endif() endif() # installation if( NOT _PAR_NOINSTALL ) ecbuild_debug("ecbuild_add_executable(${_PAR_TARGET}): installing to ${INSTALL_BIN_DIR}") # add installation paths and associate with defined component # if( DEFINED _PAR_COMPONENT ) # set( COMPONENT_DIRECTIVE "${_PAR_COMPONENT}" ) # else() # set( COMPONENT_DIRECTIVE "${PROJECT_NAME}" ) # endif() install( TARGETS ${_PAR_TARGET} EXPORT ${PROJECT_NAME}-targets RUNTIME DESTINATION ${INSTALL_BIN_DIR} LIBRARY DESTINATION ${INSTALL_LIB_DIR} ARCHIVE DESTINATION ${INSTALL_LIB_DIR} ) # COMPONENT ${COMPONENT_DIRECTIVE} ) # set build location set_target_properties( ${_PAR_TARGET} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin ) # export location of target to other projects -- must be exactly after setting the build location (see previous command) export( TARGETS ${_PAR_TARGET} APPEND FILE "${PROJECT_TARGETS_FILE}" ) else() ecbuild_debug("ecbuild_add_executable(${_PAR_TARGET}): not installing") # NOINSTALL targets are always built the build_rpath, not the install_rpath set_target_properties( ${_PAR_TARGET} PROPERTIES SKIP_BUILD_RPATH FALSE ) set_target_properties( ${_PAR_TARGET} PROPERTIES BUILD_WITH_INSTALL_RPATH FALSE ) endif() # add definitions to compilation if( DEFINED _PAR_DEFINITIONS ) target_compile_definitions(${_PAR_TARGET} PRIVATE ${_PAR_DEFINITIONS}) ecbuild_debug("ecbuild_add_executable(${_PAR_TARGET}): adding definitions ${_PAR_DEFINITIONS}") endif() # set linker language if( DEFINED _PAR_LINKER_LANGUAGE ) ecbuild_debug("ecbuild_add_executable(${_PAR_TARGET}): using linker language ${_PAR_LINKER_LANGUAGE}") set_target_properties( ${_PAR_TARGET} PROPERTIES LINKER_LANGUAGE ${_PAR_LINKER_LANGUAGE} ) if( ECBUILD_${_PAR_LINKER_LANGUAGE}_IMPLICIT_LINK_LIBRARIES ) target_link_libraries( ${_PAR_TARGET} ${ECBUILD_${_PAR_LINKER_LANGUAGE}_IMPLICIT_LINK_LIBRARIES} ) endif() endif() if( ECBUILD_IMPLICIT_LINK_LIBRARIES ) target_link_libraries( ${_PAR_TARGET} ${ECBUILD_IMPLICIT_LINK_LIBRARIES} ) endif() # make sure target is removed before - some problems with AIX add_custom_command( TARGET ${_PAR_TARGET} PRE_BUILD COMMAND ${CMAKE_COMMAND} -E remove $ ) # append to the list of this project targets set( ${PROJECT_NAME}_ALL_EXES ${${PROJECT_NAME}_ALL_EXES} ${_PAR_TARGET} CACHE INTERNAL "" ) endif() # mark source files as used ecbuild_declare_project_files( ${_PAR_SOURCES} ) if( DEFINED _PAR_TEMPLATES ) ecbuild_declare_project_files( ${_PAR_TEMPLATES} ) endif() endfunction( ecbuild_add_executable ) ecbuild-3.13.1/cmake/ecbuild_add_fortran_flags.cmake000066400000000000000000000030711513706760700224330ustar00rootroot00000000000000# (C) Copyright 2011- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation # nor does it submit to any jurisdiction. ############################################################################## #.rst: # # ecbuild_add_fortran_flags # ========================= # # Add Fortran compiler flags to CMAKE_Fortran_FLAGS only if supported by the # compiler. :: # # ecbuild_add_fortran_flags( [ ... ] # [ BUILD ] # [ NAME ] # [ NO_FAIL ] ) # # Options # ------- # # BUILD : optional # add flags to ``CMAKE_Fortran_FLAGS_`` instead of # ``CMAKE_Fortran_FLAGS`` # # NAME : optional # name of the check (if omitted, checks are enumerated) # # NO_FAIL : optional # do not fail if the flag cannot be added # ############################################################################## include( CheckFortranCompilerFlag ) include(ecbuild_add_lang_flags) macro( ecbuild_add_fortran_flags ) ecbuild_debug("call ecbuild_add_fortran_flags( ${ARGV} )") ecbuild_add_lang_flags( FLAGS ${ARGV} LANG Fortran ) endmacro() macro( cmake_add_fortran_flags ) ecbuild_deprecate( " cmake_add_fortran_flags is deprecated, use ecbuild_add_fortran_flags instead." ) ecbuild_add_fortran_flags( ${ARGV} ) endmacro() ecbuild-3.13.1/cmake/ecbuild_add_lang_flags.cmake000066400000000000000000000103541513706760700217030ustar00rootroot00000000000000# (C) Copyright 2011- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation # nor does it submit to any jurisdiction. ############################################################################## #.rst: # # ecbuild_add_lang_flags # ====================== # # This is mostly an internal function of ecbuild, wrapped by the macros ecbuild_add_c_flags, # ecbuild_add_cxx_flags and ecbuild_add_fortran_flags. # # Add compiler flags to the CMAKE_${lang}_FLAGS only if supported by compiler. :: # # ecbuild_add_lang_flags( FLAGS [ ... ] # LANG [C|CXX|Fortran] # [ BUILD ] # [ NAME ] # [ NO_FAIL ] ) # # Options # ------- # # LANG: # define the language to add the flag too # # BUILD : optional # add flags to `CMAKE_${lang}_FLAGS_` instead of `CMAKE_${lang}_FLAGS` # # NAME : optional # name of the check (if omitted, checks are enumerated) # # NO_FAIL : optional # do not fail if the flag cannot be added # ############################################################################## function( ecbuild_add_lang_flags ) ecbuild_debug("call ecbuild_add_lang_flags( ${ARGV} )") set( options NO_FAIL ) set( single_value_args BUILD NAME LANG ) set( multi_value_args FLAGS ) cmake_parse_arguments( _PAR "${options}" "${single_value_args}" "${multi_value_args}" ${_FIRST_ARG} ${ARGN} ) if(DEFINED _PAR_LANG) set(_lang ${_PAR_LANG}) else() ecbuild_critical("ecbuild_add_lang_flags() called without LANG parameter") endif() if(DEFINED _PAR_FLAGS) set(_flags ${_PAR_FLAGS}) else() list(FIND ARGV FLAGS ARG_FOUND) if( ARG_FOUND STREQUAL -1 ) ecbuild_critical("ecbuild_add_lang_flags() called without FLAGS parameter") endif() return() endif() # To handle the case where FLAGS is a list string( REPLACE ";" " " _flags "${_flags}" ) ecbuild_debug( "CMAKE_${_lang}_COMPILER_LOADED [${CMAKE_${_lang}_COMPILER_LOADED}]" ) if( CMAKE_${_lang}_COMPILER_LOADED ) if( ECBUILD_TRUST_FLAGS ) set( _flag_ok 1 ) else() set( _flag_ok 0 ) endif() if( NOT _flag_ok ) if( NOT DEFINED N_${_lang}_FLAG ) set( N_${_lang}_FLAG 0 ) endif() math( EXPR N_${_lang}_FLAG "${N_${_lang}_FLAG}+1" ) set( N_${_lang}_FLAG ${N_${_lang}_FLAG} PARENT_SCOPE ) # to increment across calls to this function if( NOT DEFINED _PAR_NAME ) set(_PAR_NAME ${PROJECT_NAME}_${_lang}_FLAG_TEST_${N_${_lang}_FLAG}) endif() if(${_lang} STREQUAL "C") ecbuild_debug( "check_c_compiler_flag( ${_flags} ${_PAR_NAME} )" ) check_c_compiler_flag( ${_flags} ${_PAR_NAME} ) endif() if(${_lang} STREQUAL "CXX") ecbuild_debug( "check_cxx_compiler_flag( ${_flags} ${_PAR_NAME} )" ) check_cxx_compiler_flag( ${_flags} ${_PAR_NAME} ) endif() if(${_lang} STREQUAL "Fortran") ecbuild_debug( "check_fortran_compiler_flag( ${_flags} ${_PAR_NAME} )" ) check_fortran_compiler_flag( ${_flags} ${_PAR_NAME} ) endif() set( _flag_ok ${${_PAR_NAME}} ) ecbuild_debug( "${_lang} flag [${_flags}] check resulted [${_flag_ok}]" ) endif( NOT _flag_ok ) if( _flag_ok ) if( _PAR_BUILD ) set( CMAKE_${_lang}_FLAGS_${_PAR_BUILD} "${CMAKE_${_lang}_FLAGS_${_PAR_BUILD}} ${_flags}" PARENT_SCOPE ) ecbuild_info( "Added ${_lang} flag [${_flags}] to build type ${_PAR_BUILD}" ) else() set( CMAKE_${_lang}_FLAGS "${CMAKE_${_lang}_FLAGS} ${_flags}" PARENT_SCOPE ) ecbuild_info( "Added ${_lang} flag [${_flags}]" ) endif() elseif( _PAR_NO_FAIL ) ecbuild_info( "${_lang} compiler ${CMAKE_${_lang}_COMPILER} does not recognise ${_lang} flag '${_flags}' -- skipping and continuing" ) else() ecbuild_critical( "${_lang} compiler ${CMAKE_${_lang}_COMPILER} does not recognise ${_lang} flag '${_flags}'" ) endif( _flag_ok ) endif( CMAKE_${_lang}_COMPILER_LOADED ) endfunction() ecbuild-3.13.1/cmake/ecbuild_add_large_file_support.cmake000066400000000000000000000027141513706760700234740ustar00rootroot00000000000000# (C) Copyright 2011- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation nor # does it submit to any jurisdiction. ############################################################################################ # ensure we use 64bit access to files even on 32bit OS's -- aka Large File Support # by making off_t 64 bit and stat behave as stat64 macro(ecbuild_add_large_file_support) check_type_size( off_t EC_SIZEOF_OFF_T ) if( EC_SIZEOF_OFF_T LESS "8" ) if( ${CMAKE_SYSTEM_NAME} MATCHES "Linux" OR ${CMAKE_SYSTEM_NAME} MATCHES "Darwin" OR ${CMAKE_SYSTEM_NAME} STREQUAL "GNU" ) add_definitions( -D_FILE_OFFSET_BITS=64 ) elseif( ${CMAKE_SYSTEM_NAME} MATCHES "AIX" ) add_definitions( -D_LARGE_FILES=64 ) else() ecbuild_warn("ENABLE_LARGE_FILE_SUPPORT active, sizeof off_t is ${EC_SIZEOF_OFF_T} < 8 " "but ecbuild does not know how to enable large files in this operating system") endif() get_directory_property( __compile_defs COMPILE_DEFINITIONS ) if( __compile_defs ) foreach( def ${__compile_defs} ) list( APPEND CMAKE_REQUIRED_DEFINITIONS -D${def} ) endforeach() endif() endif() endmacro(ecbuild_add_large_file_support) ecbuild-3.13.1/cmake/ecbuild_add_library.cmake000066400000000000000000000670241513706760700212600ustar00rootroot00000000000000# (C) Copyright 2011- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation nor # does it submit to any jurisdiction. ############################################################################## #.rst: # # ecbuild_add_library # =================== # # Add a library with a given list of source files. :: # # ecbuild_add_library( TARGET # SOURCES [ ...] # [ SOURCES_GLOB [ ...] ] # [ SOURCES_EXCLUDE_REGEX [ ...] ] # [ TYPE SHARED|STATIC|MODULE|OBJECT|INTERFACE ] # [ OBJECTS [ ...] ] # [ TEMPLATES [ ...] ] # [ LIBS [ ...] ] # [ PRIVATE_LIBS [ ...] ] # [ PUBLIC_LIBS [ ...] ] # [ INCLUDES [ ...] ] # [ PRIVATE_INCLUDES [ ...] ] # [ PUBLIC_INCLUDES [ ...] ] # [ DEFINITIONS [ ...] ] # [ PRIVATE_DEFINITIONS [ ...] ] # [ PUBLIC_DEFINITIONS [ ...] ] # [ PERSISTENT [ ...] ] # [ GENERATED [ ...] ] # [ DEPENDS [ ...] ] # [ CONDITION ] # [ PROPERTIES [ ...] ] # [ NOINSTALL ] # [ HEADER_DESTINATION ] # [ INSTALL_HEADERS LISTED|ALL ] # [ INSTALL_HEADERS_LIST [ ...] ] # [ INSTALL_HEADERS_REGEX ] # [ VERSION | AUTO_VERSION ] # [ SOVERSION | AUTO_SOVERSION ] # [ CFLAGS [ ...] ] # [ CXXFLAGS [ ...] ] # [ FFLAGS [ ...] ] # [ LINKER_LANGUAGE ] # [ OUTPUT_NAME ] ) # # Options # ------- # # TARGET : required # target name # # SOURCES : required # list of source files # # TYPE : optional # library type, one of: # # :SHARED: libraries are linked dynamically and loaded at runtime # :STATIC: archives of object files for use when linking other targets. # :MODULE: plugins that are not linked into other targets but may be loaded # dynamically at runtime using dlopen-like functionality # :OBJECT: files are just compiled into objects # :INTERFACE: no direct build output, but can be used to aggregate headers, # compilation flags and libraries # # SOURCES_GLOB : optional # search pattern to find source files to compile (note: not recommend according to CMake guidelines) # it is usually better to explicitly list the source files in the CMakeList.txt # # SOURCES_EXCLUDE_REGEX : optional # search pattern to exclude source files from compilation, applies o the results of SOURCES_GLOB # # OBJECTS : optional # list of object libraries to add to this target # # TEMPLATES : optional # list of files specified as SOURCES which are not to be compiled separately # (these are commonly template implementation files included in a header) # # LIBS : (DEPRECATED) optional # list of libraries to link against (CMake targets or external libraries), # behaves as PUBLIC_LIBS # Please use PRIVATE_LIBS or PUBLIC_LIBS or CMake command ``target_link_libraries`` instead # # PRIVATE_LIBS : optional # list of libraries to link against (CMake targets or external libraries), # they will not be exported # # PUBLIC_LIBS : optional # list of libraries to link against (CMake targets or external libraries), # they will be exported # # INCLUDES : (DEPRECATED) optional # list of paths to add to include directories, behaves as PUBLIC_INCLUDES # Please use PUBLIC_INCLUDES or PRIVATE_INCLUDES or CMake command ``target_include_directories`` instead # # PUBLIC_INCLUDES : optional # list of paths to add to include directories which will be publicly exported to other targets and projects # # PRIVATE_INCLUDES : optional # list of paths to add to include directories which won't be exported beyond this target # # DEFINITIONS : (DEPRECATED) optional # list of definitions to add to preprocessor defines # behaves as PRIVATE_DEFINITIONS # Please use PRIVATE_DEFINITIONS or PUBLIC_DEFINITIONS or CMake command ``target_compile_definitions`` instead # # PRIVATE_DEFINITIONS : optional # list of definitions to add to preprocessor defines that will not be exported beyond this target # # PUBLIC_DEFINITIONS : optional # list of definitions to add to preprocessor defines that will be publicly exported to other targets and projects # # PERSISTENT : optional # list of persistent layer object files # # GENERATED : optional # list of files to mark as generated (sets GENERATED source file property) # # DEPENDS : optional # list of targets to be built before this target # # CONDITION : optional # conditional expression which must evaluate to true for this target to be # built (must be valid in a CMake ``if`` statement) # # PROPERTIES : optional # custom properties to set on the target # # NOINSTALL : optional # do not install the library # # HEADER_DESTINATION # directory to install headers (if not specified, INSTALL_INCLUDE_DIR is used) # Note: this directory will automatically be added to target_include_directories # # INSTALL_HEADERS : optional # specify which header files to install: # # :LISTED: install header files listed as SOURCES # :ALL: install all header files ending in .h, .hh, .hpp, .H # # INSTALL_HEADERS_LIST : optional # list of extra headers to install # # INSTALL_HEADERS_REGEX : optional # regular expression to match extra headers to install # # VERSION : optional, AUTO_VERSION or LIBS_VERSION is used if not specified # build version of the library # # AUTO_VERSION : optional, ignored if VERSION is specified # use MAJOR.MINOR package version as build version of the library # # SOVERSION : optional, AUTO_SOVERSION or LIBS_SOVERSION is used if not specified # ABI version of the library # # AUTO_SOVERSION : optional, ignored if SOVERSION is specified # use MAJOR package version as ABI version of the library # # CFLAGS : optional # list of C compiler flags to use for all C source files # # See usage note below. # # CXXFLAGS : optional # list of C++ compiler flags to use for all C++ source files # # See usage note below. # # FFLAGS : optional # list of Fortran compiler flags to use for all Fortran source files # # See usage note below. # # LINKER_LANGUAGE : optional # sets the LINKER_LANGUAGE property on the target # # OUTPUT_NAME : optional # sets the OUTPUT_NAME property on the target # # Usage # ----- # # The ``CFLAGS``, ``CXXFLAGS`` and ``FFLAGS`` options apply the given compiler # flags to all C, C++ and Fortran sources passed to this command, respectively. # If any two ``ecbuild_add_executable``, ``ecbuild_add_library`` or # ``ecbuild_add_test`` commands are passed the *same* source file and each sets # a different value for the compiler flags to be applied to that file (including # when one command adds flags and another adds none), then the two commands # will be in conflict and the result may not be as expected. # # For this reason it is recommended not to use the ``*FLAGS`` options when # multiple targets share the same source files, unless the exact same flags are # applied to those sources by each relevant command. # # Care should also be taken to ensure that these commands are not passed source # files which are not required to build the target, if those sources are also # passed to other commands which set different compiler flags. # ############################################################################## function( ecbuild_add_library_impl ) set( options NOINSTALL AUTO_VERSION AUTO_SOVERSION ) set( single_value_args TARGET TYPE COMPONENT INSTALL_HEADERS INSTALL_HEADERS_REGEX LINKER_LANGUAGE HEADER_DESTINATION VERSION SOVERSION OUTPUT_NAME ) set( multi_value_args SOURCES SOURCES_GLOB SOURCES_EXCLUDE_REGEX OBJECTS TEMPLATES LIBS PRIVATE_LIBS PUBLIC_LIBS INCLUDES PRIVATE_INCLUDES PUBLIC_INCLUDES DEPENDS PERSISTENT DEFINITIONS PRIVATE_DEFINITIONS PUBLIC_DEFINITIONS INSTALL_HEADERS_LIST CFLAGS CXXFLAGS FFLAGS GENERATED CONDITION PROPERTIES ) cmake_parse_arguments( _PAR "${options}" "${single_value_args}" "${multi_value_args}" ${_FIRST_ARG} ${ARGN} ) if(_PAR_UNPARSED_ARGUMENTS) ecbuild_critical("Unknown keywords given to ecbuild_add_library(): \"${_PAR_UNPARSED_ARGUMENTS}\"") endif() if( NOT _PAR_TARGET ) ecbuild_critical("The call to ecbuild_add_library() doesn't specify the TARGET.") endif() ### optional override for target type if( NOT DEFINED _PAR_TYPE AND DEFINED ECBUILD_TARGET_${_PAR_TARGET}_TYPE ) set( _PAR_TYPE ${ECBUILD_TARGET_${_PAR_TARGET}_TYPE} ) ecbuild_debug( "ecbuild_add_libary(${_PAR_TARGET}): library type overriden to ${_PAR_TYPE}" ) endif() if( NOT _PAR_TYPE MATCHES "INTERFACE" ) if( NOT _PAR_SOURCES AND NOT _PAR_OBJECTS AND NOT _PAR_SOURCES_GLOB ) ecbuild_critical("The call to ecbuild_add_library() specifies neither SOURCES nor OBJECTS nor SOURCES_GLOB") endif() endif() ### conditional build ecbuild_evaluate_dynamic_condition( _PAR_CONDITION _${_PAR_TARGET}_condition ) if( _${_PAR_TARGET}_condition ) # defines the type of library if( DEFINED _PAR_TYPE ) # checks that is either SHARED or STATIC or MODULE if( NOT _PAR_TYPE MATCHES "STATIC" AND NOT _PAR_TYPE MATCHES "SHARED" AND NOT _PAR_TYPE MATCHES "OBJECT" AND NOT _PAR_TYPE MATCHES "MODULE" AND NOT _PAR_TYPE MATCHES "INTERFACE" ) ecbuild_critical( "library type must be one of [ STATIC | SHARED | MODULE | OBJECT | INTERFACE ]" ) endif() ecbuild_debug("ecbuild_add_library(${_PAR_TARGET}): library type is ${_PAR_TYPE}") endif() # insert already compiled objects (from OBJECT libraries) unset( _all_objects ) foreach( _obj ${_PAR_OBJECTS} ) list( APPEND _all_objects $ ) endforeach() # glob sources unset( _glob_srcs ) foreach( pattern ${_PAR_SOURCES_GLOB} ) ecbuild_list_add_pattern( LIST _glob_srcs GLOB "${pattern}" ) endforeach() foreach( pattern ${_PAR_SOURCES_EXCLUDE_REGEX} ) ecbuild_list_exclude_pattern( LIST _glob_srcs REGEX "${pattern}" ) endforeach() list( APPEND _PAR_SOURCES ${_glob_srcs} ) if( ECBUILD_LIST_SOURCES ) ecbuild_debug("ecbuild_add_library(${_PAR_TARGET}): sources ${_PAR_SOURCES}") endif() # add persistent layer files ecbuild_add_persistent( SRC_LIST _PAR_SOURCES FILES ${_PAR_PERSISTENT} NAMESPACE "${PERSISTENT_NAMESPACE}" ) # remove templates from compilation sources if( DEFINED _PAR_TEMPLATES ) ecbuild_debug("ecbuild_add_library(${_PAR_TARGET}): removing ${_PAR_TEMPLATES} from sources") list( REMOVE_ITEM _PAR_SOURCES ${_PAR_TEMPLATES} ) add_custom_target( ${_PAR_TARGET}_templates SOURCES ${_PAR_TEMPLATES} ) endif() # Separate sources if( _PAR_SOURCES ) ecbuild_separate_sources( TARGET ${_PAR_TARGET} SOURCES ${_PAR_SOURCES} ) endif() # Purge the sources list for interface libraries (now that they have been filtered) if( _PAR_TYPE MATCHES "INTERFACE" ) set( _PAR_SOURCES "" ) endif() if( ${_PAR_TARGET}_cuda_srcs AND CUDA_FOUND ) if( NOT DEFINED CUDA_LINK_LIBRARIES_KEYWORD ) set ( CUDA_LINK_LIBRARIES_KEYWORD PRIVATE ) endif() cuda_add_library( ${_PAR_TARGET} ${_PAR_TYPE} ${_PAR_SOURCES} ${_all_objects} ) else() add_library( ${_PAR_TARGET} ${_PAR_TYPE} ${_PAR_SOURCES} ${_all_objects} ) endif() # ecbuild_echo_target( ${_PAR_TARGET} ) # Set custom properties if( ${_PAR_PROPERTIES} ) set_target_properties( ${_PAR_TARGET} PROPERTIES ${_PAR_PROPERTIES} ) endif() # set OUTPUT_NAME if( DEFINED _PAR_OUTPUT_NAME ) ecbuild_debug("ecbuild_add_library(${_PAR_TARGET}): set OUTPUT_NAME to ${_PAR_OUTPUT_NAME}") set_target_properties( ${_PAR_TARGET} PROPERTIES OUTPUT_NAME ${_PAR_OUTPUT_NAME} ) endif() # add extra dependencies if( DEFINED _PAR_DEPENDS) ecbuild_debug("ecbuild_add_library(${_PAR_TARGET}): add dependency on ${_PAR_DEPENDS}") add_dependencies( ${_PAR_TARGET} ${_PAR_DEPENDS} ) endif() # For interface libraries, there is no build requirement, therefore only # the INTERFACE properties should be populated set( _PUBLIC_INTF "PUBLIC" ) if( _PAR_TYPE MATCHES "INTERFACE" ) set( _PUBLIC_INTF "INTERFACE" ) endif() # takes a list of possible includes LIST and a INTF parameter function(__addDeps) set( options ) set( single_value_args TYPE INTF ) set( multi_value_args LIST ) cmake_parse_arguments( _p "${options}" "${single_value_args}" "${multi_value_args}" ${ARGN} ) if( "${_p_TYPE}" STREQUAL LIBS ) list(REMOVE_ITEM _p_LIST debug) list(REMOVE_ITEM _p_LIST optimized) endif() ecbuild_filter_list(${_p_TYPE} LIST ${_p_LIST} LIST_INCLUDE deps LIST_EXCLUDE skipped_deps) if( "${_p_INTF}" STREQUAL "LEGACY" ) if(ECBUILD_2_COMPAT_DEPRECATE) ecbuild_deprecate("ecbuild_add_library(${_PAR_TARGET}): the usage of ${_p_TYPE} is deprecated. Use PUBLIC_${_p_TYPE} or PRIVATE_${_p_TYPE}.") endif() set(_p_INTF ${_PUBLIC_INTF}) endif() if( "${_p_TYPE}" STREQUAL LIBS ) target_link_libraries( ${_PAR_TARGET} ${_p_INTF} ${deps} ) ecbuild_debug("ecbuild_add_library(${_PAR_TARGET}): linking with [${deps}] ${_p_INTF}") if( skipped_deps ) ecbuild_debug("ecbuild_add_library(${_PAR_TARGET}): [${skipped_deps}] not found - not linking ${_p_INTF}") endif() else() target_include_directories( ${_PAR_TARGET} ${_p_INTF} ${deps} ) ecbuild_debug("ecbuild_add_library(${_PAR_TARGET}): add [${deps}] to include_directories ${_p_INTF}") if( skipped_deps ) ecbuild_debug("ecbuild_add_library(${_PAR_TARGET}): [${skipped_deps}] not found - not adding to include_directories ${_p_INTF}") endif() endif() endfunction() # add the link libraries if( DEFINED _PAR_LIBS ) __addDeps(TYPE LIBS LIST ${_PAR_LIBS} INTF LEGACY) endif() # add the private link libraries if( DEFINED _PAR_PRIVATE_LIBS ) __addDeps(TYPE LIBS LIST ${_PAR_PRIVATE_LIBS} INTF PRIVATE) endif() # add the public link libraries if( DEFINED _PAR_PUBLIC_LIBS ) __addDeps(TYPE LIBS LIST ${_PAR_PUBLIC_LIBS} INTF ${_PUBLIC_INTF}) endif() # add include dirs if defined if( DEFINED _PAR_INCLUDES ) __addDeps(TYPE INCLUDES LIST ${_PAR_INCLUDES} INTF LEGACY) endif() # add private include dirs if defined if( DEFINED _PAR_PRIVATE_INCLUDES ) __addDeps(TYPE INCLUDES LIST ${_PAR_PRIVATE_INCLUDES} INTF PRIVATE) endif() # add public include dirs if defined if( DEFINED _PAR_PUBLIC_INCLUDES ) __addDeps(TYPE INCLUDES LIST ${_PAR_PUBLIC_INCLUDES} INTF ${_PUBLIC_INTF}) endif() # FIX: Cray compiler PIC option is not detected by CMake if( NOT _PAR_TYPE MATCHES "INTERFACE" ) get_property( _target_pic TARGET ${_PAR_TARGET} PROPERTY POSITION_INDEPENDENT_CODE ) if( _target_pic ) if( "${CMAKE_C_COMPILER_ID}" STREQUAL "Cray" ) set( _PAR_CFLAGS "-fPIC -h PIC ${_PAR_CFLAGS}" ) endif() if( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Cray" ) set( _PAR_CXXFLAGS "-fPIC -h PIC ${_PAR_CXXFLAGS}" ) endif() if( "${CMAKE_Fortran_COMPILER_ID}" STREQUAL "Cray" ) set( _PAR_FFLAGS "-fPIC -h PIC ${_PAR_FFLAGS}" ) endif() endif() endif() # define VERSION if requested if( DEFINED _PAR_VERSION ) ecbuild_debug("ecbuild_add_library(${_PAR_TARGET}): set build version to ${_PAR_VERSION}") set_target_properties( ${_PAR_TARGET} PROPERTIES VERSION "${_PAR_VERSION}" ) else() if( _PAR_AUTO_VERSION OR LIBS_VERSION MATCHES "[Aa][Uu][Tt][Oo]") ecbuild_debug("ecbuild_add_library(${_PAR_TARGET}): set build version to ${${PROJECT_NAME}_VERSION_MAJOR}.${${PROJECT_NAME}_VERSION_MINOR} (auto)") set_target_properties( ${_PAR_TARGET} PROPERTIES VERSION "${${PROJECT_NAME}_VERSION_MAJOR}.${${PROJECT_NAME}_VERSION_MINOR}" ) elseif( DEFINED LIBS_VERSION ) ecbuild_debug("ecbuild_add_library(${_PAR_TARGET}): set build version to ${LIBS_VERSION}") set_target_properties( ${_PAR_TARGET} PROPERTIES VERSION "${LIBS_VERSION}" ) endif() endif() # define SOVERSION if requested if( DEFINED _PAR_SOVERSION ) ecbuild_debug("ecbuild_add_library(${_PAR_TARGET}): set ABI version to ${_PAR_SOVERSION}") set_target_properties( ${_PAR_TARGET} PROPERTIES SOVERSION "${_PAR_SOVERSION}" ) else() if( _PAR_AUTO_SOVERSION OR LIBS_SOVERSION MATCHES "[Aa][Uu][Tt][Oo]") ecbuild_debug("ecbuild_add_library(${_PAR_TARGET}): set ABI version to ${${PROJECT_NAME}_VERSION_MAJOR} (auto)") set_target_properties( ${_PAR_TARGET} PROPERTIES SOVERSION "${${PROJECT_NAME}_MAJOR_VERSION}" ) elseif( DEFINED LIBS_SOVERSION ) ecbuild_debug("ecbuild_add_library(${_PAR_TARGET}): set ABI version to ${LIBS_SOVERSION}") set_target_properties( ${_PAR_TARGET} PROPERTIES SOVERSION "${LIBS_SOVERSION}" ) endif() endif() # Override compilation flags on a per source file basis ecbuild_target_flags( ${_PAR_TARGET} "${_PAR_CFLAGS}" "${_PAR_CXXFLAGS}" "${_PAR_FFLAGS}" ) if( DEFINED _PAR_GENERATED ) ecbuild_debug("ecbuild_add_library(${_PAR_TARGET}): mark as generated ${_PAR_GENERATED}") set_source_files_properties( ${_PAR_GENERATED} PROPERTIES GENERATED 1 ) endif() # set linker language if( DEFINED _PAR_LINKER_LANGUAGE ) ecbuild_debug("ecbuild_add_library(${_PAR_TARGET}): using linker language ${_PAR_LINKER_LANGUAGE}") set_target_properties( ${_PAR_TARGET} PROPERTIES LINKER_LANGUAGE ${_PAR_LINKER_LANGUAGE} ) if( ECBUILD_${_PAR_LINKER_LANGUAGE}_IMPLICIT_LINK_LIBRARIES ) target_link_libraries( ${_PAR_TARGET} PRIVATE ${ECBUILD_${_PAR_LINKER_LANGUAGE}_IMPLICIT_LINK_LIBRARIES} ) endif() endif() if( NOT _PAR_TYPE MATCHES "OBJECT" AND NOT _PAR_TYPE MATCHES "INTERFACE" AND ECBUILD_IMPLICIT_LINK_LIBRARIES ) target_link_libraries( ${_PAR_TARGET} PRIVATE ${ECBUILD_IMPLICIT_LINK_LIBRARIES} ) endif() # Publish the relevant include directories for the headers if(ECBUILD_2_COMPAT) target_include_directories( ${_PAR_TARGET} ${_PUBLIC_INTF} $ ) get_property(_incdirs DIRECTORY PROPERTY INCLUDE_DIRECTORIES) string( TOUPPER "${PROJECT_NAME}" PNAME ) if( ${PNAME}_INCLUDE_DIRS ) foreach( incdir ${${PNAME}_INCLUDE_DIRS} ) list( APPEND _incdirs ${incdir} ) endforeach() endif() list( REMOVE_DUPLICATES _incdirs ) foreach(incdir ${_incdirs}) if(NOT incdir MATCHES "^\\$<") file(RELATIVE_PATH _rel_inc ${PROJECT_SOURCE_DIR} "${incdir}") if(NOT _rel_inc MATCHES "^\\.\\./") target_include_directories( ${_PAR_TARGET} ${_PUBLIC_INTF} $ ) endif() file(RELATIVE_PATH _rel_inc ${PROJECT_BINARY_DIR} "${incdir}") if(NOT _rel_inc MATCHES "^\\.\\./") target_include_directories( ${_PAR_TARGET} ${_PUBLIC_INTF} $ ) endif() endif() endforeach() endif() # installation (except for OBJECT libraries) if( NOT _PAR_NOINSTALL AND NOT _PAR_TYPE MATCHES "OBJECT" ) ecbuild_debug("ecbuild_add_library(${_PAR_TARGET}): installing to ${INSTALL_LIB_DIR}") # and associate with defined component # if( DEFINED _PAR_COMPONENT ) # set( COMPONENT_DIRECTIVE "${_PAR_COMPONENT}" ) # else() # set( COMPONENT_DIRECTIVE "${PROJECT_NAME}" ) # endif() install( TARGETS ${_PAR_TARGET} EXPORT ${PROJECT_NAME}-targets RUNTIME DESTINATION ${INSTALL_BIN_DIR} LIBRARY DESTINATION ${INSTALL_LIB_DIR} ARCHIVE DESTINATION ${INSTALL_LIB_DIR} ) # COMPONENT ${COMPONENT_DIRECTIVE} ) if(ECBUILD_INSTALL_LIBRARY_HEADERS) if( _PAR_HEADER_DESTINATION ) set( _h_destination "${_PAR_HEADER_DESTINATION}" ) else() set( _h_destination "${INSTALL_INCLUDE_DIR}" ) endif() if( _PAR_INSTALL_HEADERS ) if( _PAR_INSTALL_HEADERS MATCHES "LISTED" ) foreach( file ${${_PAR_TARGET}_h_srcs} ) get_filename_component( _file_dir ${file} PATH ) install( FILES ${file} DESTINATION "${_h_destination}/${_file_dir}" ) endforeach() if( DEFINED _PAR_TEMPLATES ) foreach( file ${_PAR_TEMPLATES} ) get_filename_component( _file_dir ${file} PATH ) install( FILES ${file} DESTINATION "${_h_destination}/${_file_dir}" ) endforeach() endif() if( DEFINED _PAR_PERSISTENT ) foreach( file ${_PAR_PERSISTENT} ) get_filename_component( _file_dir ${file} PATH ) get_filename_component( _file_we ${file} NAME_WE ) set( pfile "${CMAKE_CURRENT_BINARY_DIR}/${_file_dir}/${_file_we}.b" ) install( FILES ${pfile} DESTINATION "${_h_destination}/${_file_dir}" ) endforeach() endif() endif() if( _PAR_INSTALL_HEADERS MATCHES "ALL" ) install( DIRECTORY ./ DESTINATION ${_h_destination} FILES_MATCHING PATTERN "*.h" ) install( DIRECTORY ./ DESTINATION ${_h_destination} FILES_MATCHING PATTERN "*.hh" ) install( DIRECTORY ./ DESTINATION ${_h_destination} FILES_MATCHING PATTERN "*.hpp" ) install( DIRECTORY ./ DESTINATION ${_h_destination} FILES_MATCHING PATTERN "*.H" ) install( DIRECTORY ./ DESTINATION ${_h_destination} FILES_MATCHING PATTERN "*.tcc" ) install( DIRECTORY ./ DESTINATION ${_h_destination} FILES_MATCHING PATTERN "*.txx" ) install( DIRECTORY ./ DESTINATION ${_h_destination} FILES_MATCHING PATTERN "*.tcc" ) endif() endif() if( DEFINED _PAR_INSTALL_HEADERS_LIST ) install( FILES ${_PAR_INSTALL_HEADERS_LIST} DESTINATION ${_h_destination} ) endif() if( DEFINED _PAR_INSTALL_HEADERS_REGEX ) install( DIRECTORY ./ DESTINATION ${_h_destination} FILES_MATCHING PATTERN "${_PAR_INSTALL_HEADERS_REGEX}") endif() target_include_directories(${_PAR_TARGET} ${_PUBLIC_INTF} $) if( _PAR_HEADER_DESTINATION ) target_include_directories(${_PAR_TARGET} ${_PUBLIC_INTF} $ ) endif() endif() # set build location if( NOT _PAR_TYPE MATCHES "INTERFACE" ) set_target_properties( ${_PAR_TARGET} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib ) set_target_properties( ${_PAR_TARGET} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib ) if( EC_OS_NAME MATCHES "windows" ) set_target_properties( ${_PAR_TARGET} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin ) endif() endif() # export location of target to other projects -- must be exactly after setting the build location (see previous 3 commands) export( TARGETS ${_PAR_TARGET} APPEND FILE "${PROJECT_TARGETS_FILE}" ) endif() # add definitions to compilation if( DEFINED _PAR_PUBLIC_DEFINITIONS ) target_compile_definitions(${_PAR_TARGET} ${_PUBLIC_INTF} ${_PAR_PUBLIC_DEFINITIONS}) ecbuild_debug("ecbuild_add_library(${_PAR_TARGET}): adding ${_PUBLIC_INTF} definitions ${_PAR_PUBLIC_DEFINITIONS}") endif() if( DEFINED _PAR_PRIVATE_DEFINITIONS ) target_compile_definitions(${_PAR_TARGET} PRIVATE ${_PAR_PRIVATE_DEFINITIONS}) ecbuild_debug("ecbuild_add_library(${_PAR_TARGET}): adding PRIVATE definitions ${_PAR_PRIVATE_DEFINITIONS}") endif() if( DEFINED _PAR_DEFINITIONS ) if( _PAR_TYPE MATCHES "INTERFACE" ) target_compile_definitions(${_PAR_TARGET} INTERFACE ${_PAR_DEFINITIONS}) else() target_compile_definitions(${_PAR_TARGET} PRIVATE ${_PAR_DEFINITIONS}) endif() ecbuild_debug("ecbuild_add_library(${_PAR_TARGET}): adding definitions ${_PAR_DEFINITIONS}") endif() # make sure target is removed before - some problems with AIX if( NOT _PAR_TYPE MATCHES "OBJECT" AND NOT _PAR_TYPE MATCHES "INTERFACE" ) add_custom_command( TARGET ${_PAR_TARGET} PRE_BUILD COMMAND ${CMAKE_COMMAND} -E remove $ ) endif() # append to the list of this project targets if( NOT ECBUILD_2_COMPAT OR NOT _PAR_TYPE MATCHES "INTERFACE" ) set( ${PROJECT_NAME}_ALL_LIBS ${${PROJECT_NAME}_ALL_LIBS} ${_PAR_TARGET} CACHE INTERNAL "" ) endif() endif() # mark source files as used ecbuild_declare_project_files( ${_PAR_SOURCES} ) if( DEFINED _PAR_TEMPLATES ) ecbuild_declare_project_files( ${_PAR_TEMPLATES} ) endif() endfunction( ecbuild_add_library_impl ) ############################################################################## # auxiliary macro for adding a library ############################################################################## function( ecbuild_add_library ) set( options ) set( single_value_args TARGET TYPE ) set( multi_value_args ) cmake_parse_arguments( _p "${options}" "${single_value_args}" "${multi_value_args}" ${_FIRST_ARG} ${ARGN} ) if( DEFINED _p_TYPE ) # don't do anything if TYPE was specified if( _p_TYPE MATCHES "[Bb][Oo][Tt][Hh]" ) # build both types ecbuild_add_library_impl( TARGET ${_p_TARGET} TYPE SHARED ${_p_UNPARSED_ARGUMENTS} ) ecbuild_add_library_impl( TARGET ${_p_TARGET}-static TYPE STATIC ${_p_UNPARSED_ARGUMENTS} OUTPUT_NAME ${_p_TARGET} DEPENDS ${_p_TARGET} ) else() ecbuild_add_library_impl( ${ARGV} ) endif() else() if( NOT DEFINED _p_TARGET ) ecbuild_critical("The call to ecbuild_add_library() doesn't specify the TARGET.") else() if( BUILD_SHARED_LIBS MATCHES "[Bb][Oo][Tt][Hh]" ) # build both types ecbuild_add_library_impl( TARGET ${_p_TARGET} TYPE SHARED ${_p_UNPARSED_ARGUMENTS} ) ecbuild_add_library_impl( TARGET ${_p_TARGET}-static TYPE STATIC ${_p_UNPARSED_ARGUMENTS} DEPENDS ${_p_TARGET} ) # If the library is built conditionally the target might not exist if ( TARGET ${_p_TARGET}-static ) set_target_properties( ${_p_TARGET}-static PROPERTIES OUTPUT_NAME ${_p_TARGET} ) endif() else() ecbuild_add_library_impl( ${ARGV} ) endif() endif() endif() endfunction() ecbuild-3.13.1/cmake/ecbuild_add_option.cmake000066400000000000000000000364341513706760700211250ustar00rootroot00000000000000# (C) Copyright 2011- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation nor # does it submit to any jurisdiction. ############################################################################## #.rst: # # ecbuild_add_option # ================== # # Add a CMake configuration option, which may depend on a list of packages. :: # # ecbuild_add_option( FEATURE # [ DEFAULT ON|OFF ] # [ DESCRIPTION ] # [ REQUIRED_PACKAGES [ ...] ] # [ CONDITION ] # [ ADVANCED ] [ NO_TPL ] ) # # Options # ------- # # FEATURE : required # name of the feature / option # # DEFAULT : optional, defaults to ON # if set to ON, the feature is enabled even if not explicitly requested # # DESCRIPTION : optional # string describing the feature (shown in summary and stored in the cache) # # REQUIRED_PACKAGES : optional # list of packages required to be found for this feature to be enabled # # Every item in the list should be a valid argument list for # ``ecbuild_find_package``, e.g.:: # # "NAME [VERSION ] [...]" # # .. note:: # # Arguments inside the package string that require quoting need to use the # `bracket argument syntax`_ introduced in CMake 3.0 since # regular quotes even when escaped are swallowed by the CMake parser. # # Alternatively, the name of a CMake variable containing the string can be # passed, which will be expanded by ``ecbuild_find_package``: :: # # set( ECCODES_FAIL_MSG # "grib_api can be used instead (select with -DENABLE_ECCODES=OFF)" ) # ecbuild_add_option( FEATURE ECCODES # DESCRIPTION "Use eccodes instead of grib_api" # REQUIRED_PACKAGES "NAME eccodes REQUIRED FAILURE_MSG ECCODES_FAIL_MSG" # DEFAULT ON ) # # CONDITION : optional # conditional expression which must evaluate to true for this option to be # enabled (must be valid in a CMake ``if`` statement) # # ADVANCED : optional # mark the feature as advanced # # NO_TPL : optional # do not add any ``REQUIRED_PACKAGES`` to the list of third party libraries # # Usage # ----- # # Features with ``DEFAULT OFF`` need to be explcitly enabled by the user with # ``-DENABLE_=ON``. If a feature is enabled, all ``REQUIRED_PACKAGES`` # are found and ``CONDITION`` is met, ecBuild sets the variable # ``HAVE_`` to ``ON``. This is the variable to use to check for the # availability of the feature. # # If a feature is explicitly enabled but the required packages are not found, # configuration fails. This only applies when configuring from *clean cache*. # With an already populated cache, use ``-DENABLE_=REQUIRE`` to make # the feature a required feature (this cannot be done via the CMake GUI). # # .. _bracket argument syntax: https://cmake.org/cmake/help/latest/manual/cmake-language.7.html#bracket-argument # ############################################################################## macro( ecbuild_add_option ) set( options ADVANCED NO_TPL ) set( single_value_args FEATURE DEFAULT DESCRIPTION TYPE PURPOSE ) set( multi_value_args REQUIRED_PACKAGES CONDITION ) cmake_parse_arguments( _p "${options}" "${single_value_args}" "${multi_value_args}" ${_FIRST_ARG} ${ARGN} ) # # Policy CMP0077 set to NEW, to avoid warning and allow disregarding # the cache variable ENABLE_ if it is not set by the user # cmake_policy(SET CMP0077 NEW) if( _p_UNPARSED_ARGUMENTS ) ecbuild_critical("Unknown keywords given to ecbuild_add_option(): \"${_p_UNPARSED_ARGUMENTS}\"") endif() # check FEATURE parameter if( NOT _p_FEATURE ) ecbuild_critical("The call to ecbuild_add_option() doesn't specify the FEATURE.") endif() # check DEFAULT parameter if( NOT DEFINED _p_DEFAULT ) set( _p_DEFAULT ON ) else() if( NOT _p_DEFAULT MATCHES "[Oo][Nn]" AND NOT _p_DEFAULT MATCHES "[Oo][Ff][Ff]" ) ecbuild_critical("In macro ecbuild_add_option(), DEFAULT must be either ON or OFF, but found: \"${_p_DEFAULT}\"") endif() endif() ecbuild_debug("ecbuild_add_option(${_p_FEATURE}): defaults to ${_p_DEFAULT}") if( _p_PURPOSE ) ecbuild_deprecate( "ecbuild_add_option: argument PURPOSE is ignored and will be removed in a future release." ) endif() if( _p_TYPE ) ecbuild_deprecate( "ecbuild_add_option: argument TYPE is ignored and will be removed in a future release." ) endif() # check CONDITION parameter ecbuild_evaluate_dynamic_condition( _p_CONDITION _${_p_FEATURE}_condition ) # Disable deprecation warnings until end of macro, because "ENABLE_" may already have been # marked with "ecbuild_mark_compat()" in a bundle. if( ECBUILD_2_COMPAT ) set( DISABLE_ECBUILD_DEPRECATION_WARNINGS_orig ${DISABLE_ECBUILD_DEPRECATION_WARNINGS} ) set( DISABLE_ECBUILD_DEPRECATION_WARNINGS ON ) endif() # Check if user explicitly enabled/disabled the feature in cache get_property( _in_cache CACHE ENABLE_${_p_FEATURE} PROPERTY VALUE SET ) # ***Important*** # # In order to support options in multi-project scenarios, and allow the user to # reconfigure the project with a different set of options, we need to precompute # and store the value of the user provided option. # # This is done by creating a new variable _ENABLE__defined_value. # This variable is used to store the value of ENABLE_ when the user provides it. # This is done to avoid overwriting the cache value of ENABLE_ when the user # provides a different value for the same option in a different project. # if ( NOT DEFINED ${PROJECT_NAME}_ENABLE_${_p_FEATURE}_defined_value ) if ( DEFINED ENABLE_${_p_FEATURE} ) # When the user provides a value for ENABLE_, we cache it # in a new variable _ENABLE__defined_value set ( ${PROJECT_NAME}_ENABLE_${_p_FEATURE}_defined_value ${ENABLE_${_p_FEATURE}} CACHE INTERNAL "" FORCE ) else() # When the user does not provide a value for ENABLE_, # we set the default value of ENABLE_ to the default value # of the feature. set ( ${PROJECT_NAME}_ENABLE_${_p_FEATURE}_defined_value ${_p_DEFAULT} CACHE INTERNAL "" FORCE ) endif() else() if ( DEFINED ENABLE_${_p_FEATURE} ) # When the user provides a value for ENABLE_, we cache it # in a new variable _ENABLE__defined_value. set ( ${PROJECT_NAME}_ENABLE_${_p_FEATURE}_defined_value ${ENABLE_${_p_FEATURE}} CACHE INTERNAL "" FORCE ) endif() endif() # The project/user-provided specific of the feature value is used to set the value of # ENABLE_ in the current project. set ( ENABLE_${_p_FEATURE} ${${PROJECT_NAME}_ENABLE_${_p_FEATURE}_defined_value} ) if( ENABLE_${_p_FEATURE} MATCHES "REQUIRE" ) # # User explicitly marked the feature as REQUIREd # ecbuild_debug("ecbuild_add_option(${_p_FEATURE}): ENABLE_${_p_FEATURE} was required") set( ENABLE_${_p_FEATURE} ON CACHE BOOL "" FORCE ) set( ${_p_FEATURE}_user_provided_input 1 CACHE INTERNAL "" FORCE ) elseif( NOT ENABLE_${_p_FEATURE} STREQUAL "" AND _in_cache ) # # User explicitly defined the value of the feature # The user can set feature to either ON or OFF; and this is cached so it doesn't revert back to the default # ecbuild_debug("ecbuild_add_option(${_p_FEATURE}): ENABLE_${_p_FEATURE} was found in cache, updating to ENABLE_${_p_FEATURE}=${ENABLE_${_p_FEATURE}}") set( ENABLE_${_p_FEATURE} ${ENABLE_${_p_FEATURE}} CACHE BOOL "" FORCE ) set( ${_p_FEATURE}_user_provided_input 1 CACHE INTERNAL "" FORCE ) else() # # No user explicit value provided; the default value is used # ecbuild_debug("ecbuild_add_option(${_p_FEATURE}): ENABLE_${_p_FEATURE} not found in cache") set( ${_p_FEATURE}_user_provided_input 0 CACHE INTERNAL "" ) endif() # define the option -- for cmake GUI option( ENABLE_${_p_FEATURE} "${_p_DESCRIPTION}" ${ENABLE_${_p_FEATURE}} ) ecbuild_debug("ecbuild_add_option(${_p_FEATURE}): defining option ENABLE_${_p_FEATURE} '${_p_DESCRIPTION}' ${_p_DEFAULT}") ecbuild_debug("ecbuild_add_option(${_p_FEATURE}): ENABLE_${_p_FEATURE}=${ENABLE_${_p_FEATURE}}") # Allow override of ENABLE_ with _ENABLE_ (see ECBUILD-486) if( DEFINED ${PNAME}_ENABLE_${_p_FEATURE} ) ecbuild_debug("ecbuild_add_option(${_p_FEATURE}): found ${PNAME}_ENABLE_${_p_FEATURE}=${${PNAME}_ENABLE_${_p_FEATURE}}") # Cache it for future reconfiguration set( ${PNAME}_ENABLE_${_p_FEATURE} ${${PNAME}_ENABLE_${_p_FEATURE}} CACHE BOOL "Override for ENABLE_${_p_FEATURE}" ) # Warn when user provides both ENABLE_ and _ENABLE_, and explain precedence if( ${_p_FEATURE}_user_provided_input ) ecbuild_warn( "Both ENABLE_${_p_FEATURE} and ${PNAME}_ENABLE_${_p_FEATURE} are set for feature ${_p_FEATURE}." "Using ${PNAME}_ENABLE_${_p_FEATURE}=${${PNAME}_ENABLE_${_p_FEATURE}}" ) endif() # Non-cache (hard) override of ENABLE_ within this project scope only set( ENABLE_${_p_FEATURE} ${${PNAME}_ENABLE_${_p_FEATURE}} ) ecbuild_debug("ecbuild_add_option(${_p_FEATURE}): set ENABLE_${_p_FEATURE} from ${PNAME}_ENABLE_${_p_FEATURE}") ecbuild_debug("ecbuild_add_option(${_p_FEATURE}): ENABLE_${_p_FEATURE}=${ENABLE_${_p_FEATURE}}") endif() ## Update the description of the feature summary # Choose the correct tick if (ENABLE_${_p_FEATURE}) set ( _tick "ON") else() set ( _tick "OFF") endif() set(_enabled "${ENABLE_${_p_FEATURE}}") get_property( _enabled_features GLOBAL PROPERTY ENABLED_FEATURES ) if( "${_p_FEATURE}" IN_LIST _enabled_features ) set(_enabled ON) endif() set( ${PROJECT_NAME}_HAVE_${_p_FEATURE} 0 ) if( ENABLE_${_p_FEATURE} ) ecbuild_debug("ecbuild_add_option(${_p_FEATURE}): feature requested to be enabled") set( ${PROJECT_NAME}_HAVE_${_p_FEATURE} 1 ) if( _${_p_FEATURE}_condition ) ### search for dependent packages set( _failed_to_find_packages ) # clear variable foreach( pkg ${_p_REQUIRED_PACKAGES} ) ecbuild_debug("ecbuild_add_option(${_p_FEATURE}): searching for dependent package ${pkg}") string(REPLACE " " ";" pkglist ${pkg}) # string to list list(GET pkglist 0 pkgfirst) if( ECBUILD_2_COMPAT ) if( pkgfirst STREQUAL "PROJECT" ) if( ECBUILD_2_COMPAT_DEPRECATE ) ecbuild_deprecate("Arguments to ecbuild_add_option(REQUIRED_PACKAGES) " "should be valid arguments for ecbuild_find_package") endif() list(GET pkglist 1 pkgname) elseif( pkgfirst STREQUAL "NAME" ) list(GET pkglist 1 pkgname) else() set(pkgname ${pkgfirst}) endif() if(${_p_NO_TPL}) set(_no_tpl NO_TPL) else() set(_no_tpl) endif() ecbuild_compat_require(pkgname ${pkg} ${_no_tpl} FEATURE "${_p_FEATURE}" DESCRIPTION "${_p_DESCRIPTION}") elseif( pkgfirst STREQUAL "NAME" ) list(GET pkglist 1 pkgname) ecbuild_find_package(${pkglist}) else() set(pkgname ${pkgfirst}) ecbuild_find_package(${pkglist}) endif() # we have feature if all required packages were FOUND if( ${pkgname}_FOUND ) ecbuild_info( "Found package ${pkgname} required for feature ${_p_FEATURE}" ) else() ecbuild_info( "Could NOT find package ${pkgname} required for feature ${_p_FEATURE} -- ${${pkgname}_HELP_MSG}" ) set( ${PROJECT_NAME}_HAVE_${_p_FEATURE} 0 ) list( APPEND _failed_to_find_packages ${pkgname} ) endif() endforeach() else( _${_p_FEATURE}_condition ) set( ${PROJECT_NAME}_HAVE_${_p_FEATURE} 0 ) endif( _${_p_FEATURE}_condition ) # FINAL CHECK if( ${PROJECT_NAME}_HAVE_${_p_FEATURE} ) ecbuild_enable_feature( ${_p_FEATURE} ) ecbuild_info( "Feature ${_p_FEATURE} enabled" ) else() # if user provided input and we cannot satisfy FAIL otherwise WARN ecbuild_disable_unused_feature( ${_p_FEATURE} ) # Determine if a project-specific feature was requested set ( _project_specific_feature_requested OFF ) if (DEFINED ${PNAME}_ENABLE_${_p_FEATURE} AND ${PNAME}_ENABLE_${_p_FEATURE} MATCHES "[Oo][Nn]") set ( _project_specific_feature_requested ON ) endif() if( ${_p_FEATURE}_user_provided_input OR _project_specific_feature_requested ) if( NOT _${_p_FEATURE}_condition ) string(REPLACE ";" " " _condition_msg "${_p_CONDITION}") ecbuild_critical( "Feature ${_p_FEATURE} cannot be enabled -- following condition was not met: ${_condition_msg}" ) set ( _tick "OFF") else() ecbuild_critical( "Feature ${_p_FEATURE} cannot be enabled -- following required packages weren't found: ${_failed_to_find_packages}" ) set ( _tick "OFF") endif() else() if( NOT _${_p_FEATURE}_condition ) string(REPLACE ";" " " _condition_msg "${_p_CONDITION}") ecbuild_info( "Feature ${_p_FEATURE} was not enabled (also not requested) -- following condition was not met: ${_condition_msg}" ) set ( _tick "OFF") else() ecbuild_info( "Feature ${_p_FEATURE} was not enabled (also not requested) -- following required packages weren't found: ${_failed_to_find_packages}" ) set ( _tick "OFF") endif() set( ENABLE_${_p_FEATURE} OFF ) ecbuild_disable_unused_feature( ${_p_FEATURE} ) endif() endif() else() ecbuild_info( "Feature ${_p_FEATURE} disabled" ) set( ${PROJECT_NAME}_HAVE_${_p_FEATURE} 0 ) ecbuild_disable_unused_feature( ${_p_FEATURE} ) endif() # Retrieve any existing description (n.b. occurs when the same feature is added at multiple projects) set(_enabled "${ENABLE_${_p_FEATURE}}") get_property( _feature_desc GLOBAL PROPERTY _CMAKE_${_p_FEATURE}_DESCRIPTION ) # Append the new description if( _feature_desc ) add_feature_info( ${_p_FEATURE} ${_enabled} "${_feature_desc}, ${PROJECT_NAME}(${_tick}): '${_p_DESCRIPTION}'" ) else() add_feature_info( ${_p_FEATURE} ${_enabled} "${PROJECT_NAME}(${_tick}): '${_p_DESCRIPTION}'" ) endif() if( ${_p_ADVANCED} ) mark_as_advanced( ENABLE_${_p_FEATURE} ) endif() set( HAVE_${_p_FEATURE} ${${PROJECT_NAME}_HAVE_${_p_FEATURE}} ) if(ECBUILD_2_COMPAT) set(ENABLE_${_p_FEATURE} ${ENABLE_${_p_FEATURE}}) ecbuild_mark_compat(ENABLE_${_p_FEATURE} "HAVE_${_p_FEATURE} or ${PROJECT_NAME}_HAVE_${_p_FEATURE}") string( TOUPPER ${PROJECT_NAME} PROJECT_NAME_CAPS ) if (NOT "${PROJECT_NAME_CAPS}" STREQUAL "${PROJECT_NAME}") ecbuild_declare_compat( ${PROJECT_NAME_CAPS}_HAVE_${_p_FEATURE} ${PROJECT_NAME}_HAVE_${_p_FEATURE}) endif() endif() if( ECBUILD_2_COMPAT ) set( DISABLE_ECBUILD_DEPRECATION_WARNINGS ${DISABLE_ECBUILD_DEPRECATION_WARNINGS_orig} ) endif() endmacro( ecbuild_add_option ) ecbuild-3.13.1/cmake/ecbuild_add_persistent.cmake000066400000000000000000000061451513706760700220110ustar00rootroot00000000000000# (C) Copyright 2011- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation nor # does it submit to any jurisdiction. ############################################################################## #.rst: # # ecbuild_add_persistent # ====================== # # Add persistent layer object classes. :: # # ecbuild_add_persistent( SRC_LIST # FILES [ ...] ] # [ NAMESPACE ] ) # # Options # ------- # # SRC_LIST : required # CMake variable to append the generated persistent layer objects to # # FILES : required # list of base names of files to build persistent class information for # # The source file is expected to have a .h extension, the generated file # gets a .b extension. # # NAMESPACE : optional # C++ namespace to place the persistent class information in # ############################################################################## # define the script to build the persistent class information set( sg_perl "${CMAKE_CURRENT_LIST_DIR}/sg.pl" CACHE INTERNAL "perl script to generate persistent objects" ) function( ecbuild_add_persistent ) ecbuild_find_perl( REQUIRED ) set( options ) set( single_value_args SRC_LIST NAMESPACE ) set( multi_value_args FILES ) cmake_parse_arguments( _PAR "${options}" "${single_value_args}" "${multi_value_args}" ${_FIRST_ARG} ${ARGN} ) if(_PAR_UNPARSED_ARGUMENTS) ecbuild_critical("Unknown keywords given to ecbuild_add_persistent(): \"${_PAR_UNPARSED_ARGUMENTS}\"") endif() if( NOT _PAR_SRC_LIST ) ecbuild_critical("The call to ecbuild_add_persistent() doesn't specify the SRC_LIST.") endif() ecbuild_debug( "ecbuild_add_persistent: adding persistent layer for [${_PAR_FILES}]" ) set(_SOURCES ${${_PAR_SRC_LIST}}) foreach( file ${_PAR_FILES} ) get_filename_component( _file_dir ${file} PATH ) get_filename_component( _file_we ${file} NAME_WE ) set( file ${_file_we} ) if( _file_dir ) file( MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${_file_dir} ) set( file ${_file_dir}/${_file_we} ) endif() ecbuild_debug( "ecbuild_add_persistent: adding persistent layer for ${file}.b with namespace '${_PAR_NAMESPACE}' from ${file}.h in ${CMAKE_CURRENT_BINARY_DIR}/${_file_dir}" ) add_custom_command( OUTPUT ${file}.b COMMAND ${PERL_EXECUTABLE} ${sg_perl} ${CMAKE_CURRENT_SOURCE_DIR}/${file}.h ${CMAKE_CURRENT_BINARY_DIR}/${_file_dir} ${_PAR_NAMESPACE} DEPENDS ${sg_perl} ${file}.h ) set_source_files_properties( ${file}.h PROPERTIES OBJECT_DEPENDS "${file}.b" ) list( APPEND _SOURCES ${CMAKE_CURRENT_BINARY_DIR}/${file}.b ) endforeach() if( _SOURCES ) list(REMOVE_DUPLICATES _SOURCES) endif() set(${_PAR_SRC_LIST} ${_SOURCES} PARENT_SCOPE) endfunction( ecbuild_add_persistent ) ecbuild-3.13.1/cmake/ecbuild_add_resources.cmake000066400000000000000000000131011513706760700216110ustar00rootroot00000000000000# (C) Copyright 2011- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation nor # does it submit to any jurisdiction. ############################################################################## #.rst: # # ecbuild_add_resources # ===================== # # Add resources as project files but optionally exclude them from packaging. :: # # ecbuild_add_resources( TARGET # [ SOURCES [ ...] ] # [ SOURCES_PACK [ ...] ] # [ SOURCES_DONT_PACK [ ...] ] # [ PACK [ ...] ] # [ DONT_PACK [ ...] ] # [ DONT_PACK_DIRS [ ...] ] # [ DONT_PACK_REGEX [ ...] ] ) # # Options # ------- # # TARGET : required # target name (target will only be created if there are any sources) # # SOURCES : optional, alias for SOURCES_PACK # list of source files included when packaging # # SOURCES_PACK : optional, alias for SOURCES # list of source files included when packaging # # SOURCES_DONT_PACK : optional # list of source files excluded when packaging # # PACK : optional, priority over DONT_PACK, DONT_PACK_DIRS, DONT_PACK_REGEX # list of files to include when packaging # # DONT_PACK : optional # list of files to exclude when packaging # # DONT_PACK_DIRS : optional # list of directories to exclude when packaging # # DONT_PACK_REGEX : optional # list of regular expressions to match files and directories to exclude when # packaging # # Note # ---- # # All file and directory names are also *partially matched*. To ensure that # only the exact file or directory name is matched at the end of the path add # a ``$`` at the end and quote the name. # ############################################################################## macro( ecbuild_add_resources ) set( options ) set( single_value_args TARGET ) set( multi_value_args SOURCES SOURCES_PACK SOURCES_DONT_PACK PACK DONT_PACK DONT_PACK_DIRS DONT_PACK_REGEX ) cmake_parse_arguments( _PAR "${options}" "${single_value_args}" "${multi_value_args}" ${_FIRST_ARG} ${ARGN} ) if(_PAR_UNPARSED_ARGUMENTS) ecbuild_critical("Unknown keywords given to ecbuild_add_resources(): \"${_PAR_UNPARSED_ARGUMENTS}\"") endif() if( NOT _PAR_TARGET ) ecbuild_critical("The call to ecbuild_add_resources() doesn't specify the TARGET.") endif() set( LOCAL_FILES_NOT_TO_PACK "" ) # all recursive files are not to pack if( DEFINED _PAR_DONT_PACK_REGEX ) foreach( exp ${_PAR_DONT_PACK_REGEX} ) file( GLOB_RECURSE all_files_in_subdirs RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${exp} ) list( APPEND LOCAL_FILES_NOT_TO_PACK ${all_files_in_subdirs} ) endforeach() endif() # selected dirs not to pack if( DEFINED _PAR_DONT_PACK_DIRS ) foreach( dir ${_PAR_DONT_PACK_DIRS} ) list( APPEND LOCAL_FILES_NOT_TO_PACK ${dir}/ ) endforeach() endif() # selected files not to pack if( DEFINED _PAR_DONT_PACK ) list( APPEND LOCAL_FILES_NOT_TO_PACK ${_PAR_DONT_PACK} ) endif() # now lets remove files that we want to pack from the list # note that these have priority over the files not to pack # so we can GLOB_RECURSE * -> DONT_PACK and then select only the ones we pack # files to pack but are not project files if( DEFINED _PAR_PACK ) foreach( file ${_PAR_PACK} ) list( REMOVE_ITEM LOCAL_FILES_NOT_TO_PACK ${file} ) endforeach() endif() # define as project files, but dont pack them if( DEFINED _PAR_SOURCES_DONT_PACK ) list( APPEND LOCAL_FILES_NOT_TO_PACK ${_PAR_SOURCES_DONT_PACK} ) foreach( sfile ${_PAR_SOURCES_DONT_PACK} ) set( _full_sfile "${CMAKE_CURRENT_SOURCE_DIR}/${sfile}" ) if( EXISTS ${_full_sfile} ) list( APPEND ${_PAR_TARGET}_files ${_full_sfile} ) endif() endforeach() endif() # define as project files and pack them # SOURCES_PACK is alias to SOURCES if( DEFINED _PAR_SOURCES_PACK ) list( APPEND _PAR_SOURCES ${_PAR_SOURCES_PACK} ) endif() if( DEFINED _PAR_SOURCES ) list( APPEND ${_PAR_TARGET}_files ${_PAR_SOURCES} ) foreach( file ${_PAR_SOURCES} ) list( REMOVE_ITEM LOCAL_FILES_NOT_TO_PACK ${file} ) endforeach() endif() # there are project files, so lets create the target if( DEFINED ${_PAR_TARGET}_files ) add_custom_target( ${_PAR_TARGET} SOURCES ${${_PAR_TARGET}_files} ) endif() # remove CMakeLists.txt foreach( file ${LOCAL_FILES_NOT_TO_PACK} ) if( ${file} MATCHES "CMakeLists.txt" ) list( REMOVE_ITEM LOCAL_FILES_NOT_TO_PACK ${file} ) endif() endforeach() # transform the local files to full absolute paths # and place them in the global list of files not to pack foreach( file ${LOCAL_FILES_NOT_TO_PACK} ) list( APPEND ECBUILD_DONT_PACK_FILES ${CMAKE_CURRENT_SOURCE_DIR}/${file} ) endforeach() # save cache if we added any files not to pack if( LOCAL_FILES_NOT_TO_PACK ) set( ECBUILD_DONT_PACK_FILES ${ECBUILD_DONT_PACK_FILES} CACHE INTERNAL "" ) endif() endmacro( ecbuild_add_resources ) ecbuild-3.13.1/cmake/ecbuild_add_test.cmake000066400000000000000000000503561513706760700205730ustar00rootroot00000000000000# (C) Copyright 2011- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation nor # does it submit to any jurisdiction. ############################################################################## #.rst: # # ecbuild_add_test # ================ # # Add a test as a script or an executable with a given list of source files. :: # # ecbuild_add_test( [ TARGET ] # [ SOURCES [ ...] ] # [ OBJECTS [ ...] ] # [ COMMAND ] # [ TYPE EXE|SCRIPT|PYTHON ] # [ LABELS [ ...] ] # [ ARGS [ ...] ] # [ RESOURCES [ ...] ] # [ TEST_DATA [ ...] ] # [ MPI ] # [ OMP ] # [ ENABLED ON|OFF ] # [ LIBS [ ...] ] # [ NO_AS_NEEDED ] # [ INCLUDES [ ...] ] # [ DEFINITIONS [ ...] ] # [ PERSISTENT [ ...] ] # [ GENERATED [ ...] ] # [ DEPENDS [ ...] ] # [ TEST_DEPENDS [ ...] ] # [ TEST_REQUIRES [ ...] ] # [ CONDITION ] # [ PROPERTIES [ ...] ] # [ TEST_PROPERTIES [ ...] ] # [ ENVIRONMENT [ ...] ] # [ WORKING_DIRECTORY ] # [ CFLAGS [ ...] ] # [ CXXFLAGS [ ...] ] # [ FFLAGS [ ...] ] # [ LINKER_LANGUAGE ] ) # # Options # ------- # # TARGET : either TARGET or COMMAND must be provided, unless TYPE is PYTHON # target name to be built # # SOURCES : required if TARGET is provided # list of source files to be compiled # # OBJECTS : optional # list of object libraries to add to this target # # COMMAND : either TARGET or COMMAND must be provided, unless TYPE is PYTHON # command or script to execute (no executable is built) # # TYPE : optional # test type, one of: # # :EXE: run built executable, default if TARGET is provided # :SCRIPT: run command or script, default if COMMAND is provided # :PYTHON: run a Python script (requires the Python interpreter to be found) # # LABELS : optional # list of labels to assign to the test # # The project name in lower case is always added as a label. Additional # labels are assigned depending on the type of test: # # :executable: for type ``EXE`` # :script: for type ``SCRIPT`` # :python: for type ``PYTHON`` # :mpi: if ``MPI`` is set # :openmp: if ``OMP`` is set # # This allows selecting tests to run via ``ctest -L `` or tests # to exclude via ``ctest -LE ``. # # ARGS : optional # list of arguments to pass to TARGET or COMMAND when running the test # # RESOURCES : optional # list of files to copy from the test source directory to the test directory # # TEST_DATA : optional # list of test data files to download # # MPI : optional # Run with MPI using the given number of MPI tasks. # # If greater than 1, and ``MPIEXEC`` is not available, the test is disabled. # # OMP : optional # number of OpenMP threads per MPI task to use. # # If set, the environment variable OMP_NUM_THREADS will set. # Also, in case of launchers like aprun, the OMP_NUMTHREADS_FLAG will be used. # # ENABLED : optional # if set to OFF, the test is built but not enabled as a test case # # LIBS : optional # list of libraries to link against (CMake targets or external libraries) # # NO_AS_NEEDED: optional # add --no-as-needed linker flag, to prevent stripping libraries that looks like are not used # # INCLUDES : optional # list of paths to add to include directories # # DEFINITIONS : optional # list of definitions to add to preprocessor defines # # PERSISTENT : optional # list of persistent layer object files # # GENERATED : optional # list of files to mark as generated (sets GENERATED source file property) # # DEPENDS : optional # list of targets to be built before this target # # TEST_DEPENDS : optional # list of tests to be run before this one # # TEST_REQUIRES : optional # list of tests that will automatically run before this one # # CONDITION : optional # conditional expression which must evaluate to true for this target to be # built (must be valid in a CMake ``if`` statement) # # PROPERTIES : optional # custom properties to set on the target # # TEST_PROPERTIES : optional # custom properties to set on the test # # ENVIRONMENT : optional # list of environment variables to set in the test environment # # WORKING_DIRECTORY : optional # directory to switch to before running the test # # CFLAGS : optional # list of C compiler flags to use for all C source files # # See usage note below. # # CXXFLAGS : optional # list of C++ compiler flags to use for all C++ source files # # See usage note below. # # FFLAGS : optional # list of Fortran compiler flags to use for all Fortran source files # # See usage note below. # # LINKER_LANGUAGE : optional # sets the LINKER_LANGUAGE property on the target # # Usage # ----- # # The ``CFLAGS``, ``CXXFLAGS`` and ``FFLAGS`` options apply the given compiler # flags to all C, C++ and Fortran sources passed to this command, respectively. # If any two ``ecbuild_add_executable``, ``ecbuild_add_library`` or # ``ecbuild_add_test`` commands are passed the *same* source file and each sets # a different value for the compiler flags to be applied to that file (including # when one command adds flags and another adds none), then the two commands # will be in conflict and the result may not be as expected. # # For this reason it is recommended not to use the ``*FLAGS`` options when # multiple targets share the same source files, unless the exact same flags are # applied to those sources by each relevant command. # # Care should also be taken to ensure that these commands are not passed source # files which are not required to build the target, if those sources are also # passed to other commands which set different compiler flags. # ############################################################################## function( ecbuild_add_test ) set( options NO_AS_NEEDED ) set( single_value_args TARGET ENABLED COMMAND TYPE LINKER_LANGUAGE MPI OMP WORKING_DIRECTORY ) set( multi_value_args SOURCES OBJECTS LIBS INCLUDES TEST_DEPENDS DEPENDS TEST_REQUIRES LABELS ARGS PERSISTENT DEFINITIONS RESOURCES TEST_DATA CFLAGS CXXFLAGS FFLAGS GENERATED CONDITION TEST_PROPERTIES PROPERTIES ENVIRONMENT ) cmake_parse_arguments( _PAR "${options}" "${single_value_args}" "${multi_value_args}" ${_FIRST_ARG} ${ARGN} ) if(_PAR_UNPARSED_ARGUMENTS) ecbuild_critical("Unknown keywords given to ecbuild_add_test(): \"${_PAR_UNPARSED_ARGUMENTS}\"") endif() set( _TEST_DIR ${CMAKE_CURRENT_BINARY_DIR} ) # Undocumented flag for disabling all MPI tests for test environment without suitable MPI(EXEC) if( _PAR_MPI AND ECBUILD_DISABLE_MPI_TESTS ) ecbuild_debug("ecbuild_add_test(${_PAR_TARGET}): ECBUILD_DISABLE_MPI_TESTS set - disabling test") set( _PAR_ENABLED 0 ) elseif( _PAR_MPI ) # Check for MPIEXEC if it not set if( MPIEXEC_EXECUTABLE ) set( MPIEXEC ${MPIEXEC_EXECUTABLE} ) endif() if( NOT MPIEXEC ) find_program( MPIEXEC NAMES mpiexec mpirun lamexec srun DOC "Executable for running MPI programs." ) endif() if( MPIEXEC ) set(MPIEXEC_NUMPROC_FLAG "-np" CACHE STRING "Flag used by MPI to specify the number of processes for MPIEXEC") ecbuild_debug("ecbuild_add_test(${_PAR_TARGET}): Running using ${MPIEXEC} on ${_PAR_MPI} MPI rank(s)") set( _PAR_LABELS mpi ${_PAR_LABELS} ) elseif( _PAR_MPI GREATER 1 ) ecbuild_debug("ecbuild_add_test(${_PAR_TARGET}): ${_PAR_MPI} MPI ranks requested but MPIEXEC not available - disabling test") set( _PAR_ENABLED 0 ) else() ecbuild_debug("ecbuild_add_test(${_PAR_TARGET}): 1 MPI rank requested but MPIEXEC not available - running sequentially") set( _PAR_MPI 0 ) endif() endif() # Check for OMP if( DEFINED _PAR_OMP ) set( _PAR_LABELS openmp ${_PAR_LABELS} ) else() set( _PAR_OMP 1 ) endif() list( APPEND _PAR_ENVIRONMENT "OMP_NUM_THREADS=${_PAR_OMP}" ) # default is enabled if( NOT DEFINED _PAR_ENABLED ) set( _PAR_ENABLED 1 ) endif() ### check test type # command implies script if( DEFINED _PAR_COMMAND ) set( _PAR_TYPE "SCRIPT" ) set( _PAR_LABELS script ${_PAR_LABELS} ) endif() # default of TYPE if( NOT _PAR_TYPE AND DEFINED _PAR_TARGET ) set( _PAR_TYPE "EXE" ) set( _PAR_LABELS executable ${_PAR_LABELS} ) if( NOT _PAR_SOURCES ) ecbuild_critical("The call to ecbuild_add_test() defines a TARGET without SOURCES.") endif() endif() ### conditional build ecbuild_evaluate_dynamic_condition( _PAR_CONDITION _${_PAR_TARGET}_condition ) ### enable the tests if( HAVE_TESTS AND _${_PAR_TARGET}_condition AND _PAR_ENABLED ) if( _PAR_TYPE MATCHES "PYTHON" ) if( PYTHONINTERP_FOUND ) set( _PAR_COMMAND ${PYTHON_EXECUTABLE} ) set( _PAR_LABELS python ${_PAR_LABELS} ) else() ecbuild_warn( "Requested a python test but python interpreter not found - disabling test\nPYTHON_EXECUTABLE: [${PYTHON_EXECUTABLE}]" ) set( _PAR_ENABLED 0 ) endif() endif() ### further checks if( _PAR_ENABLED AND NOT _PAR_TARGET AND NOT _PAR_COMMAND ) ecbuild_critical("The call to ecbuild_add_test() defines neither a TARGET nor a COMMAND.") endif() if( _PAR_ENABLED AND NOT _PAR_COMMAND AND NOT _PAR_SOURCES ) ecbuild_critical("The call to ecbuild_add_test() defines neither a COMMAND nor SOURCES, so no test can be defined or built.") endif() if( _PAR_TYPE MATCHES "SCRIPT" AND NOT _PAR_COMMAND ) ecbuild_critical("The call to ecbuild_add_test() defines a 'script' but doesn't specify the COMMAND.") endif() # add resources if( DEFINED _PAR_RESOURCES ) ecbuild_debug("ecbuild_add_test(${_PAR_TARGET}): copying resources ${_PAR_RESOURCES}") foreach( rfile ${_PAR_RESOURCES} ) execute_process( COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/${rfile} ${_TEST_DIR} ) endforeach() endif() # build executable if( DEFINED _PAR_SOURCES ) # add persistent layer files ecbuild_add_persistent( SRC_LIST _PAR_SOURCES FILES ${_PAR_PERSISTENT} NAMESPACE "${PERSISTENT_NAMESPACE}" ) # insert already compiled objects (from OBJECT libraries) unset( _all_objects ) foreach( _obj ${_PAR_OBJECTS} ) list( APPEND _all_objects $ ) endforeach() ecbuild_separate_sources( TARGET ${_PAR_TARGET} SOURCES ${_PAR_SOURCES} ) if( ${_PAR_TARGET}_cuda_srcs AND CUDA_FOUND ) cuda_add_executable( ${_PAR_TARGET} ${_PAR_SOURCES} ${_all_objects} ) else() add_executable( ${_PAR_TARGET} ${_PAR_SOURCES} ${_all_objects} ) endif() # add include dirs if defined if( DEFINED _PAR_INCLUDES ) ecbuild_filter_list(INCLUDES LIST ${_PAR_INCLUDES} LIST_INCLUDE path LIST_EXCLUDE skipped_path) ecbuild_debug("ecbuild_add_test(${_PAR_TARGET}): add [${path}] to include_directories") if( ECBUILD_2_COMPAT ) include_directories( ${path} ) else() target_include_directories(${_PAR_TARGET} PRIVATE ${path} ) endif() ecbuild_debug("ecbuild_add_test(${_PAR_TARGET}): [${skipped_path}] not found - not adding to include_directories") endif() # add extra dependencies if( DEFINED _PAR_DEPENDS) ecbuild_debug("ecbuild_add_test(${_PAR_TARGET}): add dependency on ${_PAR_DEPENDS}") add_dependencies( ${_PAR_TARGET} ${_PAR_DEPENDS} ) endif() # add the link libraries if( DEFINED _PAR_LIBS ) list(REMOVE_ITEM _PAR_LIBS debug) list(REMOVE_ITEM _PAR_LIBS optimized) ecbuild_filter_list(LIBS LIST ${_PAR_LIBS} LIST_INCLUDE lib LIST_EXCLUDE skipped_lib) ecbuild_debug("ecbuild_add_test(${_PAR_TARGET}): linking with [${lib}]") if ( _PAR_NO_AS_NEEDED AND CMAKE_SYSTEM_NAME MATCHES "Linux" AND CMAKE_CXX_COMPILER_ID MATCHES "GNU" ) target_link_libraries( ${_PAR_TARGET} -Wl,--no-as-needed ${lib} ) else() target_link_libraries( ${_PAR_TARGET} ${lib} ) endif() ecbuild_debug("ecbuild_add_test(${_PAR_TARGET}): [${skipped_lib}] not found - not linking") endif() # Override compilation flags on a per source file basis ecbuild_target_flags( ${_PAR_TARGET} "${_PAR_CFLAGS}" "${_PAR_CXXFLAGS}" "${_PAR_FFLAGS}" ) if( DEFINED _PAR_GENERATED ) ecbuild_debug("ecbuild_add_test(${_PAR_TARGET}): mark as generated ${_PAR_GENERATED}") set_source_files_properties( ${_PAR_GENERATED} PROPERTIES GENERATED 1 ) endif() if( DEFINED _PAR_DEFINITIONS ) target_compile_definitions(${_PAR_TARGET} PRIVATE ${_PAR_DEFINITIONS}) ecbuild_debug("ecbuild_add_test(${_PAR_TARGET}): adding definitions ${_PAR_DEFINITIONS}") endif() # set linker language if( DEFINED _PAR_LINKER_LANGUAGE ) ecbuild_debug("ecbuild_add_test(${_PAR_TARGET}): using linker language ${_PAR_LINKER_LANGUAGE}") set_target_properties( ${_PAR_TARGET} PROPERTIES LINKER_LANGUAGE ${_PAR_LINKER_LANGUAGE} ) if( ECBUILD_${_PAR_LINKER_LANGUAGE}_IMPLICIT_LINK_LIBRARIES ) target_link_libraries( ${_PAR_TARGET} ${ECBUILD_${_PAR_LINKER_LANGUAGE}_IMPLICIT_LINK_LIBRARIES} ) endif() endif() if( ECBUILD_IMPLICIT_LINK_LIBRARIES ) target_link_libraries( ${_PAR_TARGET} ${ECBUILD_IMPLICIT_LINK_LIBRARIES} ) endif() # set build location to local build dir # not the project base as defined for libs and execs set_target_properties( ${_PAR_TARGET} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${_TEST_DIR} ) # whatever project settings are, we always build tests with the build_rpath, not the install_rpath set_target_properties( ${_PAR_TARGET} PROPERTIES BUILD_WITH_INSTALL_RPATH FALSE ) set_target_properties( ${_PAR_TARGET} PROPERTIES SKIP_BUILD_RPATH FALSE ) # set linker language if( DEFINED _PAR_LINKER_LANGUAGE ) ecbuild_debug("ecbuild_add_test(${_PAR_TARGET}): using linker language ${_PAR_LINKER_LANGUAGE}") set_target_properties( ${_PAR_TARGET} PROPERTIES LINKER_LANGUAGE ${_PAR_LINKER_LANGUAGE} ) endif() # make sure target is removed before - some problems with AIX get_target_property(EXE_FILENAME ${_PAR_TARGET} OUTPUT_NAME) add_custom_command( TARGET ${_PAR_TARGET} PRE_BUILD COMMAND ${CMAKE_COMMAND} -E remove ${EXE_FILENAME} ) endif() # _PAR_SOURCES if( DEFINED _PAR_COMMAND AND NOT _PAR_TARGET ) # in the absence of target, we use the command as a name set( _PAR_TARGET ${_PAR_COMMAND} ) endif() # scripts dont have actual build targets # we build a phony target to trigger the dependencies if( DEFINED _PAR_COMMAND AND DEFINED _PAR_DEPENDS ) add_custom_target( ${_PAR_TARGET}.x ALL COMMAND ${CMAKE_COMMAND} -E touch ${_PAR_TARGET}.x ) add_dependencies( ${_PAR_TARGET}.x ${_PAR_DEPENDS} ) endif() # define the arguments set( TEST_ARGS "" ) list( APPEND TEST_ARGS ${_PAR_ARGS} ) # Wrap with MPIEXEC if( _PAR_MPI ) set( MPIEXEC_TASKS ${MPIEXEC_NUMPROC_FLAG} ${_PAR_MPI} ) if( DEFINED MPIEXEC_NUMTHREAD_FLAG ) set( MPIEXEC_THREADS ${MPIEXEC_NUMTHREAD_FLAG} ${_PAR_OMP} ) endif() # MPI_ARGS is left for users to define @ configure time e.g. -DMPI_ARGS="--oversubscribe" if( MPI_ARGS ) string(REGEX REPLACE "^\"(.*)\"$" "\\1" MPI_ARGS_REMOVED_OUTER_QUOTES ${MPI_ARGS} ) string(REPLACE " " ";" MPI_ARGS_LIST ${MPI_ARGS_REMOVED_OUTER_QUOTES}) endif() set( _LAUNCH ${MPIEXEC} ${MPI_ARGS_LIST} ${MPIEXEC_TASKS} ${MPIEXEC_THREADS} ) if( NOT _PAR_COMMAND AND _PAR_TARGET ) set( _PAR_COMMAND ${_PAR_TARGET} ) endif() ecbuild_debug("ecbuild_add_test(${_PAR_TARGET}): running as ${_LAUNCH} ${_PAR_COMMAND}") if( TARGET ${_PAR_COMMAND} ) set( _PAR_COMMAND ${_LAUNCH} $ ) else() set( _PAR_COMMAND ${_LAUNCH} ${_PAR_COMMAND} ) endif() endif() ### define the test if( _PAR_ENABLED ) # we can disable and still build it but not run it with 'make tests' if( EC_OS_NAME MATCHES "windows" AND ${_PAR_TYPE} MATCHES "SCRIPT" ) # Windows has to be explicitly told to use bash for the tests. if( NOT DEFINED WINDOWS_TESTING_BASHRC ) set( WINDOWS_TESTING_BASHRC "${CMAKE_CURRENT_SOURCE_DIR}/windows_testing.bashrc" ) endif() set( _WIN_CMD ${BASH_EXE} "--rcfile" "${WINDOWS_TESTING_BASHRC}" "-ci" ) else() set( _WIN_CMD "" ) endif() if( DEFINED _PAR_COMMAND ) add_test( NAME ${_PAR_TARGET} COMMAND ${_WIN_CMD} ${_PAR_COMMAND} ${TEST_ARGS} ${_working_dir} ) # run a command as test else() add_test( NAME ${_PAR_TARGET} COMMAND ${_WIN_CMD} ${_PAR_TARGET} ${TEST_ARGS} ${_working_dir} ) # run the test that was generated endif() # Set custom properties if( DEFINED _PAR_PROPERTIES ) set_target_properties( ${_PAR_TARGET} PROPERTIES ${_PAR_PROPERTIES} ) endif() if( DEFINED _PAR_TEST_PROPERTIES ) set_tests_properties( ${_PAR_TARGET} PROPERTIES ${_PAR_TEST_PROPERTIES} ) endif() # Set the fictures properties if test requires another test to run before if ( DEFINED _PAR_TEST_REQUIRES ) ecbuild_debug("ecbuild_add_test(${_PAR_TARGET}): set test requirements to ${_PAR_TEST_REQUIRES}") foreach(_requirement ${_PAR_TEST_REQUIRES} ) set_tests_properties( ${_requirement} PROPERTIES FIXTURES_SETUP ${_requirement} ) endforeach() set_tests_properties( ${_PAR_TARGET} PROPERTIES FIXTURES_REQUIRED "${_PAR_TEST_REQUIRES}" ) endif() # get test data if( _PAR_TEST_DATA ) ecbuild_get_test_multidata( TARGET ${_PAR_TARGET}_data NAMES ${_PAR_TEST_DATA} ) list( APPEND _PAR_TEST_DEPENDS ${_PAR_TARGET}_data ) endif() # Add lower case project name to custom test labels string( TOLOWER ${PROJECT_NAME} PROJECT_NAME_LOWCASE ) set( _PAR_LABELS ${PROJECT_NAME_LOWCASE} ${_PAR_LABELS} ) list( REMOVE_DUPLICATES _PAR_LABELS ) ecbuild_debug("ecbuild_add_test(${_PAR_TARGET}): assign labels ${_PAR_LABELS}") set_property( TEST ${_PAR_TARGET} APPEND PROPERTY LABELS "${_PAR_LABELS}" ) if( DEFINED _PAR_ENVIRONMENT ) set_property( TEST ${_PAR_TARGET} APPEND PROPERTY ENVIRONMENT "${_PAR_ENVIRONMENT}" ) endif() if( DEFINED _PAR_WORKING_DIRECTORY ) ecbuild_debug("ecbuild_add_test(${_PAR_TARGET}): set working directory to ${_PAR_WORKING_DIRECTORY}") set_tests_properties( ${_PAR_TARGET} PROPERTIES WORKING_DIRECTORY "${_PAR_WORKING_DIRECTORY}") endif() if( DEFINED _PAR_TEST_DEPENDS ) ecbuild_debug("ecbuild_add_test(${_PAR_TARGET}): set test dependencies to ${_PAR_TEST_DEPENDS}") set_property( TEST ${_PAR_TARGET} APPEND PROPERTY DEPENDS "${_PAR_TEST_DEPENDS}" ) endif() endif() # add to the overall list of tests list( APPEND ECBUILD_ALL_TESTS ${_PAR_TARGET} ) list( REMOVE_DUPLICATES ECBUILD_ALL_TESTS ) set( ECBUILD_ALL_TESTS ${ECBUILD_ALL_TESTS} CACHE INTERNAL "" ) endif() # _condition # finally mark project files ecbuild_declare_project_files( ${_PAR_SOURCES} ) endfunction( ecbuild_add_test ) ecbuild-3.13.1/cmake/ecbuild_append_to_rpath.cmake000066400000000000000000000070601513706760700221450ustar00rootroot00000000000000# (C) Copyright 2011- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation nor # does it submit to any jurisdiction. ############################################################################## #.rst: # # ecbuild_append_to_rpath # ======================= # # Append paths to the rpath. :: # # ecbuild_append_to_rpath( RPATH_DIRS ) # # ``RPATH_DIRS`` is a list of directories to append to ``CMAKE_INSTALL_RPATH``. # # * If a directory is absolute, simply append it. # * If a directory is relative, build a platform-dependent relative path # (using ``@loader_path`` on Mac OSX, ``$ORIGIN`` on Linux and Solaris) # or fall back to making it absolute by prepending the install prefix. # ############################################################################## function( ecbuild_path_append var path ) list( FIND ${var} ${path} _found ) if( _found EQUAL "-1" ) list( APPEND ${var} ${path}) endif() set( ${var} "${${var}}" PARENT_SCOPE ) # endfunction() function( _make_relative_rpath_entry entry var ) if( EC_OS_NAME STREQUAL "macosx" ) set( ${var} "@loader_path/${entry}" PARENT_SCOPE ) elseif( EC_OS_NAME STREQUAL "freebsd" ) set( ${var} "$ORIGIN/${entry}" PARENT_SCOPE ) elseif( EC_OS_NAME STREQUAL "linux" ) set( ${var} "$ORIGIN/${entry}" PARENT_SCOPE ) elseif( EC_OS_NAME STREQUAL "solaris" ) set( ${var} "$ORIGIN/${entry}" PARENT_SCOPE ) elseif( EC_OS_NAME STREQUAL "aix" ) # always relative to executable path set( ${var} "${entry}" PARENT_SCOPE ) elseif( EC_OS_NAME STREQUAL "hurd" ) set( ${var} "$ORIGIN/${entry}" PARENT_SCOPE ) else() set( ${var} "${CMAKE_INSTALL_PREFIX}/${entry}" PARENT_SCOPE ) endif() endfunction() macro( ecbuild_append_to_rpath RPATH_DIRS ) if( NOT ${ARGC} EQUAL 1 ) ecbuild_error( "ecbuild_append_to_rpath takes 1 argument") endif() foreach( RPATH_DIR ${RPATH_DIRS} ) if( NOT ${RPATH_DIR} STREQUAL "" ) file( TO_CMAKE_PATH ${RPATH_DIR} RPATH_DIR ) # sanitize the path if( IS_ABSOLUTE ${RPATH_DIR} ) ecbuild_path_append( CMAKE_INSTALL_RPATH "${RPATH_DIR}" ) else() _make_relative_rpath_entry( "${RPATH_DIR}" rpath_dir_rel ) ecbuild_path_append( CMAKE_INSTALL_RPATH ${rpath_dir_rel} ) endif() endif() endforeach() endmacro( ecbuild_append_to_rpath ) macro( ecbuild_target_rpath target mode ) if( "${mode}" STREQUAL REPLACE ) set( _target_rpath "" ) elseif( "${mode}" STREQUAL APPEND ) get_target_property( _target_rpath ${target} INSTALL_RPATH ) else() ecbuild_critical( "ecbuild_target_rpath arg 2 should be either APPEND \ or REPLACE" ) endif() foreach( rpath_dir ${ARGN} ) if( NOT ${rpath_dir} STREQUAL "" ) file( TO_CMAKE_PATH ${rpath_dir} rpath_dir ) # sanitise the path if( IS_ABSOLUTE ${rpath_dir} ) ecbuild_path_append( _target_rpath "${rpath_dir}" ) else() _make_relative_rpath_entry( "${rpath_dir}" rpath_dir_rel ) ecbuild_path_append( _target_rpath ${rpath_dir_rel} ) endif() endif() endforeach() set_target_properties( ${target} PROPERTIES INSTALL_RPATH "${_target_rpath}" ) endmacro() ecbuild-3.13.1/cmake/ecbuild_bundle.cmake000066400000000000000000000202421513706760700202440ustar00rootroot00000000000000# (C) Copyright 2011- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation # nor does it submit to any jurisdiction. # Set policies include( ecbuild_policies NO_POLICY_SCOPE ) include( CMakeParseArguments ) include( ecbuild_git ) ############################################################################## #.rst: # # ecbuild_bundle_initialize # ========================= # # Initialise the ecBuild environment for a bundle. *Must* be called *before* # any call to ``ecbuild_bundle``. :: # # ecbuild_bundle_initialize() # ############################################################################## macro( ecbuild_bundle_initialize ) include( local-config.cmake OPTIONAL ) # ecmwf_stash( PROJECT ecbuild DIR ${PROJECT_SOURCE_DIR}/ecbuild STASH "ecsdk/ecbuild" BRANCH develop ) # set( CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/ecbuild/cmake;${CMAKE_MODULE_PATH}" ) include( ecbuild_system ) ecbuild_requires_macro_version( 1.6 ) ecbuild_declare_project() file( GLOB local_config_files RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *local-config.cmake ) ecbuild_add_resources( TARGET ecbuild_bundle_dont_pack DONT_PACK "${local_config_files}" ) if( EXISTS "${PROJECT_SOURCE_DIR}/README.md" ) add_custom_target( ${PROJECT_NAME}_readme SOURCES "${PROJECT_SOURCE_DIR}/README.md" ) endif() # Point CMake to the packages in the bundle when using find_package set( CMAKE_PREFIX_PATH ${CMAKE_BINARY_DIR} ${CMAKE_PREFIX_PATH} ) endmacro() ############################################################################## #.rst: # # ecbuild_bundle # ============== # # Declare a subproject to be built as part of this bundle. :: # # ecbuild_bundle( PROJECT # STASH | GIT | SOURCE # [ BRANCH | TAG ] # [ UPDATE | NOREMOTE ] # [ MANUAL ] # [ RECURSIVE ] ) # # Options # ------- # # PROJECT : required # project name for the Git repository to be managed # # STASH : DEPRECATED ; cannot be combined with GIT or SOURCE # Stash repository in the form / # # GIT : cannot be combined with STASH or SOURCE # Git URL of the remote repository to clone (see ``git help clone``) # # SOURCE : cannot be combined with STASH or GIT # Path to an existing local repository, which will be symlinked # # BRANCH : optional, cannot be combined with TAG # Git branch to check out # # TAG : optional, cannot be combined with BRANCH # Git tag or commit id to check out # # UPDATE : optional, requires BRANCH, cannot be combined with NOREMOTE # Create a CMake target update to fetch changes from the remote repository # # NOREMOTE : optional, cannot be combined with UPDATE # Do not fetch changes from the remote repository # # MANUAL : optional # Do not automatically switch branches or tags # # RECURSIVE : optional # Do a recursive fetch or update # # Usage # ----- # # A bundle is used to build a number of projects together. Each subproject # needs to be declared with a call to ecbuild_bundle, where the order of # projects is important and needs to respect dependencies: if project B # depends on project A, A should be listed before B in the bundle. # # The first time a bundle is built, the sources of all subprojects are cloned # into directories named according to project in the *source* tree of the # bundle (which means these directories should be added to ``.gitignore``). # If the ``SOURCE`` option is used it must point to an existing local # repository on disk and no new repository is cloned. Be aware that using the # ``BRANCH`` or ``TAG`` option leads to the corresponding version being checked # out in that repository! # # Subprojects are configured and built in order. Due to being added as a # subproject, the usual project discovery mechanism (i.e. locating and # importing a ``-config.cmake`` file) is not used. Also there are no # ``-config.cmake`` files being generated for individual subprojects. # However there *are* package-config files being generated for each library. # # To switch off a subproject when building a bundle, set the CMake variable # ``BUNDLE_SKIP_`` where ``PNAME`` is the capitalised project name. # ############################################################################## macro( ecbuild_bundle ) set( options ) set( single_value_args PROJECT STASH GIT SOURCE ) set( multi_value_args ) cmake_parse_arguments( _PAR "${options}" "${single_value_args}" "${multi_value_args}" ${_FIRST_ARG} ${ARGN} ) string(TOUPPER "${_PAR_PROJECT}" PNAME) ecbuild_info( "---------------------------------------------------------" ) if( BUNDLE_SKIP_${PNAME} ) ecbuild_info( "Skipping bundle project ${_PAR_PROJECT}" ) else() ecbuild_info( "Adding bundle project ${_PAR_PROJECT}" ) if( _PAR_STASH ) if( ECBUILD_2_COMPAT ) if( ECBUILD_2_COMPAT_DEPRECATE ) ecbuild_deprecate( "Keyword STASH of ecbuild_bundle is deprecated, please use GIT with the full URL instead." ) endif() ecmwf_stash( PROJECT ${_PAR_PROJECT} DIR ${PROJECT_SOURCE_DIR}/${_PAR_PROJECT} STASH ${_PAR_STASH} ${_PAR_UNPARSED_ARGUMENTS} ) else() ecbuild_critical( "ecbuild_bundle(${_PAR_PROJECT}): the STASH keyword has been removed, please use GIT instead." ) endif() elseif( _PAR_GIT ) ecbuild_git( PROJECT ${_PAR_PROJECT} DIR ${PROJECT_SOURCE_DIR}/${_PAR_PROJECT} URL ${_PAR_GIT} ${_PAR_UNPARSED_ARGUMENTS} ) elseif( _PAR_SOURCE ) if( DEFINED ${PNAME}_SOURCE ) ecbuild_critical( "ecbuild_bundle called with SOURCE for project ${_PAR_PROJECT} but ${PNAME}_SOURCE is defined" ) endif() execute_process( COMMAND ${CMAKE_COMMAND} -E create_symlink ${_PAR_SOURCE} ${PROJECT_SOURCE_DIR}/${_PAR_PROJECT} ) endif() if( NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${_PAR_PROJECT} OR NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${_PAR_PROJECT}/CMakeLists.txt ) ecbuild_critical("Source directory '${CMAKE_CURRENT_SOURCE_DIR}/${_PAR_PROJECT}' for subproject '${_PAR_PROJECT}' does not exist or does not contain a CMakeLists.txt file.") endif() # Do not descend into ecbuild if included in a bundle (ECBUILD-333) if( NOT _PAR_PROJECT STREQUAL "ecbuild" ) add_subdirectory(${PROJECT_SOURCE_DIR}/${_PAR_PROJECT}) # Some packages define _FOUND by hand, this should not happen if( DEFINED ${_PAR_PROJECT}_FOUND OR DEFINED ${PNAME}_FOUND ) if( ECBUILD_2_COMPAT ) if( ECBUILD_2_COMPAT_DEPRECATE ) ecbuild_deprecate( "Project ${_PAR_PROJECT} defines _FOUND by hand, which may break dependencies." ) endif() unset(${_PAR_PROJECT}_FOUND) unset(${PNAME}_FOUND) else() ecbuild_error( "Project ${_PAR_PROJECT} defines _FOUND by hand." ) endif() endif() endif() endif() endmacro() ############################################################################## #.rst: # # ecbuild_bundle_finalize # ======================= # # Finalise the ecBuild environment for a bundle. *Must* be called *after* the # last call to ``ecbuild_bundle``. :: # # ecbuild_bundle_finalize() # # Options # ------- # # See documentation for ecbuild_install_project() since all arguments are # forwarded to an internal call to that macro. # # If no arguments are passed, then the default installation NAME is set to # the default project name ${CMAKE_PROJECT_NAME} # ############################################################################## macro( ecbuild_bundle_finalize ) add_custom_target( update DEPENDS ${git_update_targets} ) ecbuild_info("---------------------------------------------------------") ecbuild_info("Bundle ${CMAKE_PROJECT_NAME}") ecbuild_info("---------------------------------------------------------") if("${ARGV1}") ecbuild_install_project( ${ARGV} ) else() ecbuild_install_project( NAME ${CMAKE_PROJECT_NAME} ) endif() ecbuild_print_summary() endmacro() ecbuild-3.13.1/cmake/ecbuild_cache.cmake000066400000000000000000000066741513706760700200530ustar00rootroot00000000000000# (C) Copyright 2011- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation nor # does it submit to any jurisdiction. ############################################################################## #.rst: # # ecBuild Cache # ============= # # During initialisation, ecBuild introspects the compiler and operating system # and performs a number of checks. The result of these is written to a # dedicated ``ecbuild-cache.cmake`` file in the build tree. This cache may be # used to speed up subsequent *clean* builds i.e. those where no CMakeCache.txt # exists yet. # # To use the ecBuild cache, configure with ``-DECBUILD_CACHE=``, # where ```` is the path to an existing ``ecbuild-cache.cmake``. # # .. note :: # # The ecBuild cache is specific to compiler *and* operating system. Do *not* # attempt to use a cache file created on a different machine or with a # different compiler! # ############################################################################## # Prepare the cache and clobber any existing ecbuild-cache.cmake macro( ecbuild_prepare_cache ) include( CheckSymbolExists ) include( CheckIncludeFiles ) include( CheckCSourceCompiles ) include( CheckCXXSourceCompiles ) include( CheckTypeSize ) set( ecbuild_cache_file ${CMAKE_BINARY_DIR}/ecbuild-cache.cmake ) file(WRITE ${ecbuild_cache_file} "# ecbuild cache file\n\n") endmacro() # Buffer the CMake variable var to be written to the ecBuild cache function( ecbuild_cache_var var ) if( NOT ${var} ) set( ${var} 0 ) endif() set( ECBUILD_CACHE_BUFFER "${ECBUILD_CACHE_BUFFER}set( ${var} ${${var}} )\n" CACHE INTERNAL "Cache buffer" ) endfunction() # Call check_symbol_exists only if the output is not defined yet function( ecbuild_cache_check_symbol_exists symbol includes output ) if( NOT DEFINED ${output} ) check_symbol_exists( ${symbol} ${includes} ${output} ) endif() ecbuild_cache_var( ${output} ) endfunction() # Call check_include_files only if the output is not defined yet function( ecbuild_cache_check_include_files includes output ) if( NOT DEFINED ${output} ) check_include_files( ${includes} ${output} ) endif() ecbuild_cache_var( ${output} ) endfunction() # Call check_c_source_compiles only if the output is not defined yet function( ecbuild_cache_check_c_source_compiles source output ) if( NOT DEFINED ${output} ) check_c_source_compiles( "${source}" ${output} ) endif() ecbuild_cache_var( ${output} ) endfunction() # Call check_cxx_source_compiles only if the output is not defined yet function( ecbuild_cache_check_cxx_source_compiles source output ) if( NOT DEFINED ${output} ) check_cxx_source_compiles( "${source}" ${output} ) endif() ecbuild_cache_var( ${output} ) endfunction() # Call check_type_size only if the output is not defined yet function( ecbuild_cache_check_type_size type output ) if( NOT DEFINED ${output} ) check_type_size( "${type}" ${output} ) endif() ecbuild_cache_var( ${output} ) endfunction() # Flush the ecBuild cache to disk and reset the buffer function( ecbuild_flush_cache ) file( APPEND ${ecbuild_cache_file} "${ECBUILD_CACHE_BUFFER}" ) set( ECBUILD_CACHE_BUFFER "" CACHE INTERNAL "Cache buffer" ) endfunction() ecbuild-3.13.1/cmake/ecbuild_check_c_source_return.cmake000066400000000000000000000141171513706760700233350ustar00rootroot00000000000000# (C) Copyright 2011- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation nor # does it submit to any jurisdiction. ############################################################################## #.rst: # # ecbuild_check_c_source_return # ============================= # # Compile and run a given C source code and return its output. :: # # ecbuild_check_c_source_return( # VAR # OUTPUT # [ INCLUDES [ ... ] ] # [ LIBS [ ... ] ] # [ DEFINITIONS [ ... ] ] ) # # Options # ------- # # VAR : required # name of the check and name of the CMake variable to write result to # # OUTPUT : required # name of CMake variable to write the output to # # INCLUDES : optional # list of paths to add to include directories # # LIBS : optional # list of libraries to link against (CMake targets or external libraries) # # DEFINITIONS : optional # list of definitions to add to preprocessor defines # # Usage # ----- # # This will write the given source to a .c file and compile and run it with # ecbuild_try_run. If successful, ``${VAR}`` is set to 1 and ``${OUTPUT}`` is # set to the output of the successful run in the CMake cache. # # The check will not run if ``${VAR}`` is defined (e.g. from ecBuild cache). # ############################################################################## macro( ecbuild_check_c_source_return SOURCE ) set( options ) set( single_value_args VAR OUTPUT ) set( multi_value_args INCLUDES LIBS DEFINITIONS ) cmake_parse_arguments( _PAR "${options}" "${single_value_args}" "${multi_value_args}" ${_FIRST_ARG} ${ARGN} ) if(_PAR_UNPARSED_ARGUMENTS) ecbuild_critical("Unknown keywords given to ecbuild_check_c_source_return(): \"${_PAR_UNPARSED_ARGUMENTS}\"") endif() if( NOT _PAR_VAR OR NOT _PAR_OUTPUT ) ecbuild_critical("The call to ecbuild_check_c_source_return() doesn't specify either SOURCE, VAR or OUTPUT") endif() if( NOT DEFINED ${_PAR_VAR} ) set(MACRO_CHECK_FUNCTION_DEFINITIONS "-D${_PAR_VAR} ${CMAKE_REQUIRED_FLAGS}") set(__add_libs "") set(CHECK_C_SOURCE_COMPILES_ADD_LIBRARIES) if( CMAKE_REQUIRED_LIBRARIES ) list( APPEND __add_libs ${CMAKE_REQUIRED_LIBRARIES} ) endif() if( _PAR_LIBS ) list( APPEND __add_libs ${_PAR_LIBS} ) endif() if( __add_libs ) set(CHECK_C_SOURCE_COMPILES_ADD_LIBRARIES "-DLINK_LIBRARIES:STRING=${__add_libs}") endif() set(__add_incs "") set(CHECK_C_SOURCE_COMPILES_ADD_INCLUDES) if( CMAKE_REQUIRED_INCLUDES ) list( APPEND __add_incs ${CMAKE_REQUIRED_INCLUDES} ) endif() if( _PAR_INCLUDES ) list( APPEND __add_incs ${_PAR_INCLUDES} ) endif() if( __add_incs ) set(CHECK_C_SOURCE_COMPILES_ADD_INCLUDES "-DINCLUDE_DIRECTORIES:STRING=${__add_incs}") endif() # write the source file file( WRITE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CheckCSource/test_${_PAR_VAR}.c" "${SOURCE}\n" ) ecbuild_debug( "Performing Test ${_PAR_VAR}" ) ecbuild_try_run( ${_PAR_VAR}_EXITCODE ${_PAR_VAR}_COMPILED ${CMAKE_BINARY_DIR} ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CheckCSource/test_${_PAR_VAR}.c COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_FUNCTION_DEFINITIONS} -DCMAKE_SKIP_RPATH:BOOL=${CMAKE_SKIP_RPATH} "${CHECK_C_SOURCE_COMPILES_ADD_LIBRARIES}" "${CHECK_C_SOURCE_COMPILES_ADD_INCLUDES}" COMPILE_OUTPUT_VARIABLE compile_OUTPUT RUN_OUTPUT_VARIABLE run_OUTPUT ) # if it did not compile make the return value fail code of 1 if( NOT ${_PAR_VAR}_COMPILED ) set( ${_PAR_VAR}_EXITCODE 1 ) endif() ecbuild_debug_var( ${_PAR_VAR}_EXITCODE ) ecbuild_debug_var( ${_PAR_VAR}_COMPILED ) ecbuild_debug_var( compile_OUTPUT ) ecbuild_debug_var( run_OUTPUT ) # if the return value was 0 then it worked if("${${_PAR_VAR}_EXITCODE}" EQUAL 0) ecbuild_debug("Performing Test ${_PAR_VAR} - Success") file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log "Performing C SOURCE FILE Test ${_PAR_VAR} succeded with the following compile output:\n" "${compile_OUTPUT}\n" "Performing C SOURCE FILE Run ${_PAR_VAR} succeded with the following run output:\n" "${run_OUTPUT}\n" "Return value: ${${_PAR_VAR}}\n" "Source file was:\n${SOURCE}\n") set( ${_PAR_VAR} 1 CACHE INTERNAL "Test ${_PAR_VAR}") set( ${_PAR_OUTPUT} "${run_OUTPUT}" CACHE INTERNAL "Test ${_PAR_VAR} output") else() if(CMAKE_CROSSCOMPILING AND "${${_PAR_VAR}_EXITCODE}" MATCHES "FAILED_TO_RUN") set(${_PAR_VAR} "${${_PAR_VAR}_EXITCODE}") set(${OUTPUT} "") else() set(${_PAR_VAR} "" CACHE INTERNAL "Test ${_PAR_VAR}") set(${_PAR_OUTPUT} "" CACHE INTERNAL "Test ${_PAR_VAR} output") endif() ecbuild_debug("Performing Test ${_PAR_VAR} - Failed") file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log "Performing C SOURCE FILE Test ${_PAR_VAR} failed with the following compile output:\n" "${compile_OUTPUT}\n" "Performing C SOURCE FILE Run ${_PAR_VAR} failed with the following run output:\n" "${run_OUTPUT}\n" "Return value: ${${_PAR_VAR}_EXITCODE}\n" "Source file was:\n${SOURCE}\n") endif() endif() endmacro() ecbuild-3.13.1/cmake/ecbuild_check_compiler.cmake000066400000000000000000000076411513706760700217520ustar00rootroot00000000000000# (C) Copyright 2011- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation nor # does it submit to any jurisdiction. ######################################################################################################################## # enable C to use in system introspection if( NOT CMAKE_C_COMPILER_LOADED ) enable_language( C ) ecbuild_compiler_flags( C ) endif() ######################################################################################################################## # try to get compiler version if cmake did not if( NOT CMAKE_C_COMPILER_VERSION ) set( EC_COMPILER_VERSION "?.?" ) if( CMAKE_C_COMPILER_ID MATCHES "GNU" OR CMAKE_C_COMPILER_ID MATCHES "Intel" ) exec_program( ${CMAKE_C_COMPILER} ARGS ${CMAKE_C_COMPILER_ARG1} -dumpversion OUTPUT_VARIABLE EC_COMPILER_VERSION ) string(REGEX REPLACE "([0-9])\\.([0-9])(\\.([0-9]))?" "\\1.\\2" EC_COMPILER_VERSION ${EC_COMPILER_VERSION} ) endif() if( CMAKE_C_COMPILER_ID MATCHES "Clang" ) exec_program( ${CMAKE_C_COMPILER} ARGS ${CMAKE_C_COMPILER_ARG1} --version OUTPUT_VARIABLE EC_COMPILER_VERSION ) string(REGEX REPLACE ".*clang version ([0-9])\\.([0-9])(\\.([0-9]))?.*" "\\1.\\2" EC_COMPILER_VERSION ${EC_COMPILER_VERSION} ) endif() if( CMAKE_C_COMPILER_ID MATCHES "SunPro" ) exec_program( ${CMAKE_C_COMPILER} ARGS ${CMAKE_C_COMPILER_ARG1} -V OUTPUT_VARIABLE EC_COMPILER_VERSION ) string(REGEX REPLACE ".*([0-9]+)\\.([0-9]+).*" "\\1.\\2" EC_COMPILER_VERSION ${EC_COMPILER_VERSION} ) endif() if( CMAKE_C_COMPILER_ID MATCHES "XL" ) exec_program( ${CMAKE_C_COMPILER} ARGS ${CMAKE_C_COMPILER_ARG1} -qversion OUTPUT_VARIABLE EC_COMPILER_VERSION ) string(REGEX REPLACE ".*V([0-9]+)\\.([0-9]+).*" "\\1.\\2" EC_COMPILER_VERSION ${EC_COMPILER_VERSION} ) endif() if( NOT EC_COMPILER_VERSION STREQUAL "?.?" ) set(CMAKE_C_COMPILER_VERSION "${EC_COMPILER_VERSION}" ) endif() endif() ######################################################################################################################## # improve compilation speed with -pipe (use pipes instead of files between compilation processes) # measured 5% compilation speedup with Clang (using pipes vs SSD filesystem) if( CMAKE_C_COMPILER_ID MATCHES "GNU" OR CMAKE_C_COMPILER_ID MATCHES "Clang" ) ecbuild_add_c_flags( "-pipe" NO_FAIL ) # don't fail if for some reason is not accepted endif() if( CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang" ) ecbuild_add_cxx_flags( "-pipe" NO_FAIL ) # don't fail if for some reason is not accepted endif() ######################################################################################################################## # compiler dependent fixes # For Cray compilers add "-Wl,-Bdynamic" at very end of linker commands, in order to produce dynamic executables by default if( "${CMAKE_C_COMPILER_ID}" STREQUAL "Cray" ) set( CMAKE_C_LINK_EXECUTABLE " -o -Wl,-Bdynamic" ) endif() if( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Cray" ) set( CMAKE_CXX_LINK_EXECUTABLE " -o -Wl,-Bdynamic" ) endif() if( "${CMAKE_Fortran_COMPILER_ID}" STREQUAL "Cray" ) set(CMAKE_Fortran_LINK_EXECUTABLE " -o -Wl,-Bdynamic" ) endif() ecbuild-3.13.1/cmake/ecbuild_check_cxx_source_return.cmake000066400000000000000000000141751513706760700237210ustar00rootroot00000000000000# (C) Copyright 2011- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation nor # does it submit to any jurisdiction. ############################################################################## #.rst: # # ecbuild_check_cxx_source_return # =============================== # # Compile and run a given C++ code and return its output. :: # # ecbuild_check_cxx_source_return( # VAR # OUTPUT # [ INCLUDES [ ... ] ] # [ LIBS [ ... ] ] # [ DEFINITIONS [ ... ] ] ) # # Options # ------- # # VAR : required # name of the check and name of the CMake variable to write result to # # OUTPUT : required # name of CMake variable to write the output to # # INCLUDES : optional # list of paths to add to include directories # # LIBS : optional # list of libraries to link against (CMake targets or external libraries) # # DEFINITIONS : optional # list of definitions to add to preprocessor defines # # Usage # ----- # # This will write the given source to a .cxx file and compile and run it with # ecbuild_try_run. If successful, ``${VAR}`` is set to 1 and ``${OUTPUT}`` is # set to the output of the successful run in the CMake cache. # # The check will not run if ``${VAR}`` is defined (e.g. from ecBuild cache). # ############################################################################## macro( ecbuild_check_cxx_source_return SOURCE ) set( options ) set( single_value_args VAR OUTPUT ) set( multi_value_args INCLUDES LIBS DEFINITIONS ) cmake_parse_arguments( _p "${options}" "${single_value_args}" "${multi_value_args}" ${_FIRST_ARG} ${ARGN} ) if(_p_UNPARSED_ARGUMENTS) ecbuild_critical("Unknown keywords given to ecbuild_check_cxx_source_return(): \"${_p_UNPARSED_ARGUMENTS}\"") endif() if( NOT _p_VAR OR NOT _p_OUTPUT ) ecbuild_critical("The call to ecbuild_check_cxx_source_return() doesn't specify either SOURCE, VAR or OUTPUT") endif() set( _msg "Testing ${_p_VAR}:" ) if( NOT DEFINED ${_p_VAR} ) set(MACRO_CHECK_FUNCTION_DEFINITIONS "-D${_p_VAR} ${CMAKE_REQUIRED_FLAGS}") set(__add_libs "") set(CHECK_CXX_SOURCE_COMPILES_ADD_LIBRARIES) if(CMAKE_REQUIRED_LIBRARIES) list( APPEND __add_libs ${CMAKE_REQUIRED_LIBRARIES} ) endif() if( _p_LIBS ) list( APPEND __add_libs ${_p_LIBS} ) endif() if( __add_libs ) set(CHECK_CXX_SOURCE_COMPILES_ADD_LIBRARIES "-DLINK_LIBRARIES:STRING=${__add_libs}") endif() set(__add_incs "") set(CHECK_CXX_SOURCE_COMPILES_ADD_INCLUDES) if(CMAKE_REQUIRED_INCLUDES) list( APPEND __add_incs ${CMAKE_REQUIRED_INCLUDES} ) endif() if( _p_INCLUDES ) list( APPEND __add_incs ${_p_INCLUDES} ) endif() if( __add_incs ) set(CHECK_CXX_SOURCE_COMPILES_ADD_INCLUDES "-DINCLUDE_DIRECTORIES:STRING=${__add_incs}") endif() # write the source file file( WRITE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CheckCXXSource/test_${_p_VAR}.cxx" "${SOURCE}\n" ) ecbuild_debug( "${_msg}" ) ecbuild_try_run( ${_p_VAR}_EXITCODE ${_p_VAR}_COMPILED ${CMAKE_BINARY_DIR} ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CheckCXXSource/test_${_p_VAR}.cxx COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_FUNCTION_DEFINITIONS} -DCMAKE_SKIP_RPATH:BOOL=${CMAKE_SKIP_RPATH} "${CHECK_CXX_SOURCE_COMPILES_ADD_LIBRARIES}" "${CHECK_CXX_SOURCE_COMPILES_ADD_INCLUDES}" COMPILE_OUTPUT_VARIABLE compile_OUTPUT RUN_OUTPUT_VARIABLE run_OUTPUT ) # ecbuild_debug_var( ${_p_VAR}_COMPILED ) # ecbuild_debug_var( ${_p_VAR}_EXITCODE ) # if it did not compile make the return value fail code of 1 if( NOT ${_p_VAR}_COMPILED ) ecbuild_debug( "${_msg} failed to compile" ) endif() if( "${${_p_VAR}_EXITCODE}" MATCHES "FAILED_TO_RUN" ) ecbuild_debug( "${_msg} failed to run" ) endif() # if the return value was 0 then it worked if( ${_p_VAR}_COMPILED AND "${${_p_VAR}_EXITCODE}" EQUAL 0 ) ecbuild_debug("${_msg} Success") file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log "Performing C++ SOURCE FILE Test ${_p_VAR} succeded with the following compile output:\n" "${compile_OUTPUT}\n" "Performing C++ SOURCE FILE Run ${_p_VAR} succeded with the following run output:\n" "${run_OUTPUT}\n" "Return value: ${${_p_VAR}}\n" "Source file was:\n${SOURCE}\n") set( ${_p_VAR} 1 CACHE INTERNAL "Test ${_p_VAR}") set( ${_p_OUTPUT} "${run_OUTPUT}" CACHE INTERNAL "Test ${_p_VAR} output") else() if(CMAKE_CROSSCOMPILING AND "${${_p_VAR}_EXITCODE}" MATCHES "FAILED_TO_RUN") set(${_p_VAR} "${${_p_VAR}_EXITCODE}") set(${OUTPUT} "") else() set(${_p_VAR} "" CACHE INTERNAL "Test ${_p_VAR}") set(${_p_OUTPUT} "" CACHE INTERNAL "Test ${_p_VAR} output") endif() ecbuild_debug("Test ${_p_VAR} - Failed") file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log "Performing C++ SOURCE FILE Test ${_p_VAR} failed with the following compile output:\n" "${compile_OUTPUT}\n" "Performing C++ SOURCE FILE Run ${_p_VAR} failed with the following run output:\n" "${run_OUTPUT}\n" "Return value: ${${_p_VAR}_EXITCODE}\n" "Source file was:\n${SOURCE}\n") endif() endif() endmacro() ecbuild-3.13.1/cmake/ecbuild_check_fortran.cmake000066400000000000000000000076771513706760700216240ustar00rootroot00000000000000# (C) Copyright 2011- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation nor # does it submit to any jurisdiction. ############################################################################## #.rst: # # ecbuild_check_fortran # ===================== # # Check for Fortran features. :: # # ecbuild_check_fortran( [ FEATURES [ ... ] ] # [ REQUIRED [ ... ] ] # [ PRINT ] ) # # Options # ------- # # FEATURES : optional # list of optional features to check for # # REQUIRED : optional # list of required features to check for, fails if not detected # # PRINT : optional # print a summary of features checked for, found and not found # # Note # ---- # # If neither ``FEATURES`` nor ``REQUIRED`` are given, check for all features. # ############################################################################## function( ecbuild_check_fortran ) # parse parameters set( options PRINT ) set( single_value_args ) set( multi_value_args FEATURES REQUIRED ) cmake_parse_arguments( _p "${options}" "${single_value_args}" "${multi_value_args}" ${_FIRST_ARG} ${ARGN} ) if(_p_UNPARSED_ARGUMENTS) ecbuild_critical("Unknown keywords given to ecbuild_check_fortran(): \"${_p_UNPARSED_ARGUMENTS}\"") endif() include( ${ECBUILD_MACROS_DIR}/fortran_features/CheckFortranFeatures.cmake ) fortran_find_all_features( ALL_FEATURES ) # list all available features to check if( NOT _p_FEATURES AND NOT _p_REQUIRED ) # no input, then search for all features fortran_feature_check() else() foreach( _f ${_p_FEATURES} ) fortran_feature_check( ${_f} ) endforeach() foreach( _f ${_p_REQUIRED} ) fortran_feature_check( REQUIRED ${_f} ) endforeach() endif() if( _p_FEATURES OR _p_REQUIRED ) set( Fortran_CHECKED_FEATURES ${_p_FEATURES} ${_p_REQUIRED} ) else() set( Fortran_CHECKED_FEATURES ${ALL_FEATURES} ) endif() foreach( f ${Fortran_CHECKED_FEATURES} ) string( TOUPPER ${f} FEAT ) if( HAS_Fortran_${FEAT} ) list( APPEND Fortran_SUPPORTED_FEATURES ${f} ) set( EC_HAVE_Fortran_${FEAT} 1 PARENT_SCOPE ) else() list( APPEND Fortran_NOT_SUPPORTED_FEATURES ${f} ) set( EC_HAVE_Fortran_${FEAT} 0 PARENT_SCOPE ) endif() endforeach() if( Fortran_CHECKED_FEATURES ) list( SORT Fortran_CHECKED_FEATURES ) endif() if( Fortran_SUPPORTED_FEATURES ) list( SORT Fortran_SUPPORTED_FEATURES ) endif() if( Fortran_NOT_SUPPORTED_FEATURES ) list( SORT Fortran_NOT_SUPPORTED_FEATURES ) endif() set( Fortran_CHECKED_FEATURES ${Fortran_CHECKED_FEATURES} PARENT_SCOPE ) set( Fortran_SUPPORTED_FEATURES ${Fortran_SUPPORTED_FEATURES} PARENT_SCOPE ) set( Fortran_NOT_SUPPORTED_FEATURES ${Fortran_NOT_SUPPORTED_FEATURES} PARENT_SCOPE ) if( _p_PRINT ) if( Fortran_CHECKED_FEATURES ) join( Fortran_CHECKED_FEATURES " " Fortran_CHECKED_FEATURES_STR ) ecbuild_info( "Checked Fortran features: ${Fortran_CHECKED_FEATURES_STR}" ) else() ecbuild_info( "Checked no Fortran features" ) endif() if( Fortran_SUPPORTED_FEATURES ) join( Fortran_SUPPORTED_FEATURES " " Fortran_SUPPORTED_FEATURES_STR ) ecbuild_info( "Found Fortran features: ${Fortran_SUPPORTED_FEATURES_STR}" ) else() ecbuild_info( "Found no Fortran features" ) endif() if( Fortran_NOT_SUPPORTED_FEATURES ) join( Fortran_NOT_SUPPORTED_FEATURES " " Fortran_NOT_SUPPORTED_FEATURES_STR ) ecbuild_info( "Not found Fortran features: ${Fortran_NOT_SUPPORTED_FEATURES_STR}" ) else() ecbuild_info( "Found all checked Fortran features" ) endif() endif() endfunction( ecbuild_check_fortran ) ecbuild-3.13.1/cmake/ecbuild_check_fortran_source_return.cmake000066400000000000000000000140021513706760700245570ustar00rootroot00000000000000# (C) Copyright 2011- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation nor # does it submit to any jurisdiction. ############################################################################## #.rst: # # ecbuild_check_fortran_source_return # =================================== # # Compile and run a given Fortran code and return its output. :: # # ecbuild_check_fortran_source_return( # VAR # OUTPUT # [ INCLUDES [ ... ] ] # [ LIBS [ ... ] ] # [ DEFINITIONS [ ... ] ] ) # # Options # ------- # # VAR : required # name of the check and name of the CMake variable to write result to # # OUTPUT : required # name of CMake variable to write the output to # # INCLUDES : optional # list of paths to add to include directories # # LIBS : optional # list of libraries to link against (CMake targets or external libraries) # # DEFINITIONS : optional # list of definitions to add to preprocessor defines # # Usage # ----- # # This will write the given source to a .f file and compile and run it with # ecbuild_try_run. If successful, ``${VAR}`` is set to 1 and ``${OUTPUT}`` is # set to the output of the successful run in the CMake cache. # # The check will not run if ``${VAR}`` is defined (e.g. from ecBuild cache). # ############################################################################## macro( ecbuild_check_fortran_source_return SOURCE ) set( options ) set( single_value_args VAR OUTPUT ) set( multi_value_args INCLUDES LIBS DEFINITIONS ) cmake_parse_arguments( _PAR "${options}" "${single_value_args}" "${multi_value_args}" ${_FIRST_ARG} ${ARGN} ) if(_PAR_UNPARSED_ARGUMENTS) ecbuild_critical("Unknown keywords given to ecbuild_check_fortran_source_return(): \"${_PAR_UNPARSED_ARGUMENTS}\"") endif() if( NOT _PAR_VAR OR NOT _PAR_OUTPUT ) ecbuild_critical("The call to ecbuild_check_fortran_source_return() doesn't specify either SOURCE, VAR or OUTPUT") endif() if( NOT DEFINED ${_PAR_VAR} ) set(MACRO_CHECK_FUNCTION_DEFINITIONS "-D${_PAR_VAR} ${CMAKE_REQUIRED_FLAGS}") set(__add_libs "") set(CHECK_Fortran_SOURCE_COMPILES_ADD_LIBRARIES) if( CMAKE_REQUIRED_LIBRARIES ) list( APPEND __add_libs ${CMAKE_REQUIRED_LIBRARIES} ) endif() if( _PAR_LIBS ) list( APPEND __add_libs ${_PAR_LIBS} ) endif() if( __add_libs ) set(CHECK_Fortran_SOURCE_COMPILES_ADD_LIBRARIES "-DLINK_LIBRARIES:STRING=${__add_libs}") endif() set(__add_incs "") set(CHECK_Fortran_SOURCE_COMPILES_ADD_INCLUDES) if( CMAKE_REQUIRED_INCLUDES ) list( APPEND __add_incs ${CMAKE_REQUIRED_INCLUDES} ) endif() if( _PAR_INCLUDES ) list( APPEND __add_incs ${_PAR_INCLUDES} ) endif() if( __add_incs ) set(CHECK_Fortran_SOURCE_COMPILES_ADD_INCLUDES "-DINCLUDE_DIRECTORIES:STRING=${__add_incs}") endif() # write the source file file( WRITE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/test_${_PAR_VAR}.F90" "${SOURCE}\n" ) ecbuild_debug( "Performing Test ${_PAR_VAR}" ) ecbuild_try_run( ${_PAR_VAR}_EXITCODE ${_PAR_VAR}_COMPILED ${CMAKE_BINARY_DIR} ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/test_${_PAR_VAR}.F90 COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_FUNCTION_DEFINITIONS} -DCMAKE_SKIP_RPATH:BOOL=${CMAKE_SKIP_RPATH} "${CHECK_Fortran_SOURCE_COMPILES_ADD_LIBRARIES}" "${CHECK_Fortran_SOURCE_COMPILES_ADD_INCLUDES}" COMPILE_OUTPUT_VARIABLE compile_OUTPUT RUN_OUTPUT_VARIABLE run_OUTPUT ) # if it did not compile make the return value fail code of 1 if( NOT ${_PAR_VAR}_COMPILED ) set( ${_PAR_VAR}_EXITCODE 1 ) endif() # if the return value was 0 then it worked if("${${_PAR_VAR}_EXITCODE}" EQUAL 0) ecbuild_debug("Performing Test ${_PAR_VAR} - Success") file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log "Performing Fortran SOURCE FILE Test ${_PAR_VAR} succeded with the following compile output:\n" "${compile_OUTPUT}\n" "Performing Fortran SOURCE FILE Run ${_PAR_VAR} succeded with the following run output:\n" "${run_OUTPUT}\n" "Return value: ${${_PAR_VAR}}\n" "Source file was:\n${SOURCE}\n") set( ${_PAR_VAR} 1 CACHE INTERNAL "Test ${_PAR_VAR}") set( ${_PAR_OUTPUT} "${run_OUTPUT}" CACHE INTERNAL "Test ${_PAR_VAR} output") else() if(CMAKE_CROSSCOMPILING AND "${${_PAR_VAR}_EXITCODE}" MATCHES "FAILED_TO_RUN") set(${_PAR_VAR} "${${_PAR_VAR}_EXITCODE}") set(${OUTPUT} "") else() set(${_PAR_VAR} "" CACHE INTERNAL "Test ${_PAR_VAR}") set(${_PAR_OUTPUT} "" CACHE INTERNAL "Test ${_PAR_VAR} output") endif() ecbuild_debug("Performing Test ${_PAR_VAR} - Failed") file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log "Performing Fortran SOURCE FILE Test ${_PAR_VAR} failed with the following compile output:\n" "${compile_OUTPUT}\n" "Performing Fortran SOURCE FILE Run ${_PAR_VAR} failed with the following run output:\n" "${run_OUTPUT}\n" "Return value: ${${_PAR_VAR}_EXITCODE}\n" "Source file was:\n${SOURCE}\n") endif() endif() endmacro() ecbuild-3.13.1/cmake/ecbuild_check_os.cmake000066400000000000000000000440031513706760700205520ustar00rootroot00000000000000# (C) Copyright 2011- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation nor # does it submit to any jurisdiction. ############################################################################################ # check size of pointer # Re-check size of void pointer since for some compiler combinations this is not properly set check_type_size( "void*" CMAKE_SIZEOF_VOID_P ) if( NOT CMAKE_C_COMPILER_LOADED ) enable_language( C ) ecbuild_compiler_flags( C ) endif() math( EXPR EC_OS_BITS "${CMAKE_SIZEOF_VOID_P} * 8" ) # we only support 32 and 64 bit operating systems if( NOT EC_OS_BITS EQUAL "32" AND NOT EC_OS_BITS EQUAL "64" ) ecbuild_critical( "operating system ${CMAKE_SYSTEM} ${EC_OS_BITS} bits -- ecbuild only supports 32 or 64 bit OS's" ) endif() ############################################################################################ ### this will be deprecated in ecbuild 3.x include(ecbuild_test_endiness) ecbuild_test_endiness() ############################################################################################ # For 64 bit architectures enable PIC (position-independent code) # Allow overriding the position independent code setting (ECBUILD-220) if( DEFINED ECBUILD_POSITION_INDEPENDENT_CODE ) set( CMAKE_POSITION_INDEPENDENT_CODE ${ECBUILD_POSITION_INDEPENDENT_CODE} ) elseif( ${EC_OS_BITS} EQUAL 64 ) set( CMAKE_POSITION_INDEPENDENT_CODE ON ) endif() ############################################################################################ # check for large file support ### this will be deprecated in ecbuild 3.x include(ecbuild_add_large_file_support) if( ENABLE_LARGE_FILE_SUPPORT ) ecbuild_add_large_file_support() endif() ############################################################################################ # enable profiling via gprof if( ENABLE_PROFILING ) ecbuild_deprecate( "ENABLE_PROFILING is deprecated and ignored, use ENABLE_GPROF instead" ) endif() if( ENABLE_GPROF ) # User defined profiling flag takes precedence if( ECBUILD_GPROF_FLAG ) ecbuild_debug( "Enabling profiling with user defined flag '${ECBUILD_GPROF_FLAG}'" ) # -p Generate extra code to write profile information suitable for the analysis program # prof. You must use this option when compiling the source files you want data about, # and you must also use it when linking. # # -pg Generate extra code to write profile information suitable for the analysis program # gprof. You must use this option when compiling the source files you want data about, # and you must also use it when linking. # # --coverage # This option is used to compile and link code instrumented for coverage analysis. The # option is a synonym for -fprofile-arcs -ftest-coverage (when compiling) and -lgcov # (when linking). See the documentation for those options for more details. # # * Compile the source files with -fprofile-arcs plus optimization and code generation # options. For test coverage analysis, use the additional -ftest-coverage option. # You do not need to profile every source file in a program. # # * Link your object files with -lgcov or -fprofile-arcs (the latter implies the # former). # # * Run the program on a representative workload to generate the arc profile # information. This may be repeated any number of times. You can run concurrent # instances of your program, and provided that the file system supports locking, the # data files will be correctly updated. Also "fork" calls are detected and correctly # handled (double counting will not happen). # # * For profile-directed optimizations, compile the source files again with the same # optimization and code generation options plus -fbranch-probabilities. # # * For test coverage analysis, use gcov to produce human readable information from the # .gcno and .gcda files. Refer to the gcov documentation for further information. # # With -fprofile-arcs, for each function of your program GCC creates a program flow # graph, then finds a spanning tree for the graph. Only arcs that are not on the # spanning tree have to be instrumented: the compiler adds code to count the number of # times that these arcs are executed. When an arc is the only exit or only entrance to a # block, the instrumentation code can be added to the block; otherwise, a new basic block # must be created to hold the instrumentation code. elseif( CMAKE_C_COMPILER_ID MATCHES "GNU" ) set( ECBUILD_GPROF_FLAG "-pg --coverage" ) ecbuild_debug( "Enabling profiling with GNU flag '${ECBUILD_GPROF_FLAG}'" ) # -p # # Compiles and links for function profiling # with gprof(1). # # Architecture Restrictions: Not available on Intel(R) 64 architecture # targeting the # Intel(R) Xeon Phi(TM) coprocessor x100 product family (formerly code # name Knights Corner), on IA-32 architecture targeting Intel(R) # Graphics Technology, or on Intel(R) 64 architecture targeting Intel(R) # Graphics Technology # # Arguments: # # None # # Default: # # OFF Files are compiled and linked without profiling. # # Description: # # This option compiles and links for function profiling with gprof(1). # # When you specify this option, inlining is disabled. However, you can override # this by specifying pragma forceinline, declspec forceinline (Windows* OS), # attribute always_inline (Linux* OS and OS X*), or a compiler option such as # [Q]inline-forceinline. elseif( CMAKE_C_COMPILER_ID MATCHES "Intel" ) set( ECBUILD_GPROF_FLAG "-p" ) ecbuild_debug( "Enabling profiling with Intel flag '${ECBUILD_GPROF_FLAG}'" ) # -Mprof[=option[,option,...]] # Set performance profiling options. Use of these options will cause the resulting # executable to create a performance profile that can be viewed and analyzed with the # PGPROF performance profiler. In the descriptions below, PGI-style profiling implies # compiler-generated source instrumentation. MPICH-style profiling implies the use of # instrumented wrappers for MPI library routines. The -Mprof options are: # # ccff # # dwarf Generate limited DWARF symbol information sufficient for most performance # profilers. # # func Perform PGI-style function level profiling. # # hwcts Generate a profile using event-based sampling of hardware counters via the # PAPI interface (linux86-64 only, PAPI must be installed). # # lines Perform PGI-style line level profiling. # # hpmpi (PGI CDK only) Perform MPICH-style profiling for the HP Implies # -Mmpi=hpmpi. # # mpich1 (PGI CDK only) Perform MPICH-style profiling for MPICH-1. Implies # -Mmpi=mpich1. Use MPIDIR to point to the MPICH-1 libraries. This flag is # no longer fully supported. # # mpich2 (PGI CDK only) Perform MPICH-style profiling for MPICH-2. Implies # -Mmpi=mpich2. Use MPIDIR to point to the MPICH-1 libraries. This flag is # no longer fully supported. # # mvapich1 (PGI CDK only) Perform MPICH-style profiling for MVAPICH. Implies # -Mmpi=mvapich1. Use MPIDIR to point to the MPICH-1 libraries. This flag # is no longer fully supported. # # time Generate a profile using time-based instruction-level statistical # sampling. This is equivalent to -pg, except that the profile is saved in a # file named pgprof.out instead of gmon.out. # # On Linux systems that have OProfile installed, PGPROF supports collection of # performance data without recompilation. Use of -Mprof=dwarf is useful for this mode # of profiling. elseif( CMAKE_C_COMPILER_ID MATCHES "PGI" ) set( ECBUILD_GPROF_FLAG "-Mprof=dwarf,time" ) ecbuild_debug( "Enabling profiling with PGI flag '${ECBUILD_GPROF_FLAG}'" ) # There is no equivalent to -pg for clang: # http://lists.llvm.org/pipermail/cfe-dev/2010-September/011255.html else() ecbuild_warn( "Profiling enabled but ecbuild doesn't know how to enable for this particular compiler ${CMAKE_C_COMPILER_ID}") endif() set( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${ECBUILD_GPROF_FLAG}" ) set( CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${ECBUILD_GPROF_FLAG}" ) set( CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${ECBUILD_GPROF_FLAG}" ) set( _trust_flags ${ECBUILD_TRUST_FLAGS} ) set( ECBUILD_TRUST_FLAGS ON ) ecbuild_add_c_flags( "${ECBUILD_GPROF_FLAG}" ) ecbuild_add_cxx_flags( "${ECBUILD_GPROF_FLAG}" ) ecbuild_add_fortran_flags( "${ECBUILD_GPROF_FLAG}" ) set( ECBUILD_TRUST_FLAGS ${_trust_flags} ) unset( _trust_flags ) endif() ############################################################################################ # check operating system set( EC_OS_NAME "UNKNOWN" ) ### Unix's -- Proper operating systems if( UNIX ) ### APPLE ### if( APPLE AND ${CMAKE_SYSTEM_NAME} MATCHES "Darwin" ) set( EC_OS_NAME "macosx" ) endif() ### Linux ### if( ${CMAKE_SYSTEM_NAME} MATCHES "Linux" ) set( EC_OS_NAME "linux" ) # The following option allows enabling the new dtags linker option # (when set to OFF). ONLY SET TO OFF IF YOU KNOW WHAT YOU ARE DOING AND # NEVER WHEN BUILDING PRODUCTION SOFTWARE. YOU HAVE BEEN WARNED! option( ECBUILD_DISABLE_NEW_DTAGS "Set the linker flag --disable-new-dtags" ON ) mark_as_advanced( ECBUILD_DISABLE_NEW_DTAGS ) if( ECBUILD_DISABLE_NEW_DTAGS ) # recent linkers default to --enable-new-dtags # which then adds both RPATH and RUNPATH to executables # thus invalidating RPATH setting, and making LD_LIBRARY_PATH take precedence # to be sure, use tool 'readelf -a | grep PATH' to see what paths are built-in # see: # * http://blog.qt.digia.com/blog/2011/10/28/rpath-and-runpath # * http://www.cmake.org/Wiki/CMake_RPATH_handling # * man ld # * http://blog.tremily.us/posts/rpath # * http://fwarmerdam.blogspot.co.uk/2010/12/rpath-runpath-and-ldlibrarypath.html set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--disable-new-dtags") set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--disable-new-dtags") set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,--disable-new-dtags") endif() # The following option enables a linker check to set ECBUILD_DISABLE_DYNCHECK if needed. option( ECBUILD_DISABLE_RPATH_FIX "Disable the linker fix for relative RPATH" OFF ) mark_as_advanced( ECBUILD_DISABLE_RPATH_FIX ) get_property(HAVE_SHARED_LIBS GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS) if( HAVE_SHARED_LIBS AND NOT ECBUILD_DISABLE_RPATH_FIX ) # GNU ld versions before 2.28 do not expand $ORIGIN at link time. # If this is the case for the current linker, disable checking for dynamic symbols # See https://sourceware.org/bugzilla/show_bug.cgi?id=20535 set( _linker_check_srcdir "${ECBUILD_MACROS_DIR}/../check_linker" ) if( NOT EXISTS ${_linker_check_srcdir} ) # ecbuild source dir set( _linker_check_srcdir "${ECBUILD_MACROS_DIR}/../share/ecbuild/check_linker" ) endif() set( _linker_check_bindir "${CMAKE_BINARY_DIR}/ecbuild_tmp/check_linker" ) # Make sure the build directory does not point to another version if( EXISTS ${_linker_check_bindir}/CMakeCache.txt ) file( STRINGS ${_linker_check_bindir}/CMakeCache.txt _linker_check_prev_src REGEX "^CMAKE_HOME_DIRECTORY" LIMIT_COUNT 1 ) string( REGEX REPLACE "^.*=(.+)$" "\\1" _linker_check_prev_src "${_linker_check_prev_src}" ) string( STRIP _linker_check_prev_src "${_linker_check_prev_src}" ) get_filename_component( _linker_check_prev_src "${_linker_check_prev_src}" REALPATH ) get_filename_component( _linker_check_curr_src "${_linker_check_srcdir}" REALPATH ) if( NOT _linker_check_prev_src STREQUAL _linker_check_curr_src ) file( REMOVE ${_linker_check_bindir}/CMakeCache.txt ) endif() endif() try_compile( _linker_understands_origin ${_linker_check_bindir} ${_linker_check_srcdir} test_ld_origin ) cmake_policy( PUSH ) cmake_policy( SET CMP0012 NEW ) if( NOT ${_linker_understands_origin} ) ecbuild_warn( "The linker does not support $ORIGIN at link-time, \ disabling dynamic symbol check when linking against shared libraries" ) set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--allow-shlib-undefined") set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--allow-shlib-undefined") set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,--allow-shlib-undefined") endif() cmake_policy( POP ) endif() endif() ### FreeBSD ### if( ${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD" ) set( EC_OS_NAME "freebsd" ) endif() ### OpenBSD ### if( ${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD" ) set( EC_OS_NAME "openbsd" ) endif() ### Solaris ### if( ${CMAKE_SYSTEM_NAME} MATCHES "SunOS" ) set( EC_OS_NAME "solaris" ) endif() ### AIX ### if( ${CMAKE_SYSTEM_NAME} MATCHES "AIX" ) set( EC_OS_NAME "aix" ) set( CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -bbigtoc" ) if( CMAKE_C_COMPILER_ID MATCHES "GNU" ) set( CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Xlinker" ) endif() if( CMAKE_COMPILER_IS_GNUCC ) if( EC_OS_BITS EQUAL "64" ) ecbuild_add_c_flags("-maix64") endif() if( EC_OS_BITS EQUAL "32" ) ecbuild_add_c_flags("-maix32") endif() endif() if( CMAKE_COMPILER_IS_GNUCXX ) if( EC_OS_BITS EQUAL "64" ) ecbuild_add_cxx_flags("-maix64") endif() if( EC_OS_BITS EQUAL "32" ) ecbuild_add_cxx_flags("-maix32") endif() endif() if( CMAKE_C_COMPILER_ID MATCHES "XL" ) ecbuild_add_c_flags("-qpic=large") # ecbuild_add_c_flags("-qweaksymbol") if(EC_OS_BITS EQUAL "32" ) ecbuild_add_c_flags("-q32") endif() if(${CMAKE_BUILD_TYPE} MATCHES "Release" OR ${CMAKE_BUILD_TYPE} MATCHES "Production" ) ecbuild_add_c_flags("-qstrict") ecbuild_add_c_flags("-qinline") endif() if(${CMAKE_BUILD_TYPE} MATCHES "Debug") ecbuild_add_c_flags("-qfullpath") ecbuild_add_c_flags("-qkeepparm") endif() endif() if( CMAKE_CXX_COMPILER_ID MATCHES "XL" ) ecbuild_add_cxx_flags("-qpic=large") ecbuild_add_cxx_flags("-bmaxdata:0x40000000") ecbuild_add_cxx_flags("-qrtti") ecbuild_add_cxx_flags("-qfuncsect") # ecbuild_add_cxx_flags("-qweaksymbol") if(EC_OS_BITS EQUAL "32" ) ecbuild_add_cxx_flags("-q32") endif() if(${CMAKE_BUILD_TYPE} MATCHES "Release" OR ${CMAKE_BUILD_TYPE} MATCHES "Production" ) ecbuild_add_cxx_flags("-qstrict") ecbuild_add_cxx_flags("-qinline") endif() if(${CMAKE_BUILD_TYPE} MATCHES "Debug") ecbuild_add_cxx_flags("-qfullpath") ecbuild_add_cxx_flags("-qkeepparm") endif() endif() if( CMAKE_Fortran_COMPILER_ID MATCHES "XL" ) ecbuild_add_fortran_flags("-qxflag=dealloc_cfptr") ecbuild_add_fortran_flags("-qextname") ecbuild_add_fortran_flags("-qdpc=e") ecbuild_add_fortran_flags("-bmaxdata:0x40000000") ecbuild_add_fortran_flags("-bloadmap:loadmap -bmap:loadmap") if(EC_OS_BITS EQUAL "32" ) ecbuild_add_fortran_flags("-q32") endif() endif() endif() ### GNU/Hurd ### if( ${CMAKE_SYSTEM_NAME} STREQUAL "GNU" ) set( EC_OS_NAME "hurd" ) endif() endif() ### Cygwin if( ${CMAKE_SYSTEM_NAME} MATCHES "CYGWIN" ) set( EC_OS_NAME "cygwin" ) ecbuild_warn( "Building on Cygwin should work but is untested" ) endif() ### Windows if( ${CMAKE_SYSTEM_NAME} MATCHES "Windows" OR WIN32 ) # its weird, but WIN32 also includes Win64 set( EC_OS_NAME "windows" ) find_program( BASH_EXE NAMES bash DOC "Used under Windows for fixing symlinks and running unit tests" ) if( NOT BASH_EXE ) ecbuild_critical("Could not find program 'bash'. Specify the location with -DBASH_EXE=C:/...") endif() ecbuild_warn( "CMake doesn't support symlinks on Windows. " "Replacing all symlinks with copies." ) execute_process( COMMAND ${BASH_EXE} -c "${ECBUILD_MACROS_DIR}/ecbuild_windows_replace_symlinks.sh" WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} RESULT_VARIABLE CMD_RESULT OUTPUT_VARIABLE CMD_OUTPUT ERROR_VARIABLE CMD_ERROR ) ecbuild_debug( "Windows Replace Symlinks res=[${CMD_RESULT}] " "output=[${CMD_OUTPUT}] error=[${CMD_ERROR}]" ) if( CMD_RESULT ) ecbuild_critical( "Failed to replace windows symlinks. " "output=[${CMD_OUTPUT}] error=[${CMD_ERROR}]" ) endif() endif() ### final warning / error if( ${EC_OS_NAME} MATCHES "UNKNOWN" ) if( DISABLE_OS_CHECK ) ecbuild_warn( "ecBuild is untested for this operating system: [${CMAKE_SYSTEM_NAME}]" " -- DISABLE_OS_CHECK is ON so proceeding at your own risk ..." ) else() ecbuild_critical( "ecBuild is untested for this operating system: [${CMAKE_SYSTEM_NAME}]" " -- refusing to continue. Disable this check with -DDISABLE_OS_CHECK=ON" ) endif() endif() ecbuild-3.13.1/cmake/ecbuild_check_urls.cmake000066400000000000000000000074741513706760700211310ustar00rootroot00000000000000# (C) Copyright 2020- JCSDA. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. ############################################################################## #.rst: # # ecbuild_check_urls # ====================== # # Check multiple URL validity. :: # # ecbuild_check_urls( NAMES [ ... ] # RESULT ) # # curl or wget is required (curl is preferred if available). # # Options # ------- # # NAMES : required # list of names of the files to check, including the directory structure # on the server hosting test files (if available) # # RESULT : required # check result (0 if all URLs exist, more if not) # # Usage # ----- # # Check whether files exist on ``/`` # for each name given in the list of ``NAMES``. # ``RESULT`` is set to the number of missing files. # # If the ``ECBUILD_DOWNLOAD_BASE_URL`` variable is not set, the default URL # ``https://sites.ecmwf.int/repository`` is used. # # Examples # -------- # # Check file ... existence: :: # # ecbuild_check_urls( NAMES test/data/dir/msl1.grib test/data/dir/msl2.grib # RESULT FILES_EXIST ) # ############################################################################## function(ecbuild_check_urls) set( single_value_args RESULT ) set( multi_value_args NAMES ) cmake_parse_arguments( _p "${options}" "${single_value_args}" "${multi_value_args}" ${_FIRST_ARG} ${ARGN} ) if(_p_UNPARSED_ARGUMENTS) ecbuild_critical("Unknown keywords given to ecbuild_check_url(): \"${_p_UNPARSED_ARGUMENTS}\"") endif() ### check parameters if( NOT _p_NAMES ) ecbuild_critical("ecbuild_get_test_data() expects a NAMES") endif() # Allow the user to override the download URL (ECBUILD-447) if( NOT DEFINED ECBUILD_DOWNLOAD_BASE_URL ) set( ECBUILD_DOWNLOAD_BASE_URL https://sites.ecmwf.int/repository ) endif() # Do not retry downloads by default (ECBUILD-307) if( NOT DEFINED ECBUILD_DOWNLOAD_RETRIES ) set( ECBUILD_DOWNLOAD_RETRIES 0 ) endif() # Use default timeout of 30s if not specified (ECBUILD-307) if( NOT DEFINED ECBUILD_DOWNLOAD_TIMEOUT ) set( ECBUILD_DOWNLOAD_TIMEOUT 30 ) endif() # Initialise CODE_SUM set( CODE_SUM 0 ) find_program( CURL_PROGRAM curl ) if ( NOT CURL_PROGRAM ) find_program( WGET_PROGRAM wget ) if ( NOT WGET_PROGRAM ) set( CODE 1 ) if( NOT WARNING_CANNOT_DOWNLOAD_TEST_DATA ) ecbuild_warn( "Couldn't find curl neither wget -- cannot check URL, set result to 0." ) set( WARNING_CANNOT_DOWNLOAD_TEST_DATA 1 CACHE INTERNAL "Couldn't find curl neither wget -- cannot check URL, set result to 0" ) mark_as_advanced( WARNING_CANNOT_DOWNLOAD_TEST_DATA ) endif() endif() endif() foreach( NAME ${_p_NAMES} ) if ( CURL_PROGRAM ) execute_process( COMMAND ${CURL_PROGRAM} --silent --head --fail --output /dev/null --retry ${ECBUILD_DOWNLOAD_RETRIES} --connect-timeout ${ECBUILD_DOWNLOAD_TIMEOUT} ${ECBUILD_DOWNLOAD_BASE_URL}/${NAME} RESULT_VARIABLE CODE ) else() math( EXPR ECBUILD_DOWNLOAD_RETRIES "${ECBUILD_DOWNLOAD_RETRIES} + 1" ) execute_process( COMMAND ${WGET_PROGRAM} -O/dev/null -q -t ${ECBUILD_DOWNLOAD_RETRIES} -T ${ECBUILD_DOWNLOAD_TIMEOUT} ${ECBUILD_DOWNLOAD_BASE_URL}/${NAME} RESULT_VARIABLE CODE ) endif() # Add to CODE_SUM if( CODE GREATER 0) math( EXPR CODE_SUM "${CODE_SUM} + 1" ) endif() endforeach() # Set result set( ${_p_RESULT} ${CODE_SUM} PARENT_SCOPE ) endfunction(ecbuild_check_urls) ecbuild-3.13.1/cmake/ecbuild_compile_options.cmake000066400000000000000000000172711513706760700222060ustar00rootroot00000000000000# (C) Copyright 2011- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation nor # does it submit to any jurisdiction. ############################################################################## #.rst: # # ecbuild_compile_options # ======================= # # Defined variables describing compiler options for the current compiler. :: # # Fortran: # - ``ECBUILD_Fortran_COMPILE_OPTIONS_REAL4`` : Convert all unqualified REALs to 32 bit (single precision) # - ``ECBUILD_Fortran_COMPILE_OPTIONS_REAL8`` : Convert all unqualified REALs to 64 bit (double precision) # - ``ECBUILD_Fortran_COMPILE_OPTIONS_CHECK_BOUNDS`` : Bounds checking compile options # - ``ECBUILD_Fortran_COMPILE_OPTIONS_INIT_SNAN`` : Compile options to initialize REAL's with signaling NaN # - ``ECBUILD_Fortran_COMPILE_OPTIONS_FPE_TRAP`` : Compile options to trap floating-point-exceptions # # Example use: # # 1. Application to entire scope # # ecbuild_add_fortran_flags( ${ECBUILD_Fortran_COMPILE_OPTIONS_REAL8} ) # # 2. Application to a target with mixed language source files # # target_compile_options(my_target PUBLIC # $<$:${ECBUILD_Fortran_COMPILE_OPTIONS_REAL8}>) # # A generator expression is required here to only apply the flags to Fortran files in the target. # # This is only needed if it is a mixed-language target. # # 3. On a per source file basis # # set_property(SOURCE my_source.F90 # APPEND PROPERTY COMPILE_OPTIONS ${ECBUILD_Fortran_COMPILE_OPTIONS_REAL8}) # ############################################################################## ############################################################################## #.rst: # # ecbuild_define_compile_options # ============================== # # Define a compile_option for a given compiler ID and language :: # # ecbuild_define_compile_options( NAME DESCRIPTION LANGUAGE [ REQUIRED ] # [ GNU ] [ NEC ] [ NVHPC ] [ Intel ] # [ IntelLLVM ] [ Cray ] [ Flang ] [ NAG ] # [ LLVMFlang ] ) # # Options # ------- # # NAME : # The name given to compile_option # # DESCRIPTION : # The description of compile_option # # LANGUAGE : # The compiler language the compile_options apply to # # GNU : optional # The values for the compile option for GNU compiler and given LANGUAGE # # NEC : optional # The values for the compile option for NEC compiler and given LANGUAGE # # NVHPC : optional # The values for the compile option for NVHPC compiler and given LANGUAGE # # Intel : optional # The values for the compile option for Intel compiler and given LANGUAGE # # IntelLLVM : optional # The values for the compile option for IntelLLVM compiler and given LANGUAGE # # Cray : optional # The values for the compile option for Cray compiler and given LANGUAGE # # Flang : optional # The values for the compile option for Flang compiler and given LANGUAGE # # NAG : optional # The values for the compile option for NAG compiler and given LANGUAGE # # LLVMFlang : optional # The values for the compile option for LLVM Flang compiler and given LANGUAGE # # REQUIRED : optional # fail if the compile_options for the current compiler are not implemented, # to avoid nasty surpises # ############################################################################## function( ecbuild_define_compile_options ) set( supported_compiler_ids GNU NEC NVHPC Intel IntelLLVM Cray Flang NAG LLVMFlang ) set( options REQUIRED ) set( single_value_args NAME DESCRIPTION LANGUAGE ) set( multi_value_args ${supported_compiler_ids} ) cmake_parse_arguments( _p "${options}" "${single_value_args}" "${multi_value_args}" ${_FIRST_ARG} ${ARGN} ) if(_p_UNPARSED_ARGUMENTS) ecbuild_critical("Unknown keywords given to ecbuild_define_compiler_options(): \"${_p_UNPARSED_ARGUMENTS}\"") endif() if(NOT DEFINED _p_LANGUAGE) ecbuild_critical("Argument LANGUAGE is required to function ecbuild_define_compiler_options()") endif() set(lang ${_p_LANGUAGE}) if( CMAKE_${lang}_COMPILER_LOADED) set(${lang}_COMPILER_ID ${CMAKE_${lang}_COMPILER_ID}) if(ECBUILD_${lang}_COMPILER_ID) set(${lang}_COMPILER_ID ${ECBUILD_${lang}_COMPILER_ID}) endif() foreach(compiler_id ${supported_compiler_ids}) if(_p_${compiler_id} AND ${lang}_COMPILER_ID STREQUAL "${compiler_id}") set(${_p_NAME} ${_p_${compiler_id}} CACHE STRING "${_p_${DESCRIPTION}}") ecbuild_debug("${_p_NAME}: ${${_p_NAME}}") endif() endforeach() if(_p_REQUIRED) if( NOT DEFINED ${_p_NAME} ) list(FIND ARGV ${${lang}_COMPILER_ID} ARG_FOUND) if( ARG_FOUND STREQUAL -1 ) ecbuild_critical( " Variable '${_p_NAME}' must be defined for compiler with ID ${${lang}_COMPILER_ID}.\n" " Description:\n" " ${_p_DESCRIPTION}\n" " Please submit a patch. In the mean time you can provide the variable to the CMake configuration.") endif() endif() endif() endif() endfunction() ############################################################################## ### ECBUILD_Fortran_COMPILE_OPTIONS_REAL4 ecbuild_define_compile_options( NAME ECBUILD_Fortran_COMPILE_OPTIONS_REAL4 DESCRIPTION "Compile options to convert all unqualified reals to 32 bit (single precision)" LANGUAGE Fortran REQUIRED NEC -fdefault-real=4 NVHPC -r4 GNU # empty (default) Intel # empty (default) IntelLLVM # empty (default) Cray # empty (default) Flang # empty (default) NAG # empty (default) LLVMFlang # empty (default) ) ### ECBUILD_Fortran_COMPILE_OPTIONS_REAL8 ecbuild_define_compile_options( NAME ECBUILD_Fortran_COMPILE_OPTIONS_REAL8 DESCRIPTION "Compile options to convert all unqualified reals and doubles to 64 bit (double precision)" LANGUAGE Fortran REQUIRED GNU -fdefault-real-8 -fdefault-double-8 NEC -fdefault-real=8 -fdefault-double=8 NVHPC -r8 Intel -r8 IntelLLVM -r8 Cray -sreal64 Flang -fdefault-real-8 NAG -double LLVMFlang -fdefault-real-8 ) ### ECBUILD_Fortran_COMPILE_OPTIONS_CHECK_BOUNDS ecbuild_define_compile_options( NAME ECBUILD_Fortran_COMPILE_OPTIONS_CHECK_BOUNDS DESCRIPTION "Bounds checking compile options" LANGUAGE Fortran GNU -fcheck=bounds NEC -fcheck=bounds NVHPC -Mbounds Intel -check bounds IntelLLVM -check bounds Cray -Rb ) ### ECBUILD_Fortran_COMPILE_OPTIONS_INIT_SNAN ecbuild_define_compile_options( NAME ECBUILD_Fortran_COMPILE_OPTIONS_INIT_SNAN DESCRIPTION "Compile options to initialize REAL's with signaling NaN" LANGUAGE Fortran GNU -finit-real=snan Intel -init=snan IntelLLVM -init=snan Cray -ei ) ### ECBUILD_Fortran_COMPILE_OPTIONS_FPE_TRAP ecbuild_define_compile_options( NAME ECBUILD_Fortran_COMPILE_OPTIONS_FPE_TRAP DESCRIPTION "Compile options to trap floating-point-exceptions" LANGUAGE Fortran GNU -ffpe-trap=invalid,zero,overflow Intel -fpe0 IntelLLVM -fpe0 NVHPC -Ktrap=fp Cray -Ktrap=fp Flang -ffp-exception-behavior=strict ) ecbuild-3.13.1/cmake/ecbuild_compiler_flags.cmake000066400000000000000000000332671513706760700217740ustar00rootroot00000000000000# (C) Copyright 2011- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation nor # does it submit to any jurisdiction. ############################################################################## #.rst: # # ecbuild_compiler_flags # ====================== # # Set compiler specific default compilation flags for a given language. :: # # ecbuild_compiler_flags( ) # # The procedure is as follows: # # 1. ecBuild does **not** set ``CMAKE__FLAGS`` i.e. the user can set # these via ``-D`` or the CMake cache and these will be the "base" flags. # # 2. ecBuild **overwrites** ``CMAKE__FLAGS_`` in the CMake cache # for all build types with compiler specific defaults for the currently # loaded compiler i.e. any value set by the user via ``-D`` or the CMake # cache **has no effect**. # # 3. Any value the user provides via ``ECBUILD__FLAGS`` or # ``ECBUILD__FLAGS_`` **overrides** the corresponding # ``CMAKE__FLAGS`` or ``CMAKE__FLAGS_`` **without being # written to the CMake cache**. # ############################################################################## macro( ecbuild_compiler_flags _lang ) # Set compiler and language specific default flags - OVERWRITES variables in CMake cache if( CMAKE_${_lang}_COMPILER_LOADED ) ecbuild_debug( "ecbuild_compiler_flags(${_lang}): try include ${ECBUILD_MACROS_DIR}/compiler_flags/${CMAKE_${_lang}_COMPILER_ID}_${_lang}.cmake ") include( ${ECBUILD_MACROS_DIR}/compiler_flags/${CMAKE_${_lang}_COMPILER_ID}_${_lang}.cmake OPTIONAL ) endif() set (_btypelist NONE DEBUG BIT PRODUCTION RELEASE RELWITHDEBINFO) if (NOT "${CMAKE_BUILD_TYPE}" IN_LIST _btypelist) list (APPEND _btypelist "${CMAKE_BUILD_TYPE}") endif () # Apply user or toolchain specified compilation flag overrides (NOT written to cache) foreach( _btype IN LISTS _btypelist) if( DEFINED ECBUILD_${_lang}_FLAGS_${_btype} ) ecbuild_debug( "ecbuild_compiler_flags(${_lang}): overriding CMAKE_${_lang}_FLAGS_${_btype} with ${ECBUILD_${_lang}_FLAGS_${_btype}}") set( CMAKE_${_lang}_FLAGS_${_btype} ${ECBUILD_${_lang}_FLAGS_${_btype}} ) endif() mark_as_advanced( CMAKE_${_lang}_FLAGS_${_btype} ) endforeach() if( DEFINED ECBUILD_${_lang}_FLAGS ) ecbuild_debug( "ecbuild_compiler_flags(${_lang}): overriding CMAKE_${_lang}_FLAGS with ${ECBUILD_${_lang}_FLAGS}") set( CMAKE_${_lang}_FLAGS "${ECBUILD_${_lang}_FLAGS}" ) endif() mark_as_advanced( CMAKE_${_lang}_FLAGS ) if( DEFINED ECBUILD_${_lang}_LINK_FLAGS ) ecbuild_debug( "ecbuild_compiler_flags(${_lang}): overriding CMAKE_${_lang}_LINK_FLAGS with ${ECBUILD_${_lang}_LINK_FLAGS}") set( CMAKE_${_lang}_LINK_FLAGS "${ECBUILD_${_lang}_LINK_FLAGS}" ) endif() mark_as_advanced( CMAKE_${_lang}_LINK_FLAGS ) ecbuild_debug_var( CMAKE_${_lang}_FLAGS ) foreach( _btype IN LISTS _btypelist) ecbuild_debug_var( CMAKE_${_lang}_FLAGS_${_btype} ) endforeach() endmacro() ############################################################################## #.rst: # # ecbuild_purge_compiler_flags # ============================ # # Purge compiler flags for a given language :: # # ecbuild_purge_compiler_flags( ) # ############################################################################## macro( ecbuild_purge_compiler_flags _lang ) set( options WARN ) set( oneValueArgs "" ) set( multiValueArgs "" ) set (_btypelist ALL DEBUG BIT PRODUCTION RELEASE RELWITHDEBINFO) if (NOT "${CMAKE_BUILD_TYPE}" IN_LIST _btypelist) list (APPEND _btypelist "${CMAKE_BUILD_TYPE}") endif () cmake_parse_arguments( _PAR "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} ) if( CMAKE_${_lang}_COMPILER_LOADED ) # Clear default compilation flags potentially inherited from parent scope # when using custom compilation flags if( ECBUILD_SOURCE_FLAGS OR ECBUILD_COMPILE_FLAGS ) set(CMAKE_${_lang}_FLAGS "") foreach( _btype IN LISTS _btypelist) set(CMAKE_${_lang}_FLAGS_${_btype} "") endforeach() endif() endif() if( ${_PAR_WARN} ) ecbuild_warn( "Purging compiler flags set for ${_lang}" ) endif() endmacro() ############################################################################## #.rst: # # ecbuild_linker_flags # ==================== # # Apply user or toolchain specified linker flag overrides per object type (NOT written to cache) # # ecbuild_linker_flags() # ############################################################################## macro( ecbuild_linker_flags ) foreach( _obj EXE SHARED MODULE ) if( ECBUILD_${_obj}_LINKER_FLAGS ) set( CMAKE_${_obj}_LINKER_FLAGS ${ECBUILD_${_obj}_LINKER_FLAGS} ) endif() if( NOT "$ENV{LD_RUN_PATH}" EQUAL "" ) set( LD_RUN_PATH "$ENV{LD_RUN_PATH}" ) string( REPLACE ":" ";" LD_RUN_PATH "$ENV{LD_RUN_PATH}" ) foreach( rpath ${LD_RUN_PATH} ) ecbuild_regex_escape( "${rpath}" rpath_escaped ) if( NOT CMAKE_${_obj}_LINKER_FLAGS MATCHES ".*-Wl,-rpath,${rpath_escaped}.*") set( CMAKE_${_obj}_LINKER_FLAGS "${CMAKE_${_obj}_LINKER_FLAGS} -Wl,-rpath,${rpath}" ) endif() endforeach() endif() endforeach() set (_btypelist NONE DEBUG BIT PRODUCTION RELEASE RELWITHDEBINFO) if (NOT "${CMAKE_BUILD_TYPE}" IN_LIST _btypelist) list (APPEND _btypelist "${CMAKE_BUILD_TYPE}") endif () foreach( _btype IN LISTS _btypelist) foreach( _obj EXE SHARED MODULE ) if( ECBUILD_${_obj}_LINKER_FLAGS_${_btype} ) set( CMAKE_${_obj}_LINKER_FLAGS_${_btype} ${ECBUILD_${_obj}_LINKER_FLAGS_${_btype}} ) endif() endforeach() endforeach() endmacro() ############################################################################## #.rst: # # ecbuild_override_compiler_flags # =============================== # # Purge existing CMAKE__FLAGS flags and trigger the use of per source # file overrideable flags (see ``Using custom compilation flags`` for an # explanation). # # ecbuild_override_compiler_flags() # ############################################################################## macro( ecbuild_override_compiler_flags ) set( options "" ) set( oneValueArgs SOURCE_FLAGS COMPILE_FLAGS ) set( multiValueArgs "" ) cmake_parse_arguments( _PAR "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} ) # Ensure COMPILE/SOURCE_FLAGS is a valid file path if( DEFINED _PAR_COMPILE_FLAGS AND NOT EXISTS ${_PAR_COMPILE_FLAGS} ) ecbuild_warn( "COMPILE_FLAGS points to non-existent file ${_PAR_COMPILE_FLAGS} and will be ignored" ) unset( ECBUILD_COMPILE_FLAGS ) unset( ECBUILD_COMPILE_FLAGS CACHE ) elseif( DEFINED _PAR_SOURCE_FLAGS AND NOT EXISTS ${_PAR_SOURCE_FLAGS} ) ecbuild_warn( "SOURCE_FLAGS points to non-existent file ${_PAR_SOURCE_FLAGS} and will be ignored" ) unset( ECBUILD_SOURCE_FLAGS ) unset( ECBUILD_SOURCE_FLAGS CACHE ) elseif( DEFINED _PAR_SOURCE_FLAGS OR DEFINED _PAR_COMPILE_FLAGS ) foreach( _lang C CXX Fortran ) if( CMAKE_${_lang}_COMPILER_LOADED ) ecbuild_purge_compiler_flags( ${_lang} WARN ) endif() endforeach() if( DEFINED _PAR_COMPILE_FLAGS ) if( DEFINED ECBUILD_COMPILE_FLAGS) ecbuild_debug( "Override ECBUILD_COMPILE_FLAGS (${ECBUILD_COMPILE_FLAGS}) with ${_PAR_COMPILE_FLAGS}" ) endif() set( ECBUILD_COMPILE_FLAGS ${_PAR_COMPILE_FLAGS} ) include( ${ECBUILD_COMPILE_FLAGS} ) elseif( DEFINED _PAR_SOURCE_FLAGS ) if( DEFINED ECBUILD_SOURCE_FLAGS) ecbuild_debug( "Override ECBUILD_SOURCE_FLAGS (${ECBUILD_SOURCE_FLAGS}) with ${_PAR_SOURCE_FLAGS}" ) endif() set( ECBUILD_SOURCE_FLAGS ${_PAR_SOURCE_FLAGS} ) endif() ecbuild_linker_flags() endif() endmacro() ############################################################################## #.rst: # # Using custom compilation flags # ============================== # # If compilation flags need to be controlled on a per source file basis, # ecBuild supports defining custom rules in a CMake or JSON file. # # When using this approach, *default compilation flags are NOT loaded*! # # Overriding compilation flags on a per source file basis using CMake rules # ------------------------------------------------------------------------- # # Compiler flags can be overridden on a per source file basis by setting the # CMake variable ``ECBUILD_COMPILE_FLAGS`` to the *full path* of a CMake file # defining the override rules. If set, ``_ECBUILD_COMPILE_FLAGS`` # takes precendence and ``ECBUILD_COMPILE_FLAGS`` is ignored, allowing for # rules that only apply to a subproject (e.g. in a bundle). # # Flags can be overridden in 3 different ways: # # 1. By defining project specific flags for a language and (optionally) # build type e.g. :: # # set(_Fortran_FLAGS "...") # common flags for all build types # set(_Fortran_FLAGS_DEBUG "...") # only for DEBUG build type # # 2. By defining source file specific flags which are *combined* with the # project and target specific flags :: # # set_source_files_properties( # PROPERTIES COMPILE_FLAGS "..." # common flags for all build types # COMPILE_FLAGS_DEBUG "...") # only for DEBUG build type # # 3. By defining source file specific flags which *override* the project and # target specific flags :: # # set_source_files_properties( # PROPERTIES OVERRIDE_COMPILE_FLAGS "..." # OVERRIDE_COMPILE_FLAGS_DEBUG "...") # # See ``examples/override-compile-flags`` in the ecBuild source tree for a # complete example using this technique. # # Overriding compilation flags on a per source file basis using JSON rules # ------------------------------------------------------------------------ # # Compiler flags can be overridden on a per source file basis by setting the # CMake variable ``ECBUILD_SOURCE_FLAGS`` to the *full path* of a JSON file # defining the override rules. If set, ``_ECBUILD_SOURCE_FLAGS`` # takes precendence and ``ECBUILD_SOURCE_FLAGS`` is ignored, allowing for # rules that only apply to a subproject (e.g. in a bundle). # # The JSON file lists shell glob patterns and the rule to apply to each source # file matching the pattern, defined as an array ``[op, flag1, ...]`` # containing an operator followed by one or more flags. Valid operators are: # # :+: Add the flags to the default compilation flags for matching files # :=: Set the flags for matching files, disregarding default compilation flags # :/: Remove the flags from the default compilation flags for matching files # # Rules can be nested to e.g. only apply to a subdirectory by setting the rule # to a dictionary, which will only apply to source files matching its pattern. # # An example JSON file demonstrating different rule types is given below: :: # # { # "*" : [ "+", "-g0" ], # "*.cxx" : [ "+", "-cxx11" ], # "*.f90" : [ "+", "-pipe" ], # "foo.c" : [ "+", "-O0" ], # "foo.cc" : [ "+", "-O2", "-pipe" ], # "bar/*": { # "*.f90" : [ "=", "-O1" ] # }, # "baz/*": { # "*.f90" : [ "/", "-pipe" ], # "*.f90" : [ "/", "-O2" ], # "*.f90" : [ "+", "-O3" ] # } # } # # See ``examples/override-compile-flags`` in the ecBuild source tree for a # complete example using this technique. # ############################################################################## # We need to detect if the Fortran compiler is NEC, as it identifies as GNU # and some compiler flags are different than for GNU. # The resulting compiler ID "NEC" is then stored in ECBUILD_Fortran_COMPILER_ID # without modifying CMAKE_Fortran_COMPILER_ID. if( CMAKE_Fortran_COMPILER_LOADED ) set( _compiler_id ${CMAKE_Fortran_COMPILER_ID} ) if( NOT DEFINED ECBUILD_Fortran_COMPILER_ID AND CMAKE_Fortran_COMPILER_ID STREQUAL "GNU" ) try_compile( _is_nec ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_LIST_DIR}/determine-nec.F90 ) if( _is_nec ) ecbuild_info("NEC Fortran compiler detected") set( _compiler_id NEC ) endif() endif() set(ECBUILD_Fortran_COMPILER_ID ${_compiler_id} CACHE STRING "CMAKE_Fortran_COMPILER_ID") endif() include(ecbuild_compile_options) string( TOUPPER ${PROJECT_NAME} PROJECT_NAME_CAPS ) # Custom (project specific) compilation flags enabled? foreach( _flags COMPILE SOURCE ) if( ${PROJECT_NAME_CAPS}_ECBUILD_${_flags}_FLAGS ) if ( ECBUILD_${_flags}_FLAGS ) ecbuild_debug( "Override ECBUILD_${_flags}_FLAGS (${ECBUILD_${_flags}_FLAGS}) with ${PROJECT_NAME} specific flags (${${PROJECT_NAME_CAPS}_ECBUILD_${_flags}_FLAGS})" ) else() ecbuild_debug( "Use ${PROJECT_NAME} specific ECBUILD_${_flags}_FLAGS (${${PROJECT_NAME_CAPS}_ECBUILD_${_flags}_FLAGS})" ) endif() set( ECBUILD_${_flags}_FLAGS ${${PROJECT_NAME_CAPS}_ECBUILD_${_flags}_FLAGS} ) endif() endforeach() if( DEFINED ECBUILD_COMPILE_FLAGS ) ecbuild_override_compiler_flags( COMPILE_FLAGS ${ECBUILD_COMPILE_FLAGS} ) elseif( DEFINED ECBUILD_SOURCE_FLAGS ) ecbuild_override_compiler_flags( SOURCE_FLAGS ${ECBUILD_SOURCE_FLAGS} ) endif() foreach( _lang C CXX Fortran ) if( CMAKE_${_lang}_COMPILER_LOADED ) # Load default compilation flags only if custom compilation flags not enabled if( NOT (DEFINED ECBUILD_SOURCE_FLAGS OR DEFINED ECBUILD_COMPILE_FLAGS) ) ecbuild_compiler_flags( ${_lang} ) endif() endif() endforeach() if( NOT DEFINED ECBUILD_COMPILE_FLAGS AND NOT DEFINED ECBUILD_SOURCE_FLAGS ) ecbuild_linker_flags() endif() ecbuild-3.13.1/cmake/ecbuild_config.h.in000066400000000000000000000046311513706760700200200ustar00rootroot00000000000000/* * (C) Copyright 2011- ECMWF. * * This software is licensed under the terms of the Apache Licence Version 2.0 * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. * In applying this licence, ECMWF does not waive the privileges and immunities * granted to it by virtue of its status as an intergovernmental organisation nor * does it submit to any jurisdiction. */ #ifndef @PNAME@_ecbuild_config_h #define @PNAME@_ecbuild_config_h /* ecbuild info */ #ifndef ECBUILD_VERSION_STR #define ECBUILD_VERSION_STR "@ecbuild_VERSION_STR@" #endif #ifndef ECBUILD_VERSION #define ECBUILD_VERSION "@ecbuild_VERSION@" #endif #ifndef ECBUILD_MACROS_DIR #define ECBUILD_MACROS_DIR "@ECBUILD_MACROS_DIR@" #endif /* config info */ #define @PNAME@_OS_NAME "@CMAKE_SYSTEM@" #define @PNAME@_OS_BITS @EC_OS_BITS@ #define @PNAME@_OS_BITS_STR "@EC_OS_BITS@" #define @PNAME@_OS_STR "@EC_OS_NAME@.@EC_OS_BITS@" #define @PNAME@_OS_VERSION "@CMAKE_SYSTEM_VERSION@" #define @PNAME@_SYS_PROCESSOR "@CMAKE_SYSTEM_PROCESSOR@" #define @PNAME@_BUILD_TIMESTAMP "@EC_BUILD_TIMESTAMP@" #define @PNAME@_BUILD_TYPE "@CMAKE_BUILD_TYPE@" #define @PNAME@_C_COMPILER_ID "@CMAKE_C_COMPILER_ID@" #define @PNAME@_C_COMPILER_VERSION "@CMAKE_C_COMPILER_VERSION@" #define @PNAME@_CXX_COMPILER_ID "@CMAKE_CXX_COMPILER_ID@" #define @PNAME@_CXX_COMPILER_VERSION "@CMAKE_CXX_COMPILER_VERSION@" #define @PNAME@_C_COMPILER "@CMAKE_C_COMPILER@" #define @PNAME@_C_FLAGS "@EC_C_FLAGS@" #define @PNAME@_CXX_COMPILER "@CMAKE_CXX_COMPILER@" #define @PNAME@_CXX_FLAGS "@EC_CXX_FLAGS@" /* Needed for finding per package config files */ #define @PNAME@_INSTALL_DIR "@CMAKE_INSTALL_PREFIX@" #define @PNAME@_INSTALL_BIN_DIR "@CMAKE_INSTALL_PREFIX@/@INSTALL_BIN_DIR@" #define @PNAME@_INSTALL_LIB_DIR "@CMAKE_INSTALL_PREFIX@/@INSTALL_LIB_DIR@" #define @PNAME@_INSTALL_DATA_DIR "@CMAKE_INSTALL_PREFIX@/@INSTALL_DATA_DIR@" #define @PNAME@_DEVELOPER_SRC_DIR "@CMAKE_SOURCE_DIR@" #define @PNAME@_DEVELOPER_BIN_DIR "@CMAKE_BINARY_DIR@" /* Fortran support */ #if @EC_HAVE_FORTRAN@ #define @PNAME@_Fortran_COMPILER_ID "@CMAKE_Fortran_COMPILER_ID@" #define @PNAME@_Fortran_COMPILER_VERSION "@CMAKE_Fortran_COMPILER_VERSION@" #define @PNAME@_Fortran_COMPILER "@CMAKE_Fortran_COMPILER@" #define @PNAME@_Fortran_FLAGS "@EC_Fortran_FLAGS@" #endif #endif /* @PNAME@_ecbuild_config_h */ ecbuild-3.13.1/cmake/ecbuild_configure_file.cmake000066400000000000000000000020331513706760700217510ustar00rootroot00000000000000# (C) Copyright 2018- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation nor # does it submit to any jurisdiction. function(ecbuild_configure_file _PAR_TEMPLATE _PAR_FILENAME) get_filename_component(config_file ${_PAR_FILENAME} NAME) set(tmp_file "${CMAKE_CURRENT_BINARY_DIR}/${config_file}.ecbuild") configure_file( ${_PAR_TEMPLATE} ${tmp_file} ${ARGN}) file(STRINGS "${tmp_file}" content) string(REGEX MATCH "\\$ ... )``. :: # # ecbuild_declare_project() # # Sets the following CMake variables # # :_GIT_SHA1: Git revision (if project is a Git repo) # :_GIT_SHA1_SHORT: short Git revision (if project is a Git repo) # :_VERSION: version as given in project( VERSION ) # :_VERSION_MAJOR: major version number # :_VERSION_MINOR: minor version number # :_VERSION_PATCH: patch version number # :INSTALL_BIN_DIR: relative install directory for executables # :INSTALL_LIB_DIR: relative install directory for libraries # :INSTALL_INCLUDE_DIR: relative install directory for include files # :INSTALL_DATA_DIR: relative install directory for data # :INSTALL_CMAKE_DIR: relative install directory for CMake files # # Generation of the first two variables can be disabled by setting the # ECBUILD_RECORD_GIT_COMMIT_SHA1 option to OFF. This prevents # makefiles from being regenerated whenever the Git revision changes. # # Customising install locations # ----------------------------- # # The relative installation directories of components can be customised by # setting the following CMake variables on the command line or in cache: # # :INSTALL_BIN_DIR: directory for installing executables # (default: ``bin``) # :INSTALL_LIB_DIR: directory for installing libraries # (default: ``lib``) # :INSTALL_INCLUDE_DIR: directory for installing include files # (default: ``include``) # :INSTALL_DATA_DIR: directory for installing data # (default: ``share/``) # :INSTALL_CMAKE_DIR: directory for installing CMake files # (default: ``lib/cmake/``) # # Using *relative* paths is recommended, which are interpreted relative to the # ``CMAKE_INSTALL_PREFIX``. Using absolute paths makes the build # non-relocatable and may break the generation of relocatable binary packages. # ############################################################################## macro( ecbuild_declare_project ) if( NOT ${PROJECT_NAME}_DECLARED ) set( ${PROJECT_NAME}_DECLARED TRUE ) string( TOUPPER ${PROJECT_NAME} PNAME ) # reset the lists of targets (executables, libs, tests & resources) set( ${PROJECT_NAME}_ALL_EXES "" CACHE INTERNAL "" ) set( ${PROJECT_NAME}_ALL_LIBS "" CACHE INTERNAL "" ) # if git project get its HEAD SHA1 # leave it here so we may use ${PROJECT_NAME}_GIT_SHA1 on the version file if( (${ECBUILD_RECORD_GIT_COMMIT_SHA1}) AND (EXISTS ${PROJECT_SOURCE_DIR}/.git) ) get_git_head_revision( GIT_REFSPEC ${PROJECT_NAME}_GIT_SHA1 ) if( ${PROJECT_NAME}_GIT_SHA1 ) string( SUBSTRING "${${PROJECT_NAME}_GIT_SHA1}" 0 7 ${PROJECT_NAME}_GIT_SHA1_SHORT ) # ecbuild_debug_var( ${PROJECT_NAME}_GIT_SHA1 ) # ecbuild_debug_var( ${PROJECT_NAME}_GIT_SHA1_SHORT ) else() ecbuild_debug( "Could not get git-sha1 for project ${PROJECT_NAME}") endif() if( ECBUILD_2_COMPAT ) ecbuild_declare_compat( ${PNAME}_GIT_SHA1 ${PROJECT_NAME}_GIT_SHA1 ) ecbuild_declare_compat( ${PNAME}_GIT_SHA1_SHORT ${PROJECT_NAME}_GIT_SHA1_SHORT) endif() endif() if(NOT (DEFINED ${PROJECT_NAME}_VERSION AND DEFINED ${PROJECT_NAME}_VERSION_MAJOR)) if(ECBUILD_2_COMPAT) if(ECBUILD_2_COMPAT_DEPRECATE) ecbuild_deprecate("Please set a project version in the project() rather than using VERSION.cmake:\n\t project( ${PROJECT_NAME} VERSION x.x.x LANGUAGES C CXX Fortran )") endif() ecbuild_compat_setversion() else() ecbuild_critical("Please define a version for ${PROJECT_NAME}\n\tproject( ${PROJECT_NAME} VERSION x.x.x LANGUAGES C CXX Fortran )") endif() endif() if( NOT DEFINED ${PROJECT_NAME}_VERSION_STR ) set( ${PROJECT_NAME}_VERSION_STR ${${PROJECT_NAME}_VERSION} ) endif() if(ECBUILD_2_COMPAT) ecbuild_declare_compat( ${PNAME}_MAJOR_VERSION ${PROJECT_NAME}_VERSION_MAJOR ) ecbuild_declare_compat( ${PNAME}_MINOR_VERSION ${PROJECT_NAME}_VERSION_MINOR ) ecbuild_declare_compat( ${PNAME}_PATCH_VERSION ${PROJECT_NAME}_VERSION_PATCH ) ecbuild_declare_compat( ${PNAME}_VERSION_STR ${PROJECT_NAME}_VERSION_STR ) ecbuild_declare_compat( ${PNAME}_VERSION ${PROJECT_NAME}_VERSION ) endif() # install dirs for this project # Use defaults unless values are already present in cache include(GNUInstallDirs) if( NOT INSTALL_BIN_DIR ) set( INSTALL_BIN_DIR ${CMAKE_INSTALL_BINDIR} ) endif() if( NOT INSTALL_LIB_DIR ) set( INSTALL_LIB_DIR ${CMAKE_INSTALL_LIBDIR} ) endif() if( NOT INSTALL_INCLUDE_DIR ) set( INSTALL_INCLUDE_DIR ${CMAKE_INSTALL_INCLUDEDIR} ) endif() # INSTALL_DATA_DIR is package specific and needs to be reset for subpackages # in a bundle. Users *cannot* override this directory (ECBUILD-315) set( INSTALL_DATA_DIR share/${PROJECT_NAME} ) # The Modern CMake convention is to have the cmake directory in lib/cmake/${PROJECT_NAME} set( INSTALL_CMAKE_DIR ${INSTALL_LIB_DIR}/cmake/${PROJECT_NAME} ) mark_as_advanced( INSTALL_BIN_DIR ) mark_as_advanced( INSTALL_LIB_DIR ) mark_as_advanced( INSTALL_INCLUDE_DIR ) mark_as_advanced( INSTALL_DATA_DIR ) mark_as_advanced( INSTALL_CMAKE_DIR ) # warnings for non-relocatable projects foreach( p LIB BIN INCLUDE DATA CMAKE ) if( IS_ABSOLUTE ${INSTALL_${p}_DIR} ) ecbuild_warn( "Defining INSTALL_${p}_DIR as absolute path '${INSTALL_${p}_DIR}' makes this build non-relocatable, possibly breaking the installation of RPMS and DEB packages" ) endif() endforeach() # make relative paths absolute ( needed later on ) and cache them ... foreach( p LIB BIN INCLUDE DATA CMAKE ) set( var INSTALL_${p}_DIR ) if( NOT IS_ABSOLUTE "${${var}}" ) set( ${PROJECT_NAME}_FULL_INSTALL_${p}_DIR "${CMAKE_INSTALL_PREFIX}/${${var}}" CACHE INTERNAL "${PROJECT_NAME} ${p} full install path" ) else() ecbuild_warn( "Setting an absolute path for ${VAR} in project ${PNAME}, breakes generation of relocatable binary packages (rpm,deb,...)" ) set( ${PROJECT_NAME}_FULL_INSTALL_${p}_DIR "${${var}}" CACHE INTERNAL "${PROJECT_NAME} ${p} full install path" ) endif() if( ECBUILD_2_COMPAT ) ecbuild_declare_compat( ${PNAME}_FULL_INSTALL_${p}_DIR ${PROJECT_NAME}_FULL_INSTALL_${p}_DIR ) endif() # ecbuild_debug_var( ${PROJECT_NAME}_FULL_INSTALL_${p}_DIR ) endforeach() # correctly set CMAKE_INSTALL_RPATH if( ENABLE_RPATHS ) if( ENABLE_RELATIVE_RPATHS ) file( RELATIVE_PATH relative_rpath ${${PROJECT_NAME}_FULL_INSTALL_BIN_DIR} ${${PROJECT_NAME}_FULL_INSTALL_LIB_DIR} ) # ecbuild_debug_var( relative_rpath ) ecbuild_append_to_rpath( ${relative_rpath} ) else() # make rpaths absolute if( IS_ABSOLUTE ${INSTALL_LIB_DIR} ) ecbuild_append_to_rpath( "${INSTALL_LIB_DIR}" ) else() ecbuild_append_to_rpath( "${CMAKE_INSTALL_PREFIX}/${INSTALL_LIB_DIR}" ) endif() endif() endif() # make sure nothing breaks if INSTALL_LIB_DIR is not lib if( NOT INSTALL_LIB_DIR STREQUAL "lib" AND NOT EXISTS ${CMAKE_BINARY_DIR}/${INSTALL_LIB_DIR} ) execute_process( COMMAND ${CMAKE_COMMAND} -E create_symlink lib ${CMAKE_BINARY_DIR}/${INSTALL_LIB_DIR} ) endif() # ecbuild_debug_var( CMAKE_INSTALL_RPATH ) set( PROJECT_TARGETS_FILE "${PROJECT_BINARY_DIR}/${PROJECT_NAME}-targets.cmake" ) file( REMOVE ${PROJECT_TARGETS_FILE} ) # print project header ecbuild_info( "---------------------------------------------------------" ) unset( _version_str ) if( ${PROJECT_NAME}_VERSION_STR ) set( _version_str "(${${PROJECT_NAME}_VERSION_STR})" ) endif() if( ${PROJECT_NAME}_GIT_SHA1_SHORT ) ecbuild_info( "${Green}[${PROJECT_NAME}] ${_version_str} [${${PROJECT_NAME}_GIT_SHA1_SHORT}]${ColourReset}" ) else() ecbuild_info( "[${PROJECT_NAME}] ${_version_str}" ) endif() endif() # Define ${PROJECT_NAME}_DIR in PARENT_SCOPE so that a `find_package( )` in a bundle # will easily find the project without requiring a `HINT _BINARY_DIR` argument [ECBUILD-460] if( NOT CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR ) # Guard needed because PARENT_SCOPE cannot be used in top-level CMake project set( ${PROJECT_NAME}_DIR ${PROJECT_BINARY_DIR} PARENT_SCOPE ) endif() include( ecbuild_setup_test_framework ) # setup test framework ecbuild_add_option( FEATURE PKGCONFIG DEFAULT ON DESCRIPTION "Enable ecbuild_pkgconfig" ) endmacro( ecbuild_declare_project ) ecbuild-3.13.1/cmake/ecbuild_define_build_types.cmake000066400000000000000000000044371513706760700226400ustar00rootroot00000000000000# (C) Copyright 2011- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation nor # does it submit to any jurisdiction. ############################################################################################ # define default build type set( _BUILD_TYPE_MSG "Build type options defined by ecbuild are: [ None | Debug | Bit | Production | Release | RelWithDebInfo ]" ) if( NOT ECBUILD_DEFAULT_BUILD_TYPE ) set( ECBUILD_DEFAULT_BUILD_TYPE "RelWithDebInfo" ) endif() if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE ${ECBUILD_DEFAULT_BUILD_TYPE} CACHE STRING ${_BUILD_TYPE_MSG} FORCE ) endif() # capitalize the build type for easy use with conditionals string( TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_CAPS ) # correct capitalization of the build type if( CMAKE_BUILD_TYPE_CAPS STREQUAL "NONE" ) set(CMAKE_BUILD_TYPE None CACHE STRING ${_BUILD_TYPE_MSG} FORCE ) endif() if( CMAKE_BUILD_TYPE_CAPS STREQUAL "DEBUG" ) set(CMAKE_BUILD_TYPE Debug CACHE STRING ${_BUILD_TYPE_MSG} FORCE ) endif() if( CMAKE_BUILD_TYPE_CAPS STREQUAL "BIT" ) set(CMAKE_BUILD_TYPE Bit CACHE STRING ${_BUILD_TYPE_MSG} FORCE ) endif() if( CMAKE_BUILD_TYPE_CAPS STREQUAL "PRODUCTION" ) set(CMAKE_BUILD_TYPE Production CACHE STRING ${_BUILD_TYPE_MSG} FORCE ) endif() if( CMAKE_BUILD_TYPE_CAPS STREQUAL "RELEASE" ) set(CMAKE_BUILD_TYPE Release CACHE STRING ${_BUILD_TYPE_MSG} FORCE ) endif() if( CMAKE_BUILD_TYPE_CAPS STREQUAL "RELWITHDEBINFO" ) set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING ${_BUILD_TYPE_MSG} FORCE ) endif() # warn if build type is not one of the defined ones if( NOT CMAKE_BUILD_TYPE MATCHES "None" AND NOT CMAKE_BUILD_TYPE MATCHES "Debug" AND NOT CMAKE_BUILD_TYPE MATCHES "Bit" AND NOT CMAKE_BUILD_TYPE MATCHES "Production" AND NOT CMAKE_BUILD_TYPE MATCHES "Release" AND NOT CMAKE_BUILD_TYPE MATCHES "RelWithDebInfo" ) ecbuild_warn( "CMAKE_BUILD_TYPE has an unusual value (\"${CMAKE_BUILD_TYPE_CAPS}\"). ${_BUILD_TYPE_MSG}. Please make sure your build system correctly handles CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}.") endif() ecbuild-3.13.1/cmake/ecbuild_define_options.cmake000066400000000000000000000035751513706760700220120ustar00rootroot00000000000000# (C) Copyright 2011- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation nor # does it submit to any jurisdiction. # general options option( BUILD_SHARED_LIBS "build shared libraries when possible" ON ) option( ENABLE_RPATHS "when installing insert RPATHS into binaries" ON ) mark_as_advanced( ENABLE_RPATHS ) option( ENABLE_RELATIVE_RPATHS "try to use relative RPATHS, including build dir" ON ) mark_as_advanced( ENABLE_RELATIVE_RPATHS ) option( ENABLE_LARGE_FILE_SUPPORT "build with large file support" ON ) mark_as_advanced( ENABLE_LARGE_FILE_SUPPORT ) option( ENABLE_PROFILING "build with profiling support" OFF ) mark_as_advanced( ENABLE_PROFILING ) option( ENABLE_FORTRAN_C_INTERFACE "Enable Fortran/C Interface" OFF ) mark_as_advanced( ENABLE_FORTRAN_C_INTERFACE ) option( CHECK_UNUSED_FILES "check for unused project files (slow)" OFF ) mark_as_advanced( CHECK_UNUSED_FILES ) option( ECBUILD_INSTALL_LIBRARY_HEADERS "Will install library headers" ON ) mark_as_advanced( ECBUILD_INSTALL_LIBRARY_HEADERS ) option( ECBUILD_INSTALL_FORTRAN_MODULES "Will install Fortran modules" ON ) mark_as_advanced( ECBUILD_INSTALL_FORTRAN_MODULES ) option( ECBUILD_RECORD_GIT_COMMIT_SHA1 "When building ecbuild projects that are Git repos, create variables recording the full and short Git revision" ON ) mark_as_advanced( ECBUILD_RECORD_GIT_COMMIT_SHA1 ) include( CMakeDependentOption ) # make options depend on one another set( CMAKE_NO_SYSTEM_FROM_IMPORTED ON ) # hide some CMake options from CMake UI mark_as_advanced( CMAKE_OSX_ARCHITECTURES CMAKE_OSX_DEPLOYMENT_TARGET CMAKE_OSX_SYSROOT ) ecbuild-3.13.1/cmake/ecbuild_define_paths.cmake000066400000000000000000000026461513706760700214340ustar00rootroot00000000000000# (C) Copyright 2011- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation nor # does it submit to any jurisdiction. # define project paths file( MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/bin ) file( MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/lib ) ####################################################################################################### # setup library building rpaths (both in build dir and then when installed) # add the automatic parts to RPATH which point to dirs outside build tree set( CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE ) # use RPATHs for the build tree set( CMAKE_SKIP_BUILD_RPATH FALSE ) # build with *relative* rpaths by default if( ENABLE_RELATIVE_RPATHS ) set( CMAKE_BUILD_WITH_INSTALL_RPATH TRUE ) else() # in case the RPATH is absolute, the install RPATH cannot be set # at build-time since it breaks the build tree dynamic links set( CMAKE_BUILD_WITH_INSTALL_RPATH FALSE ) endif() # put the include dirs which are in the source or build tree # before all other include dirs, so the headers in the sources # are prefered over the already installed ones (since cmake 2.4.1) set( CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE ON ) ecbuild-3.13.1/cmake/ecbuild_define_properties.cmake000066400000000000000000000017311513706760700225030ustar00rootroot00000000000000# (C) Copyright 2011- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation nor # does it submit to any jurisdiction. ############################################################################################ # define custom properties ############################################################################################ # source properties: # Custom property to determine if compiler flags have been applied yet: define_property( SOURCE PROPERTY CUSTOM_FLAGS BRIEF_DOCS "Custom compiler flags have been applied to source file" FULL_DOCS "Compiler flags have been applied to the source file, using custom CMake rules. Assists processing of sources that are used by multiple targets. Treated as Boolean." ) ecbuild-3.13.1/cmake/ecbuild_dont_pack.cmake000066400000000000000000000055161513706760700207440ustar00rootroot00000000000000# (C) Copyright 2011- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation # nor does it submit to any jurisdiction. ############################################################################## #.rst: # # ecbuild_dont_pack # ================= # # Specify files and directories to exclude from packaging. :: # # ecbuild_dont_pack( [ FILES [ ... ] ] # [ DIRS [ ... ] ] # [ REGEX ] ) # # Options # ------- # # FILES : optional, one of FILES, DIRS, REGEX required # list of files to exclude from packaging # # DIRS : optional, one of FILES, DIRS, REGEX required # list of directories to exclude from packaging # # REGEX : optional, one of FILES, DIRS, REGEX required # regular expression to match files / directories to exclude from packaging # ############################################################################## macro( ecbuild_dont_pack ) set( options ) set( single_value_args REGEX ) set( multi_value_args FILES DIRS ) cmake_parse_arguments( _PAR "${options}" "${single_value_args}" "${multi_value_args}" ${_FIRST_ARG} ${ARGN} ) if(_PAR_UNPARSED_ARGUMENTS) ecbuild_critical("Unknown keywords given to ecbuild_dont_pack(): \"${_PAR_UNPARSED_ARGUMENTS}\"") endif() if( NOT DEFINED _PAR_REGEX AND NOT DEFINED _PAR_FILES AND NOT DEFINED _PAR_DIRS ) ecbuild_critical("Call to ecbuild_dont_pack does not speficify any list to avoid packing.") endif() set( LOCAL_FILES_NOT_TO_PACK "" ) # all recursive files are not to pack if( DEFINED _PAR_REGEX ) file( GLOB_RECURSE all_files_in_subdirs RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${_PAR_REGEX} ) list( APPEND LOCAL_FILES_NOT_TO_PACK ${all_files_in_subdirs} ) endif() # selected dirs not to pack if( DEFINED _PAR_DIRS ) foreach( dir ${_PAR_DIRS} ) list( APPEND LOCAL_FILES_NOT_TO_PACK ${dir}/ ) endforeach() endif() # selected files not to pack if( DEFINED _PAR_FILES ) list( APPEND LOCAL_FILES_NOT_TO_PACK ${_PAR_FILES} ) endif() # transform the local files to full absolute paths # and place them in the global list of files not to pack foreach( file ${LOCAL_FILES_NOT_TO_PACK} ) list( APPEND ECBUILD_DONT_PACK_FILES ${CMAKE_CURRENT_SOURCE_DIR}/${file} ) endforeach() # save cache if we added any files not to pack if( LOCAL_FILES_NOT_TO_PACK ) list(REMOVE_DUPLICATES ECBUILD_DONT_PACK_FILES) set( ECBUILD_DONT_PACK_FILES ${ECBUILD_DONT_PACK_FILES} CACHE INTERNAL "" ) endif() endmacro() ecbuild-3.13.1/cmake/ecbuild_download_resource.cmake000066400000000000000000000051071513706760700225140ustar00rootroot00000000000000# (C) Copyright 2011- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation # nor does it submit to any jurisdiction. ############################################################################## #.rst: # # ecbuild_download_resource # ========================= # # Download a file from a given URL and save to FILE at configure time. :: # # ecbuild_download_resource( FILE URL ) # # curl or wget is required (curl is preferred if available). # # The default timeout is 30 seconds, which can be overridden with # ``ECBUILD_DOWNLOAD_TIMEOUT``. Downloads are by default only tried once, use # ``ECBUILD_DOWNLOAD_RETRIES`` to set the number of retries. # ############################################################################## function( ecbuild_download_resource _p_OUT _p_URL ) # Do not retry downloads by default (ECBUILD-307) if( NOT DEFINED ECBUILD_DOWNLOAD_RETRIES ) set( ECBUILD_DOWNLOAD_RETRIES 0 ) endif() # Use default timeout of 30s if not specified (ECBUILD-307) if( NOT DEFINED ECBUILD_DOWNLOAD_TIMEOUT ) set( ECBUILD_DOWNLOAD_TIMEOUT 30 ) endif() if( NOT EXISTS ${_p_OUT} ) find_program( CURL_PROGRAM curl ) mark_as_advanced(CURL_PROGRAM) if( CURL_PROGRAM ) execute_process( COMMAND ${CURL_PROGRAM} --silent --show-error --fail --retry ${ECBUILD_DOWNLOAD_RETRIES} --connect-timeout ${ECBUILD_DOWNLOAD_TIMEOUT} --output ${_p_OUT} ${_p_URL} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} RESULT_VARIABLE CMD_RESULT ) else() find_program( WGET_PROGRAM wget ) if( WGET_PROGRAM ) # wget takes the total number of tries, curl the number or retries math( EXPR ECBUILD_DOWNLOAD_RETRIES ${ECBUILD_DOWNLOAD_RETRIES} + 1 ) execute_process( COMMAND ${WGET_PROGRAM} -nv -O ${_p_OUT} -t ${ECBUILD_DOWNLOAD_RETRIES} -T ${ECBUILD_DOWNLOAD_TIMEOUT} ${_p_URL} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} RESULT_VARIABLE CMD_RESULT ) else() ecbuild_critical("Could not find curl or wget. Error downloading ${_p_URL}") endif() endif() if(CMD_RESULT) ecbuild_critical("Error downloading ${_p_URL}") endif() endif() endfunction() ecbuild-3.13.1/cmake/ecbuild_echo_targets.cmake000066400000000000000000000126721513706760700214520ustar00rootroot00000000000000# (C) Copyright 2011- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation # nor does it submit to any jurisdiction. ############################################################################## #.rst: # # ecbuild_echo_target_property # ============================ # # Output a given property of a given target. :: # # ecbuild_echo_target_property( ) # ############################################################################## function(ecbuild_echo_target_property tgt prop) cmake_policy(PUSH) if( POLICY CMP0026 ) cmake_policy( SET CMP0026 OLD) endif() # v for value, d for defined, s for set get_property(v TARGET ${tgt} PROPERTY ${prop}) get_property(d TARGET ${tgt} PROPERTY ${prop} DEFINED) get_property(s TARGET ${tgt} PROPERTY ${prop} SET) # only produce output for values that are set if(s) ecbuild_debug("tgt='${tgt}' prop='${prop}'") ecbuild_debug(" value='${v}'") ecbuild_debug(" defined='${d}'") ecbuild_debug(" set='${s}'") ecbuild_debug("") endif() cmake_policy(POP) endfunction() ############################################################################## #.rst: # # ecbuild_echo_target # =================== # # Output all possible target properties of a given target. :: # # ecbuild_echo_target( ) # ############################################################################## function(ecbuild_echo_target tgt) if(NOT TARGET ${tgt}) ecbuild_debug("There is no target named '${tgt}'") return() endif() set(props DEBUG_OUTPUT_NAME DEBUG_POSTFIX RELEASE_OUTPUT_NAME RELEASE_POSTFIX ARCHIVE_OUTPUT_DIRECTORY ARCHIVE_OUTPUT_DIRECTORY_DEBUG ARCHIVE_OUTPUT_DIRECTORY_RELEASE ARCHIVE_OUTPUT_NAME ARCHIVE_OUTPUT_NAME_DEBUG ARCHIVE_OUTPUT_NAME_RELEASE AUTOMOC AUTOMOC_MOC_OPTIONS BUILD_WITH_INSTALL_RPATH BUNDLE BUNDLE_EXTENSION COMPILE_DEFINITIONS COMPILE_DEFINITIONS_DEBUG COMPILE_DEFINITIONS_RELEASE COMPILE_FLAGS DEBUG_POSTFIX RELEASE_POSTFIX DEFINE_SYMBOL ENABLE_EXPORTS EXCLUDE_FROM_ALL EchoString FOLDER FRAMEWORK Fortran_FORMAT Fortran_MODULE_DIRECTORY GENERATOR_FILE_NAME GNUtoMS HAS_CXX IMPLICIT_DEPENDS_INCLUDE_TRANSFORM IMPORTED IMPORTED_CONFIGURATIONS IMPORTED_IMPLIB IMPORTED_IMPLIB_DEBUG IMPORTED_IMPLIB_RELEASE IMPORTED_LINK_DEPENDENT_LIBRARIES IMPORTED_LINK_DEPENDENT_LIBRARIES_DEBUG IMPORTED_LINK_DEPENDENT_LIBRARIES_RELEASE IMPORTED_LINK_INTERFACE_LANGUAGES IMPORTED_LINK_INTERFACE_LANGUAGES_DEBUG IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE IMPORTED_LINK_INTERFACE_LIBRARIES IMPORTED_LINK_INTERFACE_LIBRARIES_DEBUG IMPORTED_LINK_INTERFACE_LIBRARIES_RELEASE IMPORTED_LINK_INTERFACE_MULTIPLICITY IMPORTED_LINK_INTERFACE_MULTIPLICITY_DEBUG IMPORTED_LINK_INTERFACE_MULTIPLICITY_RELEASE IMPORTED_LOCATION IMPORTED_LOCATION_DEBUG IMPORTED_LOCATION_RELEASE IMPORTED_NO_SONAME IMPORTED_NO_SONAME_DEBUG IMPORTED_NO_SONAME_RELEASE IMPORTED_SONAME IMPORTED_SONAME_DEBUG IMPORTED_SONAME_RELEASE IMPORT_PREFIX IMPORT_SUFFIX INCLUDE_DIRECTORIES INSTALL_NAME_DIR INSTALL_RPATH INSTALL_RPATH_USE_LINK_PATH INTERPROCEDURAL_OPTIMIZATION INTERPROCEDURAL_OPTIMIZATION_DEBUG INTERPROCEDURAL_OPTIMIZATION_RELEASE LABELS LIBRARY_OUTPUT_DIRECTORY LIBRARY_OUTPUT_DIRECTORY_DEBUG LIBRARY_OUTPUT_DIRECTORY_RELEASE LIBRARY_OUTPUT_NAME LIBRARY_OUTPUT_NAME_DEBUG LIBRARY_OUTPUT_NAME_RELEASE LINKER_LANGUAGE LINK_DEPENDS LINK_FLAGS LINK_FLAGS_DEBUG LINK_FLAGS_RELEASE LINK_INTERFACE_LIBRARIES LINK_INTERFACE_LIBRARIES_DEBUG LINK_INTERFACE_LIBRARIES_RELEASE LINK_INTERFACE_MULTIPLICITY LINK_INTERFACE_MULTIPLICITY_DEBUG LINK_INTERFACE_MULTIPLICITY_RELEASE LINK_SEARCH_END_STATIC LINK_SEARCH_START_STATIC LOCATION LOCATION_DEBUG LOCATION_RELEASE MACOSX_BUNDLE MACOSX_BUNDLE_INFO_PLIST MACOSX_FRAMEWORK_INFO_PLIST MAP_IMPORTED_CONFIG_DEBUG MAP_IMPORTED_CONFIG_RELEASE OSX_ARCHITECTURES OSX_ARCHITECTURES_DEBUG OSX_ARCHITECTURES_RELEASE OUTPUT_NAME OUTPUT_NAME_DEBUG OUTPUT_NAME_RELEASE POST_INSTALL_SCRIPT PREFIX PRE_INSTALL_SCRIPT PRIVATE_HEADER PROJECT_LABEL PUBLIC_HEADER RESOURCE RULE_LAUNCH_COMPILE RULE_LAUNCH_CUSTOM RULE_LAUNCH_LINK RUNTIME_OUTPUT_DIRECTORY RUNTIME_OUTPUT_DIRECTORY_DEBUG RUNTIME_OUTPUT_DIRECTORY_RELEASE RUNTIME_OUTPUT_NAME RUNTIME_OUTPUT_NAME_DEBUG RUNTIME_OUTPUT_NAME_RELEASE SKIP_BUILD_RPATH SOURCES SOVERSION STATIC_LIBRARY_FLAGS STATIC_LIBRARY_FLAGS_DEBUG STATIC_LIBRARY_FLAGS_RELEASE SUFFIX TYPE VERSION VS_DOTNET_REFERENCES VS_GLOBAL_WHATEVER VS_GLOBAL_KEYWORD VS_GLOBAL_PROJECT_TYPES VS_KEYWORD VS_SCC_AUXPATH VS_SCC_LOCALPATH VS_SCC_PROJECTNAME VS_SCC_PROVIDER VS_WINRT_EXTENSIONS VS_WINRT_REFERENCES WIN32_EXECUTABLE XCODE_ATTRIBUTE_WHATEVER ) ecbuild_debug("======================== ${tgt} ========================") foreach(p ${props}) ecbuild_echo_target_property("${tgt}" "${p}") endforeach() ecbuild_debug("") endfunction() ############################################################################## #.rst: # # ecbuild_echo_targets # ==================== # # Output all possible target properties of the specified list-of-targets. # This is very useful for debugging. :: # # ecbuild_echo_targets( ) # ############################################################################## function(ecbuild_echo_targets) set(tgts ${ARGV}) foreach(t ${tgts}) ecbuild_echo_target("${t}") endforeach() endfunction() ecbuild-3.13.1/cmake/ecbuild_enable_fortran.cmake000066400000000000000000000057351513706760700217660ustar00rootroot00000000000000# (C) Copyright 2011- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation nor # does it submit to any jurisdiction. ############################################################################## #.rst: # # ecbuild_enable_fortran # ====================== # # Enable the Fortran language. :: # # ecbuild_enable_fortran( [ MODULE_DIRECTORY ] [ REQUIRED ] ) # # Options # ------- # # MODULE_DIRECTORY : optional, defaults to ``${PROJECT_BINARY_DIR}/module`` # set the CMAKE_Fortran_MODULE_DIRECTORY # # NO_MODULE_DIRECTORY : optional # unset CMAKE_Fortran_MODULE_DIRECTORY # # REQUIRED : optional # fail if no working Fortran compiler was detected # ############################################################################## macro( ecbuild_enable_fortran ) set( options REQUIRED NO_MODULE_DIRECTORY ) set( single_value_args MODULE_DIRECTORY ) set( multi_value_args ) cmake_parse_arguments( _PAR "${options}" "${single_value_args}" "${multi_value_args}" ${_FIRST_ARG} ${ARGN} ) if(_PAR_UNPARSED_ARGUMENTS) ecbuild_critical("Unknown keywords given to ecbuild_enable_fortran(): \"${_PAR_UNPARSED_ARGUMENTS}\"") endif() if( NOT CMAKE_Fortran_COMPILER_LOADED ) enable_language( Fortran ) ecbuild_compiler_flags( Fortran ) endif() if( _PAR_REQUIRED ) if( CMAKE_Fortran_COMPILER_FORCED ) set( CMAKE_Fortran_COMPILER_WORKS 1 ) endif() if( NOT CMAKE_Fortran_COMPILER OR NOT CMAKE_Fortran_COMPILER_WORKS ) ecbuild_critical( "Fortran compiler required by project ${PROJECT_NAME} but does not seem to work" ) endif() endif() if( CMAKE_Fortran_COMPILER_LOADED ) include(CheckFortranFunctionExists) if( CMAKE_C_COMPILER_LOADED AND ENABLE_FORTRAN_C_INTERFACE ) include(FortranCInterface) endif() set( EC_HAVE_FORTRAN 1 ) # see issue ECBUILD-298 if( CMAKE_Fortran_COMPILER_ID MATCHES PGI ) unset( CMAKE_Fortran_COMPILE_OPTIONS_PIE ) unset( CMAKE_SHARED_LIBRARY_LINK_Fortran_FLAGS ) endif() endif() if( _PAR_NO_MODULE_DIRECTORY ) unset( CMAKE_Fortran_MODULE_DIRECTORY ) else() if( _PAR_MODULE_DIRECTORY ) set( CMAKE_Fortran_MODULE_DIRECTORY ${_PAR_MODULE_DIRECTORY} ) else() set( CMAKE_Fortran_MODULE_DIRECTORY ${PROJECT_BINARY_DIR}/module ) endif() file( MAKE_DIRECTORY ${CMAKE_Fortran_MODULE_DIRECTORY} ) if( ECBUILD_2_COMPAT ) include_directories( ${CMAKE_Fortran_MODULE_DIRECTORY} ) endif() # We should also not auto-install. Every project is already doing this anyway # install( CODE "EXECUTE_PROCESS (COMMAND \"${CMAKE_COMMAND}\" -E copy_directory \"${CMAKE_Fortran_MODULE_DIRECTORY}/\${BUILD_TYPE}\" \"${INSTALL_INCLUDE_DIR}\")" ) endif() endmacro( ecbuild_enable_fortran ) ecbuild-3.13.1/cmake/ecbuild_evaluate_dynamic_condition.cmake000066400000000000000000000023111513706760700243500ustar00rootroot00000000000000# (C) Copyright 2018- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation nor # does it submit to any jurisdiction. ############################################################################## #.rst: # # ecbuild_evaluate_dynamic_condition # ================================== # # Add a CMake configuration option, which may depend on a list of packages. :: # # ecbuild_evaluate_dynamic_condition( condition outVariable ) # # Options # ------- # condition A list of boolean statements like OPENSSL_FOUND AND ENABLE_OPENSSL # function(ecbuild_evaluate_dynamic_condition _conditions _outVar) if( DEFINED ${_conditions}) if(${${_conditions}}) set( ${_outVar} TRUE ) else() set( ${_outVar} FALSE ) endif() else() set( ${_outVar} TRUE ) endif() ecbuild_debug("ecbuild_evaluate_dynamic_condition(${_outVar}): checking condition '${${_conditions}}' -> ${${_outVar}}") set( ${_outVar} ${${_outVar}} PARENT_SCOPE ) endfunction() ecbuild-3.13.1/cmake/ecbuild_features.cmake000066400000000000000000000044271513706760700206200ustar00rootroot00000000000000# (C) Copyright 2011- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation # nor does it submit to any jurisdiction. # Internal macros to handle CMake features include( FeatureSummary ) # Write list of enabled features to CMake variable ${OUT} macro( ecbuild_enabled_features OUT ) get_property( ${OUT} GLOBAL PROPERTY ENABLED_FEATURES ) endmacro() # Write list of disabled features to CMake variable ${OUT} macro( ecbuild_disabled_features OUT ) get_property( ${OUT} GLOBAL PROPERTY DISABLED_FEATURES ) endmacro() # Enable the feature ${_name} (add to enabled features, remove from disabled) function( ecbuild_enable_feature _name ) get_property( _enabled_features GLOBAL PROPERTY ENABLED_FEATURES ) get_property( _disabled_features GLOBAL PROPERTY DISABLED_FEATURES ) if( _disabled_features ) list( REMOVE_ITEM _disabled_features ${_name} ) endif() list( APPEND _enabled_features ${_name} ) list( REMOVE_DUPLICATES _enabled_features ) set_property(GLOBAL PROPERTY ENABLED_FEATURES "${_enabled_features}" ) set_property(GLOBAL PROPERTY DISABLED_FEATURES "${_disabled_features}" ) endfunction() # Disable the feature ${_name} (add to disabled features, remove from enabled) function( ecbuild_disable_feature _name ) get_property( _enabled_features GLOBAL PROPERTY ENABLED_FEATURES ) get_property( _disabled_features GLOBAL PROPERTY DISABLED_FEATURES ) if( _enabled_features ) list( REMOVE_ITEM _enabled_features ${_name} ) endif() list( APPEND _disabled_features ${_name} ) list( REMOVE_DUPLICATES _disabled_features ) set_property(GLOBAL PROPERTY ENABLED_FEATURES "${_enabled_features}" ) set_property(GLOBAL PROPERTY DISABLED_FEATURES "${_disabled_features}" ) endfunction() # Disable the feature ${_name} globally (if it has not been enabled in any subproject) function( ecbuild_disable_unused_feature _name ) get_property( _enabled GLOBAL PROPERTY ENABLED_FEATURES ) if ( _name IN_LIST _enabled ) # if not already disabled ecbuild_disable_feature( ${_name} ) endif() endfunction() ecbuild-3.13.1/cmake/ecbuild_filter_list.cmake000066400000000000000000000045311513706760700213160ustar00rootroot00000000000000# (C) Copyright 2018- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation nor # does it submit to any jurisdiction. ############################################################################## #.rst: # # ecbuild_filter_list # =================== # # Filters a list for NOTFOUND entries and non existing TARGETS. :: # # ecbuild_filter_list( [INCLUDES] [LIBS] # LIST # [LIST_INCLUDE ] # [LIST_EXCLUDE ]) # # Options # ------- # # INCLUDES : optional # Consider existing dirs as valid # # LIBS : optional # Consider existing targets, files and compile flags as valid # # LIST : required # a list # # LIST_INCLUDE : optional # The output list with all valid entries of LIST # # LIST_EXCLUDE : optional # The output list with all invalid entries of LIST # function(ecbuild_filter_list) set(options INCLUDES LIBS) set(single_value_args LIST_INCLUDE LIST_EXCLUDE) set(multi_value_args LIST) cmake_parse_arguments(_PAR "${options}" "${single_value_args}" "${multi_value_args}" ${ARGN}) set(__listIn ${_PAR_LIST}) set(__listOut) set(__listOutSkip) if(NOT DEFINED ECBUILD_NO_FILTER_DEPS) list(REMOVE_DUPLICATES __listIn) foreach(lib ${__listIn}) if(_PAR_INCLUDES AND IS_DIRECTORY "${lib}") list(APPEND __listOut ${lib}) elseif(_PAR_LIBS AND TARGET "${lib}") list(APPEND __listOut ${lib}) elseif(_PAR_LIBS AND "${lib}" MATCHES "^-") list(APPEND __listOut ${lib}) elseif(_PAR_LIBS AND EXISTS "${lib}") list(APPEND __listOut ${lib}) elseif(lib) list(APPEND __listOut ${lib}) else() list(APPEND __listOutSkip ${lib}) endif() endforeach() else() set(__listOut ${__listIn}) endif() if(_PAR_LIST_INCLUDE) set(${_PAR_LIST_INCLUDE} ${__listOut} PARENT_SCOPE) endif() if(_PAR_LIST_EXCLUDE) set(${_PAR_LIST_EXCLUDE} ${__listOutSkip} PARENT_SCOPE) endif() endfunction() ecbuild-3.13.1/cmake/ecbuild_find_fortranlibs.cmake000066400000000000000000000110721513706760700223210ustar00rootroot00000000000000# (C) Copyright 2011- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation # nor does it submit to any jurisdiction. ############################################################################## #.rst: # # ecbuild_find_fortranlibs # ======================== # # Find the Fortran (static) link libraries. :: # # ecbuild_find_fortranlibs( [ COMPILER gfortran|pgi|xlf|intel ] # [ REQUIRED ] ) # # Options # ------- # # COMPILER : optional, defaults to gfortran # request a given Fortran compiler (``gfortran``, ``pgi``, ``xlf``, ``intel``) # # REQUIRED : optional # fail if Fortran libraries were not found # ############################################################################## macro( ecbuild_find_fortranlibs ) ecbuild_deprecate( "ecbuild_find_fortranlibs is deprecated and will be removed in an upcoming ecBuild release" ) # parse parameters set( options REQUIRED ) set( single_value_args COMPILER ) set( multi_value_args ) cmake_parse_arguments( _PAR "${options}" "${single_value_args}" "${multi_value_args}" ${_FIRST_ARG} ${ARGN} ) if(_PAR_UNPARSED_ARGUMENTS) ecbuild_critical("Unknown keywords given to ecbuild_find_fortranlibs(): \"${_PAR_UNPARSED_ARGUMENTS}\"") endif() if( NOT FORTRANLIBS_FOUND ) # don't repeat search if( _PAR_COMPILER ) set( __known_fcomp 0 ) endif() if( _PAR_COMPILER MATCHES "gfortran" ) set( WITH_LIBGFORTRAN 1 ) set( __known_fcomp 1 ) endif() if( _PAR_COMPILER MATCHES "pgi" ) set( WITH_PGI_FORTRAN 1 ) set( __known_fcomp 1 ) endif() if( _PAR_COMPILER MATCHES "xlf" ) set( WITH_XL_FORTRAN 1 ) set( __known_fcomp 1 ) endif() if( _PAR_COMPILER MATCHES "intel" ) set( WITH_INTEL_FORTRAN 1 ) set( __known_fcomp 1 ) endif() if( _PAR_COMPILER AND NOT __known_fcomp ) ecbuild_critical( "unknown fortran compiler ${_PAR_COMPILER}" ) endif() ### set path from environment variables foreach( _fortran_lib PGI XLF LIBGFORTRAN INTEL ) if( NOT ${_fortran_lib}_PATH AND NOT "$ENV{${_fortran_lib}_PATH}" STREQUAL "" ) set( ${_fortran_lib}_PATH "$ENV{${_fortran_lib}_PATH}" ) endif() endforeach() set( _flibs_found 0 ) ### default is to search for gfortran if( NOT (WITH_PGI_FORTRAN OR WITH_LIBGFORTRAN OR WITH_XL_FORTRAN OR WITH_INTEL_FORTRAN) AND NOT (DEFINED PGI_PATH OR DEFINED LIBGFORTRAN_PATH OR DEFINED XLF_PATH OR DEFINED INTEL_PATH) ) ecbuild_warn( "Finding fortran libs for unspecified Fortran compiler: default search [ gfortran ]" ) set( WITH_LIBGFORTRAN 1 ) endif() ### actual search ... if( WITH_PGI_FORTRAN OR DEFINED PGI_PATH ) find_package(PGIFortran) if( LIBPGIFORTRAN_FOUND ) set( FORTRAN_LIBRARIES ${PGIFORTRAN_LIBRARIES} ) set( _flibs_found 1 ) set( _flibs_txt "PGI" ) endif() endif() if( WITH_LIBGFORTRAN OR DEFINED LIBGFORTRAN_PATH ) find_package(LibGFortran) if( LIBGFORTRAN_FOUND ) set( FORTRAN_LIBRARIES ${GFORTRAN_LIBRARIES} ) set( _flibs_found 1 ) set( _flibs_txt "gfortran" ) endif() endif() if( WITH_XL_FORTRAN OR DEFINED XLF_PATH ) find_package(XLFortranLibs) if( LIBXLFORTRAN_FOUND ) set( FORTRAN_LIBRARIES ${XLFORTRAN_LIBRARIES} ) set( _flibs_found 1 ) set( _flibs_txt "XLF" ) endif() endif() if( WITH_INTEL_FORTRAN OR DEFINED INTEL_PATH ) find_package(LibIFort) if( LIBIFORT_FOUND ) set( FORTRAN_LIBRARIES ${IFORT_LIBRARIES} ) set( _flibs_found 1 ) set( _flibs_txt "Intel" ) endif() endif() ### set found if( _flibs_found ) set( FORTRANLIBS_FOUND 1 CACHE INTERNAL "Fortran libraries found" ) set( FORTRANLIBS_NAME ${_flibs_txt} CACHE INTERNAL "Fortran library name" ) set( FORTRAN_LIBRARIES ${FORTRAN_LIBRARIES} CACHE INTERNAL "Fortran libraries" ) ecbuild_info( "Found Fortran libraries: ${_flibs_txt}" ) else() set( FORTRANLIBS_FOUND 0 ) if( _PAR_REQUIRED ) ecbuild_critical( "Failed to find Fortran libraries" ) else() ecbuild_warn( "Failed to find Fortran libraries" ) endif() endif() endif( NOT FORTRANLIBS_FOUND ) endmacro( ecbuild_find_fortranlibs ) ecbuild-3.13.1/cmake/ecbuild_find_lexyacc.cmake000066400000000000000000000057411513706760700214320ustar00rootroot00000000000000# (C) Copyright 2011- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation nor # does it submit to any jurisdiction. ############################################################################## #.rst: # # ecbuild_find_lexyacc # ==================== # # Find flex and bison (preferred) or lex and yacc. # # Input variables # --------------- # # The following CMake variables can set to skip search for bison or yacc: # # :SKIP_BISON: do not search for flex and bison # :SKIP_YACC: do not search for lex and yacc # # Output variables # ---------------- # # The following CMake variables are set if flex and bison were found: # # :FLEX_FOUND: flex was found # :BISON_FOUND: bison was found # :FLEX_EXECUTABLE: path to the flex executable # :BISON_EXECUTABLE: path to the bison executable # # The following CMake variables are set if lex and yacc were found: # # :LEXYACC_FOUND: Found suitable combination of bison, lex, yacc, flex # :LEX_FOUND: lex was found # :YACC_FOUND: yacc was found # :LEX_EXECUTABLE: path to the lex executable # :YACC_EXECUTABLE: path to the yacc executable # ############################################################################## macro( ecbuild_find_lexyacc ) # find preferably bison or else yacc if( NOT SKIP_BISON ) find_package( BISON ) if(BISON_FOUND AND BISON_VERSION VERSION_LESS 2.3 ) ecbuild_critical( "Bison found with version ${BISON_VERSION} is less than 2.3.\nPlease define BISON_EXECUTABLE to an appropriate version or define SKIP_BISON to try finding Yacc instead" ) endif() find_package( FLEX ) endif() if( NOT BISON_FOUND AND NOT SKIP_YACC ) find_package( YACC ) find_package( LEX ) endif() set( LEXYACC_FOUND 1 ) if( NOT YACC_FOUND AND NOT BISON_FOUND ) # neither bison nor yacc were found ecbuild_debug( "Neither bison or yacc were found - at least one is required (together with its lexical analyser" ) set( LEXYACC_FOUND 0 ) endif() if( NOT YACC_FOUND ) # check for both bison & flex together if( BISON_FOUND AND NOT FLEX_FOUND ) set( LEXYACC_FOUND 0 ) ecbuild_debug( "Both bison and flex are required - flex not found" ) endif() if( FLEX_FOUND AND NOT BISON_FOUND ) set( LEXYACC_FOUND 0 ) ecbuild_debug( "Both bison and flex are required - bison not found" ) endif() endif() if( NOT BISON_FOUND ) # check for both yacc & lex together if( YACC_FOUND AND NOT LEX_FOUND ) set( LEXYACC_FOUND 0 ) ecbuild_debug( "Both yacc and lex are required - lex not found" ) endif() if( LEX_FOUND AND NOT YACC_FOUND ) set( LEXYACC_FOUND 0 ) ecbuild_debug( "Both yacc and lex are required - yacc not found" ) endif() endif() endmacro( ecbuild_find_lexyacc ) ecbuild-3.13.1/cmake/ecbuild_find_mpi.cmake000066400000000000000000000165321513706760700205670ustar00rootroot00000000000000# (C) Copyright 2011- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation nor # does it submit to any jurisdiction. ############################################################################## #.rst: # # ecbuild_find_mpi # ================ # # Find MPI and check if MPI compilers successfully compile C/C++/Fortran. :: # # ecbuild_find_mpi( [ COMPONENTS [ ... ] ] # [ REQUIRED ] ) # # Options # ------- # # COMPONENTS : optional, defaults to C # list of required languages bindings # # REQUIRED : optional # fail if MPI was not found # # Input variables # --------------- # # ECBUILD_FIND_MPI : optional, defaults to TRUE # test C/C++/Fortran MPI compiler wrappers (assume working if FALSE) # # Output variables # ---------------- # # The following CMake variables are set if MPI was found: :: # # MPI_FOUND # MPI_LIBRARY # MPI_EXTRA_LIBRARY # # The following CMake variables are set if C bindings were found: :: # # MPI_C_FOUND # MPI_C_COMPILER # MPI_C_COMPILE_FLAGS # MPI_C_INCLUDE_PATH # MPI_C_LIBRARIES # MPI_C_LINK_FLAGS # # The following CMake variables are set if C++ bindings were found: :: # # MPI_CXX_FOUND # MPI_CXX_COMPILER # MPI_CXX_COMPILE_FLAGS # MPI_CXX_INCLUDE_PATH # MPI_CXX_LIBRARIES # MPI_CXX_LINK_FLAGS # # The following CMake variables are set if Fortran bindings were found: :: # # MPI_Fortran_FOUND # MPI_Fortran_COMPILER # MPI_Fortran_COMPILE_FLAGS # MPI_Fortran_INCLUDE_PATH # MPI_Fortran_LIBRARIES # MPI_Fortran_LINK_FLAGS # ############################################################################## macro( ecbuild_find_mpi ) # parse parameters set( options REQUIRED ) set( single_value_args ) set( multi_value_args COMPONENTS ) cmake_parse_arguments( _PAR "${options}" "${single_value_args}" "${multi_value_args}" ${_FIRST_ARG} ${ARGN} ) if(_PAR_UNPARSED_ARGUMENTS) ecbuild_critical("Unknown keywords given to ecbuild_find_mpi(): \"${_PAR_UNPARSED_ARGUMENTS}\"") endif() if( NOT _PAR_COMPONENTS ) set( _PAR_COMPONENTS C ) endif() # if user defined compilers are MPI compliant, then we use them ... if( NOT DEFINED ECBUILD_FIND_MPI ) set( ECBUILD_FIND_MPI TRUE ) endif() if( ECBUILD_FIND_MPI ) if( NOT _PAR_REQUIRED ) find_package( MPI COMPONENTS ${_PAR_COMPONENTS} ) else() find_package( MPI REQUIRED COMPONENTS ${_PAR_COMPONENTS} ) endif() if( C_COMPILER_SUPPORTS_MPI ) set( MPI_C_FOUND TRUE ) endif() if( CXX_COMPILER_SUPPORTS_MPI ) set( MPI_CXX_FOUND TRUE ) endif() if( Fortran_COMPILER_SUPPORTS_MPI ) set( MPI_Fortran_FOUND TRUE ) endif() else() if( CMAKE_C_COMPILER_LOADED ) set( C_COMPILER_SUPPORTS_MPI TRUE ) set( MPI_C_FOUND TRUE ) endif() if( CMAKE_CXX_COMPILER_LOADED ) set( CXX_COMPILER_SUPPORTS_MPI TRUE ) set( MPI_CXX_FOUND TRUE ) endif() if( CMAKE_Fortran_COMPILER_LOADED ) set( Fortran_COMPILER_SUPPORTS_MPI TRUE ) set( MPI_Fortran_FOUND TRUE ) endif() endif( ECBUILD_FIND_MPI ) # hide these variables from UI mark_as_advanced( MPI_LIBRARY MPI_EXTRA_LIBRARY ) set( MPI_FOUND TRUE ) foreach( _lang ${_PAR_COMPONENTS} ) if( NOT MPI_${_lang}_FOUND ) set( MPI_FOUND FALSE ) endif() if( NOT MPI_${_lang}_INCLUDE_DIRS ) set( MPI_${_lang}_INCLUDE_DIRS ${MPI_${_lang}_INCLUDE_PATH} ) endif() endforeach() endmacro( ecbuild_find_mpi ) ############################################################################## #.rst: # # ecbuild_enable_mpi # ================== # # Find MPI, add include directories and set compiler flags. :: # # ecbuild_enable_mpi( [ COMPONENTS [ ... ] ] # [ REQUIRED ] ) # # For each MPI language binding found, set the corresponding compiler flags # and add the include directories. # # See ``ecbuild_find_mpi`` for input and output variables. # # Options # ------- # # COMPONENTS : optional, defaults to C # list of required languages bindings # # REQUIRED : optional # fail if MPI was not found # ############################################################################## macro( ecbuild_enable_mpi ) set( options REQUIRED ) set( single_value_args ) set( multi_value_args COMPONENTS ) cmake_parse_arguments( _PAR "${options}" "${single_value_args}" "${multi_value_args}" ${_FIRST_ARG} ${ARGN} ) if(_PAR_UNPARSED_ARGUMENTS) ecbuild_critical("Unknown keywords given to ecbuild_find_mpi(): \"${_PAR_UNPARSED_ARGUMENTS}\"") endif() if( NOT _PAR_COMPONENTS ) set (_PAR_COMPONENTS C ) endif() if( NOT _PAR_REQUIRED ) ecbuild_find_mpi( COMPONENTS ${_PAR_COMPONENTS} ) else() ecbuild_find_mpi( COMPONENTS ${_PAR_COMPONENTS} REQUIRED ) endif() if( MPI_C_FOUND AND NOT C_COMPILER_SUPPORTS_MPI ) ecbuild_add_c_flags("${MPI_C_COMPILE_FLAGS}") include_directories(${MPI_C_INCLUDE_DIRS}) endif() if( MPI_CXX_FOUND AND NOT CXX_COMPILER_SUPPORTS_MPI ) ecbuild_add_cxx_flags("${MPI_CXX_COMPILE_FLAGS}") include_directories(${MPI_CXX_INCLUDE_DIRS}) endif() if( MPI_Fortran_FOUND AND NOT Fortran_COMPILER_SUPPORTS_MPI ) include( ecbuild_check_fortran_source_return ) ecbuild_add_fortran_flags("${MPI_Fortran_COMPILE_FLAGS}") include_directories(${MPI_Fortran_INCLUDE_DIRS}) endif() endmacro( ecbuild_enable_mpi ) ############################################################################## #.rst: # # ecbuild_include_mpi # =================== # # Add MPI include directories and set compiler flags, assuming MPI was found. # # For each MPI language binding found, set corresponding compiler flags and # add include directories. ``ecbuild_find_mpi`` must have been called before. # ############################################################################## macro( ecbuild_include_mpi ) set( options ) set( single_value_args ) set( multi_value_args ) cmake_parse_arguments( _PAR "${options}" "${single_value_args}" "${multi_value_args}" ${_FIRST_ARG} ${ARGN} ) if(_PAR_UNPARSED_ARGUMENTS) ecbuild_critical("Unknown keywords given to ecbuild_find_mpi(): \"${_PAR_UNPARSED_ARGUMENTS}\"") endif() if( MPI_C_FOUND AND NOT C_COMPILER_SUPPORTS_MPI ) include( ecbuild_check_c_source_return ) ecbuild_add_c_flags("${MPI_C_COMPILE_FLAGS}") include_directories(${MPI_C_INCLUDE_DIRS}) endif() if( MPI_CXX_FOUND AND NOT CXX_COMPILER_SUPPORTS_MPI ) include( ecbuild_check_cxx_source_return ) ecbuild_add_cxx_flags("${MPI_CXX_COMPILE_FLAGS}") include_directories(${MPI_CXX_INCLUDE_DIRS}) endif() if( MPI_Fortran_FOUND AND NOT Fortran_COMPILER_SUPPORTS_MPI ) include( ecbuild_check_fortran_source_return ) ecbuild_add_fortran_flags("${MPI_Fortran_COMPILE_FLAGS}") include_directories(${MPI_Fortran_INCLUDE_DIRS}) endif() endmacro( ecbuild_include_mpi ) ecbuild-3.13.1/cmake/ecbuild_find_omp.cmake000066400000000000000000000160001513706760700205630ustar00rootroot00000000000000# (C) Copyright 2011- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation nor # does it submit to any jurisdiction. ############################################################################## # macro for looking for openmp flags macro( lookup_omp_flags ) set(_OMP_FLAG_GNU "-fopenmp") set(_OMPSTUBS_FLAG_GNU "-fno-openmp") set(_OMP_FLAG_Cray "-homp") set(_OMPSTUBS_FLAG_Cray "-hnoomp") set(_OMP_FLAG_XL "-qsmp=omp") set(_OMPSTUBS_FLAG_XL "-qsmp=noomp") set(_OMP_FLAG_Intel "-qopenmp") set(_OMPSTUBS_FLAG_Intel "-qopenmp-stubs") # sample C openmp source code to test set(_OMP_C_TEST_SOURCE " #include int main() { #ifdef _OPENMP #pragma omp parallel { (void)omp_get_thread_num(); } return 0; #else breaks_on_purpose #endif } ") set( _OMP_CXX_TEST_SOURCE ${_OMP_C_TEST_SOURCE} ) # sample C openmp source code to test set(_OMPSTUBS_C_TEST_SOURCE " // Include must be found #include int main() { #ifdef _OPENMP breaks_on_purpose #else #pragma omp parallel { // This pragma should have passed compilation (void)0; } return 0; #endif } ") set( _OMPSTUBS_CXX_TEST_SOURCE ${_OMPSTUBS_C_TEST_SOURCE} ) # sample Fortran openmp source code to test set(_OMP_Fortran_TEST_SOURCE " program main use omp_lib end program ") set( _OMPSTUBS_Fortran_TEST_SOURCE ${_OMP_Fortran_TEST_SOURCE} ) endmacro() ############################################################################## #.rst: # # ecbuild_find_omp # ================ # # Find OpenMP. :: # # ecbuild_find_omp( [ COMPONENTS [ ... ] ] # [ REQUIRED ] # [ STUBS ] ) # # Options # ------- # # COMPONENTS : optional, defaults to C # list of required languages bindings # # REQUIRED : optional # fail if OpenMP was not found # # STUBS : optional # search for OpenMP stubs # # Output variables # ---------------- # # The following CMake variables are set if OpenMP was found: # # :OMP_FOUND: OpenMP was found # # For each language listed in COMPONENTS, the following variables are set: # # :OMP__FOUND: OpenMP bindings for LANG were found # :OMP__FLAGS: OpenMP compiler flags for LANG # # If the STUBS option was given, all variables are also set with the OMPSTUBS # instead of the OMP prefix. # ############################################################################## macro( ecbuild_find_omp ) set( options REQUIRED STUBS ) set( single_value_args ) set( multi_value_args COMPONENTS ) cmake_parse_arguments( _PAR "${options}" "${single_value_args}" "${multi_value_args}" ${_FIRST_ARG} ${ARGN} ) if( NOT _PAR_COMPONENTS ) ecbuild_critical( "No COMPONENTS were specified, looking for OMP.\n Please find with COMPONENTS C CXX Fortran " ) endif() set( _STUBS "" ) if( _PAR_STUBS ) set( _STUBS "STUBS" ) endif() lookup_omp_flags() set( OMP${_STUBS}_FOUND TRUE ) foreach( _LANG ${_PAR_COMPONENTS} ) if( NOT OMP${_STUBS}_${_LANG}_FLAGS ) if( DEFINED _OMP${_STUBS}_FLAG_${CMAKE_${_LANG}_COMPILER_ID} ) set( _OMP${_STUBS}_${_LANG}_FLAG "${_OMP${_STUBS}_FLAG_${CMAKE_${_LANG}_COMPILER_ID}}" ) endif() if( CMAKE_${_LANG}_COMPILER_LOADED AND _OMP${_STUBS}_${_LANG}_FLAG ) set(SAVE_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}") set(CMAKE_REQUIRED_FLAGS "${_OMP${_STUBS}_${_LANG}_FLAG}") include(Check${_LANG}SourceCompiles) set( _SOURCE ${_OMP${_STUBS}_${_LANG}_TEST_SOURCE} ) set( _FLAG ${_LANG}_COMPILER_SUPPORTS_OMP${_STUBS}) if( _LANG STREQUAL "C" ) check_c_source_compiles("${_SOURCE}" ${_FLAG} ) endif() if( _LANG STREQUAL "CXX" ) check_cxx_source_compiles("${_SOURCE}" ${_FLAG} ) endif() if( _LANG STREQUAL "Fortran" ) check_fortran_source_compiles("${_SOURCE}" ${_FLAG} SRC_EXT f90) endif() set(CMAKE_REQUIRED_FLAGS "${SAVE_CMAKE_REQUIRED_FLAGS}") endif() if( ${_LANG}_COMPILER_SUPPORTS_OMP${_STUBS} ) set( OMP${_STUBS}_${_LANG}_FLAGS ${_OMP${_STUBS}_${_LANG}_FLAG} ) endif() else() set( ${_LANG}_COMPILER_SUPPORTS_OMP${_STUBS} TRUE ) endif() set( OMP${_STUBS}_${_LANG}_FIND_QUIETLY TRUE ) include(FindPackageHandleStandardArgs) find_package_handle_standard_args( OMP${_STUBS}_${_LANG} REQUIRED_VARS ${_LANG}_COMPILER_SUPPORTS_OMP${_STUBS} ) if( OMP${_STUBS}_FORTRAN_FOUND ) set( OMP${_STUBS}_Fortran_FOUND TRUE ) endif() if( NOT OMP${_STUBS}_${_LANG}_FOUND ) set( OMP${_STUBS}_FOUND FALSE ) endif() if( _PAR_STUBS ) set( OMP_${_LANG}_FOUND ${OMPSTUBS_${_LANG}_FOUND} ) set( OMP_${_LANG}_FLAGS ${OMPSTUBS_${_LANG}_FLAGS} ) endif() endforeach() if( _PAR_STUBS ) set( OMP_FOUND ${OMPSTUBS_FOUND} ) endif() endmacro( ecbuild_find_omp ) ############################################################################## #.rst: # # ecbuild_enable_omp # ================== # # Find OpenMP for C, C++ and Fortran and set the compiler flags for each # language for which OpenMP support was detected. # ############################################################################## macro( ecbuild_enable_omp ) ecbuild_debug("ecbuild_enable_omp: Trying to enable OpenMP") ecbuild_find_omp( COMPONENTS C CXX Fortran ) ecbuild_debug_var("OMP_C_FOUND") if( OMP_C_FOUND ) ecbuild_debug("Adding ${OMP_C_FLAGS} to CMAKE_C_FLAGS") set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OMP_C_FLAGS}" ) endif() ecbuild_debug_var("OMP_CXX_FOUND") if( OMP_CXX_FOUND ) ecbuild_debug("Adding ${OMP_CXX_FLAGS} to CMAKE_CXX_FLAGS") set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OMP_CXX_FLAGS}" ) endif() ecbuild_debug_var("OMP_Fortran_FOUND") if( OMP_Fortran_FOUND ) ecbuild_debug("Adding ${OMP_Fortran_FLAGS} to CMAKE_Fortran_FLAGS") set( CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${OMP_Fortran_FLAGS}" ) endif() endmacro( ecbuild_enable_omp ) ############################################################################## #.rst: # # ecbuild_enable_ompstubs # ======================= # # Find OpenMP stubs for C, C++ and Fortran and set the compiler flags for each # language for which OpenMP stubs were detected. # ############################################################################## macro( ecbuild_enable_ompstubs ) ecbuild_find_omp( COMPONENTS C CXX Fortran STUBS ) if( OMPSTUBS_C_FOUND ) set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OMPSTUBS_C_FLAGS}" ) endif() if( OMPSTUBS_CXX_FOUND ) set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OMPSTUBS_CXX_FLAGS}" ) endif() if( OMPSTUBS_Fortran_FOUND ) set( CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${OMPSTUBS_Fortran_FLAGS}" ) endif() endmacro( ecbuild_enable_ompstubs ) ecbuild-3.13.1/cmake/ecbuild_find_package.cmake000066400000000000000000000330741513706760700213750ustar00rootroot00000000000000# (C) Copyright 2011- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation nor # does it submit to any jurisdiction. ############################################################################## #.rst: # # ecbuild_find_package # ==================== # # Find a package and import its configuration. :: # # ecbuild_find_package( [ NAME ] # [ [ VERSION ] [ EXACT ] ] # [ COMPONENTS [ ... ] ] # [ URL ] # [ DESCRIPTION ] # [ TYPE ] # [ PURPOSE ] # [ FAILURE_MSG ] # [ REQUIRED ] # [ QUIET ] ) # # Options # ------- # # NAME : required # package name (used as ``Find.cmake`` and ``-config.cmake``) # # VERSION : optional # minimum required package version # # COMPONENTS : optional # list of package components to find (behaviour depends on the package) # # EXACT : optional, requires VERSION # require the exact version rather than a minimum version # # URL : optional # homepage of the package (shown in summary and stored in the cache) # # DESCRIPTION : optional # literal string or name of CMake variable describing the package # # TYPE : optional, one of RUNTIME|OPTIONAL|RECOMMENDED|REQUIRED # type of dependency of the project on this package (defaults to OPTIONAL) # # PURPOSE : optional # literal string or name of CMake variable describing which functionality # this package enables in the project # # FAILURE_MSG : optional # literal string or name of CMake variable containing a message to be # appended to the failure message if the package is not found # # REQUIRED : optional (equivalent to TYPE REQUIRED, and overrides TYPE argument) # fail if package cannot be found # # QUIET : optional # do not output package information if found # # Input variables # --------------- # # The following CMake variables influence the behaviour if set (```` is # the package name as given, ```` is the capitalised version): # # :_ROOT: install prefix path of the package # :_PATH: install prefix path of the package, prefer _ROOT # :_PATH: install prefix path of the package, prefer _ROOT # :_DIR: directory containing the ``-config.cmake`` file # (usually ``/lib/cmake/``), prefer _ROOT # :CMAKE_PREFIX_PATH: Specify this when most packages are installed in same prefix # # The environment variables ``_ROOT``, ``_PATH``, ``_PATH``, ``_DIR`` # are taken into account only if the corresponding CMake variables are unset. # # Note, some packages are found via ``Find.cmake`` and may have their own mechanism of # finding paths with other variables, e.g. ``_HOME``. See the corresponing # ``Find.cmake`` file for datails, or use `cmake --help-module Find` if it is a # standard CMake-recognized module. # # Usage # ----- # # The search proceeds as follows: # # 1. If is a subproject of the top-level project, search for # ``-config.cmake`` in ``_BINARY_DIR``. # # 2. If ``Find.cmake`` exists in ``CMAKE_MODULE_PATH``, search using it. # # 3. If any paths have been specified by the user via CMake or environment # variables as given above: # # * search for ``-config.cmake`` in those paths only # * fail if the package was not found in any of those paths # * Search paths are in order from high to low priority: # - ``_DIR`` # - ``_ROOT`` # - ``_PATH`` # - ``_PATH`` # - ``ENV{_ROOT}`` # - ``ENV{_PATH}`` # - ``ENV{_PATH}`` # - ``CMAKE_PREFIX_PATH`` # - ``ENV{_DIR}`` # - ``ENV{CMAKE_PREFIX_PATH}`` # - ``system paths`` # # See CMake documentation of ``find_package()`` for details. # # 4. Fail if the package was not found and is REQUIRED. # ############################################################################## macro( ecbuild_find_package ) set( options REQUIRED RECOMMENDED QUIET EXACT ) set( single_value_args NAME VERSION URL DESCRIPTION TYPE PURPOSE FAILURE_MSG ) set( multi_value_args COMPONENTS ) cmake_parse_arguments( _PAR "${options}" "${single_value_args}" "${multi_value_args}" ${ARGN} ) if(_PAR_UNPARSED_ARGUMENTS) if( NOT _PAR_NAME ) set( _PAR_NAME ${ARGV0} ) list( REMOVE_ITEM _PAR_UNPARSED_ARGUMENTS ${ARGV0} ) if( NOT _PAR_VERSION AND "${ARGV1}" MATCHES "^[0-9]+(\\.[0-9]+)*$" ) set( _PAR_VERSION ${ARGV1} ) list( REMOVE_ITEM _PAR_UNPARSED_ARGUMENTS ${ARGV1} ) endif() endif() endif() if(_PAR_UNPARSED_ARGUMENTS) ecbuild_critical("Unknown keywords given to ecbuild_find_package(): \"${_PAR_UNPARSED_ARGUMENTS}\"") endif() if( NOT _PAR_NAME ) ecbuild_critical("The call to ecbuild_find_package() doesn't specify the NAME.") endif() if( _PAR_EXACT AND NOT _PAR_VERSION ) ecbuild_critical("Call to ecbuild_find_package() requests EXACT but doesn't specify VERSION.") endif() if( _PAR_QUIET ) set( _${_PAR_NAME}_find_quiet QUIET ) endif() # If the package is required, set TYPE to REQUIRED # Due to shortcomings in CMake's argument parser, passing TYPE REQUIRED has no effect if( _PAR_REQUIRED ) set( _PAR_TYPE REQUIRED ) endif() # As mentioned in documentation above, the default TYPE is OPTIONAL if( NOT _PAR_TYPE ) set( _PAR_TYPE OPTIONAL ) endif() set( _${_PAR_NAME}_version "" ) if( _PAR_VERSION ) set( _${_PAR_NAME}_version ${_PAR_VERSION} ) if( _PAR_EXACT ) set( _${_PAR_NAME}_version ${_PAR_VERSION} EXACT ) endif() endif() set( _${_PAR_NAME}_components "" ) if( DEFINED _PAR_COMPONENTS ) set( _${_PAR_NAME}_components COMPONENTS ${_PAR_COMPONENTS} ) endif() if( ECBUILD_2_COMPAT ) # Disable deprecation warnings until ecbuild_mark_compat, because "_FOUND" may already have been # marked with "ecbuild_mark_compat()" in a bundle. set( DISABLE_ECBUILD_DEPRECATION_WARNINGS_orig ${DISABLE_ECBUILD_DEPRECATION_WARNINGS} ) set( DISABLE_ECBUILD_DEPRECATION_WARNINGS ON ) endif() # cancel the effect of ecbuild_install_project setting _FOUND in # compat mode (otherwise this means the -config.cmake file may not # always be loaded, see ECBUILD-401) if( ECBUILD_2_COMPAT ) unset( ${_PAR_NAME}_FOUND ) endif() # if a project with the same name has been defined, try to use it if( ${_PAR_NAME}_BINARY_DIR ) # 1) search using CONFIG mode -- try to locate a configuration file provided by the package (package-config.cmake) # _BINARY_DIR is defined by CMake when using project() if( NOT ${_PAR_NAME}_FOUND ) ecbuild_debug("ecbuild_find_package(${_PAR_NAME}): find_package( ${_PAR_NAME} ${_${_PAR_NAME}_version} ${_${_PAR_NAME}_components} ${_${_PAR_NAME}_find_quiet} )\n" " using hints ${_PAR_NAME}_BINARY_DIR=${${_PAR_NAME}_BINARY_DIR}" ) find_package( ${_PAR_NAME} ${_${_PAR_NAME}_version} ${_${_PAR_NAME}_components} ${_${_PAR_NAME}_find_quiet} NO_MODULE HINTS ${${_PAR_NAME}_BINARY_DIR} NO_DEFAULT_PATH ) endif() if( NOT ${_PAR_NAME}_FOUND ) if( ${_PAR_NAME}_CONSIDERED_VERSIONS ) ecbuild_critical( "${_PAR_NAME} was found in the source tree but no suitable version (or component set) was found at '${${_PAR_NAME}_BINARY_DIR}'" ) else() ecbuild_critical( "${_PAR_NAME} was found in the source tree but could not be loaded from '${${_PAR_NAME}_BINARY_DIR}'" ) endif() endif() else() # If a Find.cmake module is found, use MODULE keyword, otherwise, use CONFIG. # This makes the find_package error message much more consise. find_file( ${_PAR_NAME}_FindModule Find${_PAR_NAME}.cmake PATHS ${CMAKE_MODULE_PATH} ${CMAKE_ROOT}/Modules NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH) find_file( ${_PAR_NAME}_FindModule Find${_PAR_NAME}.cmake PATHS ${CMAKE_MODULE_PATH} ${CMAKE_ROOT}/Modules ) if( ${_PAR_NAME}_FindModule ) set( _${_PAR_NAME}_mode MODULE ) else() set( _${_PAR_NAME}_mode CONFIG ) endif() # Read variables like _PATH and _PATH, # and make older versions (CMake < 3.12) forward compatible with _ROOT ecbuild_find_package_search_hints( NAME ${_PAR_NAME} ) # Disable search in package registry, and save to be restored after find_package() set( CMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY_orig ${CMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY} ) set( CMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY ON ) # The actual find_package() ecbuild_debug ( "ecbuild_find_package(${_PAR_NAME}): find_package( ${_PAR_NAME} ${_${_PAR_NAME}_version} ${_${_PAR_NAME}_find_quiet} ${_${_PAR_NAME}_components} ${_${_PAR_NAME}_mode} )") find_package( ${_PAR_NAME} ${_${_PAR_NAME}_version} ${_${_PAR_NAME}_find_quiet} ${_${_PAR_NAME}_components} ${_${_PAR_NAME}_mode} ) # Restore setting set( CMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY ${CMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY_orig} ) endif() string( TOUPPER ${_PAR_NAME} pkgUPPER ) if(ECBUILD_2_COMPAT) ecbuild_declare_compat(${pkgUPPER}_FOUND ${_PAR_NAME}_FOUND) endif() if( ECBUILD_2_COMPAT ) set( DISABLE_ECBUILD_DEPRECATION_WARNINGS ${DISABLE_ECBUILD_DEPRECATION_WARNINGS_orig} ) endif() ### final messages if( ${_PAR_NAME}_FOUND ) if( NOT _PAR_QUIET ) if( ${_PAR_NAME}_DIR ) # Defined by find_package if found via CONFIG option ecbuild_info( "${PROJECT_NAME} FOUND ${_PAR_NAME}: ${${_PAR_NAME}_DIR} (found version \"${${_PAR_NAME}_VERSION}\")" ) else() if( ${_PAR_NAME}_VERSION ) ecbuild_info( "${PROJECT_NAME} FOUND ${_PAR_NAME} (found version \"${${_PAR_NAME}_VERSION}\")" ) else() ecbuild_info( "${PROJECT_NAME} FOUND ${_PAR_NAME}" ) endif() endif() foreach( var IN ITEMS INCLUDE_DIRS INCLUDE_DIR ) if( ${_PAR_NAME}_${var} ) ecbuild_info( " ${_PAR_NAME}_${var} : [${${_PAR_NAME}_${var}}]" ) break() endif() if( ${pkgUPPER}_${var} ) ecbuild_info( " ${pkgUPPER}_${var} : [${${pkgUPPER}_${var}}]" ) break() endif() endforeach() foreach( var IN ITEMS LIBRARIES LIBRARY ) if( ${pkgUPPER}_${var} ) ecbuild_info( " ${pkgUPPER}_${var} : [${${pkgUPPER}_${var}}]" ) break() endif() if( ${_PAR_NAME}_${var} ) ecbuild_info( " ${_PAR_NAME}_${var} : [${${_PAR_NAME}_${var}}]" ) break() endif() endforeach() foreach( var IN ITEMS DEFINITIONS ) if( ${pkgUPPER}_${var} ) ecbuild_info( " ${pkgUPPER}_${var} : [${${pkgUPPER}_${var}}]" ) break() endif() if( ${_PAR_NAME}_${var} ) ecbuild_info( " ${_PAR_NAME}_${var} : [${${_PAR_NAME}_${var}}]" ) break() endif() endforeach() endif() if( DEFINED ${_PAR_DESCRIPTION} ) set( _PAR_DESCRIPTION ${${_PAR_DESCRIPTION}} ) endif() if( DEFINED ${_PAR_PURPOSE} ) set( _PAR_PURPOSE ${${_PAR_PURPOSE}} ) endif() set_package_properties( ${_PAR_NAME} PROPERTIES URL "${_PAR_URL}" DESCRIPTION "${_PAR_DESCRIPTION}" TYPE "${_PAR_TYPE}" PURPOSE "${_PAR_PURPOSE}" ) else() set( _failed_message ${_PAR_FAILURE_MSG} ) if( DEFINED ${_PAR_FAILURE_MSG} ) set( _failed_message "${${_PAR_FAILURE_MSG}}" ) endif() # Quite verbose message, only to be printed when package is REQUIRED, or ECBUILD_LOG_LEVEL <= DEBUG # When TYPE is RECOMMENDED, we will issue with ecbuild_warn, otherwise ecbuild_info set( _default_failed_message "${PROJECT_NAME} FAILED to find ${_PAR_TYPE} package ${_PAR_NAME}" ) if( ${_PAR_NAME}_FindModule ) set( _failed_help "find_package(${_PAR_NAME}) used a Find${_PAR_NAME} module to find ${_PAR_NAME}\n" " Please check file `${${_PAR_NAME}_FindModule}` for help on setting variables to find this package." ) else() set( _failed_help "find_package(${_PAR_NAME}) assumed ${_PAR_NAME} is a CMake project.\n" " Recommended variables that can help detection:\n" " - ${_PAR_NAME}_ROOT : the install prefix (as in /bin /lib /include)\n" " - CMAKE_PREFIX_PATH : the install prefix (as ${_PAR_NAME}_ROOT, or its parent directory as in /${_PAR_NAME})" ) endif() if( NOT _failed_message ) if(_PAR_TYPE MATCHES "(RECOMMENDED|REQUIRED)" ) set( _failed_message "${_default_failed_message}\n${_failed_help}" ) else() set( _failed_message ${_default_failed_message} ) endif() endif() if( _PAR_REQUIRED ) ecbuild_critical( "${_failed_message}" ) endif() if( NOT _PAR_QUIET ) if( _PAR_TYPE MATCHES "RECOMMENDED" ) ecbuild_warn( "${_failed_message}" ) else() ecbuild_info( "${_failed_message}" ) endif() if( ECBUILD_LOG_LEVEL LESS_EQUAL ${ECBUILD_DEBUG} ) ecbuild_debug( "${_failed_help}" ) endif() else() ecbuild_debug( "${_failed_message}" ) endif() endif() endmacro() ecbuild-3.13.1/cmake/ecbuild_find_package_search_hints.cmake000066400000000000000000000144271513706760700241300ustar00rootroot00000000000000# (C) Copyright 2011- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation nor # does it submit to any jurisdiction. ############################################################################## #.rst: # # ecbuild_find_package_search_hints # ================================= # # Detect more search hints and possibly add to _ROOT :: # # ecbuild_find_package_search_hints( NAME ) # # This is called within ecbuild_find_package(). # Alternatively it can be called anywhere before a standard find_package() # # Motivation # ---------- # # Since CMake 3.12 the recommended approach to find_package is via _ROOT # which can be set both as variable or in the environment. # Many environments still need to be adapted to this, as they are set up with the # ecbuild 2 convention _PATH or _PATH. Furthermore this allows compatibility # with _ROOT for CMake versions < 3.12 # # Procedure # --------- # # 1) If neither _ROOT nor _DIR are set in scope: # Try setting _ROOT variable to first valid in list [ _PATH ; _PATH ] # # 2) If 1) was not succesfull and neither _ROOT nor _DIR are set in environment: # Try setting _ROOT variable to first valid in list [ ENV{_PATH} ; ENV{_PATH} ] # # 3) Overcome CMake versions < 3.12 that do not yet recognize _ROOT in scope or environment # If CMake version < 3.12: # If _DIR not defined in scope or environment, but _ROOT IS defined in scope or environment # Try setting _DIR to a valid cmake-dir deduced from _ROOT. # # Warning: Deduction is not feature-complete (it could be improved, but should now cover 99% of cases) # It is advised to use CMake 3.12 instead. # ############################################################################## function( ecbuild_find_package_search_hints ) set( options ) set( single_value_args NAME ) set( multi_value_args ) cmake_parse_arguments( _PAR "${options}" "${single_value_args}" "${multi_value_args}" ${_FIRST_ARG} ${ARGN} ) if( NOT DEFINED _PAR_NAME ) ecbuild_critical( "ecbuild_find_package_search_hints(): NAME argument is missing" ) endif() string( TOUPPER ${_PAR_NAME} pkgUPPER ) unset( _outvar ) unset( _names ) # Diagnose what is there for debugging list( APPEND _names ${_PAR_NAME} ) if( NOT ${pkgUPPER} STREQUAL ${_PAR_NAME} ) list( APPEND _names ${pkgUPPER} ) endif() foreach( _suffix DIR ROOT HOME PATH ROOT_DIR ) foreach( _name ${_names}) if( DEFINED ${_name}_${_suffix} ) list( APPEND _outvar "${_name}_${_suffix}: ${${_name}_${_suffix}}") endif() if( DEFINED ENV{${_name}_${_suffix}} ) list( APPEND _outvar "ENV{${_name}_${_suffix}}: $ENV{${_name}_${_suffix}}") endif() endforeach() endforeach() if( DEFINED CMAKE_PREFIX_PATH ) list( APPEND _outvar "CMAKE_PREFIX_PATH: ${CMAKE_PREFIX_PATH}") endif() if( DEFINED ENV{CMAKE_PREFIX_PATH} ) list( APPEND _outvar "ENV{CMAKE_PREFIX_PATH}: $ENV{CMAKE_PREFIX_PATH}") endif() if( _outvar ) string( REPLACE ";" "\n - " print_this "${_outvar}" ) ecbuild_debug( "ecbuild_find_package_search_hints(${_PAR_NAME}): Detected variables that could influence find_package() :\n - ${print_this}" ) endif() # Only look at older variables _PATH and _PATH if _ROOT and _DIR are not defined in scope if( NOT DEFINED ${_PAR_NAME}_ROOT AND NOT DEFINED ${_PAR_NAME}_DIR ) if( NOT DEFINED ${_PAR_NAME}_ROOT AND DEFINED ${_PAR_NAME}_PATH ) ecbuild_debug("ecbuild_find_package_search_hints(${_PAR_NAME}): Setting ${_PAR_NAME}_ROOT to ${_PAR_NAME}_PATH: ${${_PAR_NAME}_PATH}") set( ${_PAR_NAME}_ROOT ${${_PAR_NAME}_PATH} ) endif() if( NOT DEFINED ${_PAR_NAME}_ROOT AND DEFINED ${pkgUPPER}_PATH ) ecbuild_debug("ecbuild_find_package_search_hints(${_PAR_NAME}): Setting ${_PAR_NAME}_ROOT to ${pkgUPPER}_PATH: ${${pkgUPPER}_PATH}") set( ${_PAR_NAME}_ROOT ${${pkgUPPER}_PATH} ) endif() if( DEFINED ${_PAR_NAME}_ROOT ) set( ${_PAR_NAME}_ROOT ${${_PAR_NAME}_ROOT} PARENT_SCOPE ) endif() endif() # Only look at older variables ENV{_PATH} and ENV{_PATH} if _ROOT and _DIR are not defined in scope or in environment if( NOT DEFINED ${_PAR_NAME}_ROOT AND NOT DEFINED ENV{${_PAR_NAME}_ROOT} AND NOT DEFINED ${_PAR_NAME}_DIR AND NOT DEFINED ENV{${_PAR_NAME}_DIR} ) if( NOT DEFINED ${_PAR_NAME}_ROOT AND DEFINED ENV{${_PAR_NAME}_PATH} ) ecbuild_debug("ecbuild_find_package_search_hints(${_PAR_NAME}): Setting ${_PAR_NAME}_ROOT to ENV{${_PAR_NAME}_PATH}: $ENV{${_PAR_NAME}_PATH}") set( ${_PAR_NAME}_ROOT $ENV{${_PAR_NAME}_PATH} ) endif() if( NOT DEFINED ${_PAR_NAME}_ROOT AND DEFINED ENV{${pkgUPPER}_PATH} ) ecbuild_debug("ecbuild_find_package_search_hints(${_PAR_NAME}): Setting ${_PAR_NAME}_ROOT to ENV{${pkgUPPER}_PATH}: $ENV{${pkgUPPER}_PATH}") set( ${_PAR_NAME}_ROOT $ENV{${pkgUPPER}_PATH} ) endif() if( DEFINED ${_PAR_NAME}_ROOT ) set( ${_PAR_NAME}_ROOT ${${_PAR_NAME}_ROOT} PARENT_SCOPE ) endif() endif() #### Overcome CMake 3.11 to 3.12 transition with _ROOT # warning! this is not fully foolproof! if( CMAKE_VERSION VERSION_LESS 3.12 ) if( ( NOT DEFINED ${_PAR_NAME}_DIR AND NOT DEFINED ENV{${_PAR_NAME}_DIR} ) AND ( DEFINED ${_PAR_NAME}_ROOT OR DEFINED ENV{${_PAR_NAME}_ROOT}} ) ) if( DEFINED ${_PAR_NAME}_ROOT ) set( _root ${_PAR_NAME}_ROOT ) else() set( _root $ENV{${_PAR_NAME}_ROOT} ) endif() foreach( _path_suffix lib/cmake/${_PAR_NAME} share/${_PAR_NAME}/cmake ) if( EXISTS ${_root}/${_path_suffix} ) ecbuild_debug("ecbuild_find_package_search_hints(${_PAR_NAME}): Setting ${_PAR_NAME}_DIR to ${_root}/${_path_suffix}") set( ${_PAR_NAME}_DIR ${_root}/${_path_suffix} PARENT_SCOPE ) break() endif() endforeach() endif() endif() endfunction() ecbuild-3.13.1/cmake/ecbuild_find_perl.cmake000066400000000000000000000041611513706760700207370ustar00rootroot00000000000000# (C) Copyright 2011- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation nor # does it submit to any jurisdiction. ############################################################################## #.rst: # # ecbuild_find_perl # ================= # # Find perl executable and its version. :: # # ecbuild_find_perl( [ REQUIRED ] ) # # Options # ------- # # REQUIRED : optional # fail if perl was not found # # Output variables # ---------------- # # The following CMake variables are set if perl was found: # # :PERL_FOUND: perl was found # :PERL_EXECUTABLE: path to the perl executable # :PERL_VERSION: perl version # :PERL_VERSION_STRING: perl version (same as ``PERL_VERSION``) # ############################################################################## macro( ecbuild_find_perl ) # parse parameters set( options REQUIRED ) set( single_value_args ) set( multi_value_args ) cmake_parse_arguments( _p "${options}" "${single_value_args}" "${multi_value_args}" ${_FIRST_ARG} ${ARGN} ) if(_p_UNPARSED_ARGUMENTS) ecbuild_critical("Unknown keywords given to ecbuild_find_perl(): \"${_p_UNPARSED_ARGUMENTS}\"") endif() find_package( Perl QUIET ) if( NOT PERL_EXECUTABLE AND _p_REQUIRED ) ecbuild_critical( "Failed to find Perl (REQUIRED)" ) endif() if( PERL_EXECUTABLE ) execute_process( COMMAND ${PERL_EXECUTABLE} -V:version OUTPUT_VARIABLE perl_version_output_variable RESULT_VARIABLE perl_version_return ) if( NOT perl_version_return ) string(REGEX REPLACE "version='([^']+)'.*" "\\1" PERL_VERSION ${perl_version_output_variable}) endif() # from cmake 2.8.8 onwards if( NOT PERL_VERSION_STRING ) set( PERL_VERSION_STRING ${PERL_VERSION} ) endif() ecbuild_debug("ecbuild_find_perl: found perl version ${PERL_VERSION_STRING} as ${PERL_EXECUTABLE}") endif() endmacro( ecbuild_find_perl ) ecbuild-3.13.1/cmake/ecbuild_find_python.cmake000066400000000000000000000142051513706760700213160ustar00rootroot00000000000000# (C) Copyright 2011- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation nor # does it submit to any jurisdiction. ############################################################################## #.rst: # # ecbuild_find_python # =================== # # Find Python interpreter, its version and the Python libraries. :: # # ecbuild_find_python( [ VERSION ] [ REQUIRED ] [ NO_LIBS ] ) # # Options # ------- # # VERSION : optional # minimum required version # # REQUIRED : optional # fail if Python was not found # # NO_LIBS : optional # only search for the Python interpreter, not the libraries # # Unless ``NO_LIBS`` is set, the ``python-config`` utility, if found, is used # to determine the Python include directories, libraries and link line. Set the # CMake variable ``PYTHON_NO_CONFIG`` to use CMake's FindPythonLibs instead. # # Output variables # ---------------- # # The following CMake variables are set if python was found: # # :Python_Interpreter_FOUND: Python interpreter was found # :Python_Development_FOUND: Python (development) libraries were found # :Python_FOUND: Python was found (both interpreter and libraries) # :Python_EXECUTABLE: Python executable # :Python_VERSION_MAJOR: Major version number # :Python_VERSION_MINOR: Minor version number # :Python_VERSION_PATCH: Patch version number # :Python_VERSION: Python version # :Python_INCLUDE_DIRS: Python include directories # :Python_LIBRARIES: Python libraries # :Python_SITELIB: Python site packages directory # # The following variables with prefix ``PYTHON_`` are now *DEPRECATED* and # will be removed in a future version; these variables are still set for # backwards compatibility. The new variables with prefix ``Python_`` # should be used instead. # # :PYTHONINTERP_FOUND: Python interpreter was found # :PYTHONLIBS_FOUND: Python libraries were found # :PYTHON_FOUND: Python was found (both interpreter and libraries) # :PYTHON_EXECUTABLE: Python executable # :PYTHON_VERSION_MAJOR: major version number # :PYTHON_VERSION_MINOR: minor version number # :PYTHON_VERSION_PATCH: patch version number # :PYTHON_VERSION_STRING: Python version # :PYTHON_INCLUDE_DIRS: Python include directories # :PYTHON_LIBRARIES: Python libraries # :PYTHON_SITE_PACKAGES: Python site packages directory # ############################################################################## set( __test_python ${CMAKE_CURRENT_LIST_DIR}/pymain.c ) function( ecbuild_find_python ) # parse parameters set( options REQUIRED NO_LIBS ) set( single_value_args VERSION ) set( multi_value_args ) cmake_parse_arguments( _p "${options}" "${single_value_args}" "${multi_value_args}" ${_FIRST_ARG} ${ARGN} ) if(_p_UNPARSED_ARGUMENTS) ecbuild_critical("Unknown keywords given to ecbuild_find_python(): \"${_p_UNPARSED_ARGUMENTS}\"") endif() if( _p_REQUIRED ) ecbuild_debug( "ecbuild_find_python: Searching for Python interpreter (required) ..." ) set( _p_REQUIRED REQUIRED ) else() ecbuild_debug( "ecbuild_find_python: Searching for Python interpreter ..." ) unset( _p_REQUIRED ) endif() # find python interpreter/executable # Search first without specifying the version, since doing so gives preference to the specified # version even though a never version of the interpreter may be available if ( _p_NO_LIBS ) find_package( Python ${_p_VERSION} COMPONENTS Interpreter ${_p_REQUIRED} ) set( __required_vars Python_FOUND Python_Interpreter_FOUND ) else() find_package( Python ${_p_VERSION} COMPONENTS Interpreter Development ${_p_REQUIRED} ) set( __required_vars Python_FOUND Python_Interpreter_FOUND Python_Development_FOUND ) endif() if( Python_Interpreter_FOUND ) ecbuild_debug( "ecbuild_find_python: Found Python interpreter version '${Python_VERSION}' at '${Python_EXECUTABLE}'" ) # python site-packages are located at... ecbuild_debug( "ecbuild_find_python: Python_SITELIB=${Python_SITELIB}" ) else() ecbuild_debug( "ecbuild_find_python: could NOT find Python interpreter!" ) endif() find_package_handle_standard_args( Python DEFAULT_MSG ${__required_vars} ) set( Python_FOUND ${Python_FOUND} PARENT_SCOPE ) set( Python_Interpreter_FOUND ${Python_Interpreter_FOUND} PARENT_SCOPE ) set( Python_Development_FOUND ${Python_Development_FOUND} PARENT_SCOPE ) set( Python_EXECUTABLE ${Python_EXECUTABLE} PARENT_SCOPE ) set( Python_VERSION_MAJOR ${Python_VERSION_MAJOR} PARENT_SCOPE ) set( Python_VERSION_MINOR ${Python_VERSION_MINOR} PARENT_SCOPE ) set( Python_VERSION_PATCH ${Python_VERSION_PATCH} PARENT_SCOPE ) set( Python_VERSION ${Python_VERSION} PARENT_SCOPE ) set( Python_INCLUDE_DIRS ${Python_INCLUDE_DIRS} PARENT_SCOPE ) set( Python_LIBRARIES ${Python_LIBRARIES} PARENT_SCOPE ) set( Python_SITELIB ${Python_SITELIB} PARENT_SCOPE ) # To keep backwards compatibility, the old variable names (PYTHON_*) are set as well set( PYTHON_FOUND "${Python_FOUND}" PARENT_SCOPE ) set( PYTHONINTERP_FOUND "${Python_Interpreter_FOUND}" PARENT_SCOPE ) set( PYTHONLIBS_FOUND "${Python_Development_FOUND}" PARENT_SCOPE ) set( PYTHON_EXECUTABLE "${Python_EXECUTABLE}" PARENT_SCOPE ) set( PYTHON_VERSION_MAJOR "${Python_VERSION_MAJOR}" PARENT_SCOPE ) set( PYTHON_VERSION_MINOR "${Python_VERSION_MINOR}" PARENT_SCOPE ) set( PYTHON_VERSION_PATCH "${Python_VERSION_PATCH}" PARENT_SCOPE ) set( PYTHON_VERSION_STRING "${Python_VERSION}" PARENT_SCOPE ) set( PYTHON_INCLUDE_DIRS "${Python_INCLUDE_DIRS}" PARENT_SCOPE ) set( PYTHON_LIBRARIES "${Python_LIBRARIES}" PARENT_SCOPE ) set( PYTHON_SITE_PACKAGES "${Python_SITELIB}" PARENT_SCOPE ) endfunction( ecbuild_find_python ) ecbuild-3.13.1/cmake/ecbuild_generate_config_headers.cmake000066400000000000000000000043041513706760700236060ustar00rootroot00000000000000# (C) Copyright 2011- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation nor # does it submit to any jurisdiction. ############################################################################## #.rst: # # ecbuild_generate_config_headers # =============================== # # Generates the ecBuild configuration header for the project with the system # introspection done by CMake. :: # # ecbuild_generate_config_headers( [ DESTINATION ] ) # # Options # ------- # # DESTINATION : optional # installation destination directory # ############################################################################## function( ecbuild_generate_config_headers ) # parse parameters set( options ) set( single_value_args DESTINATION ) set( multi_value_args ) cmake_parse_arguments( _p "${options}" "${single_value_args}" "${multi_value_args}" ${_FIRST_ARG} ${ARGN} ) if(_p_UNPARSED_ARGUMENTS) ecbuild_critical("Unknown keywords given to ecbuild_generate_config_headers(): \"${_p_UNPARSED_ARGUMENTS}\"") endif() # generate list of compiler flags string( TOUPPER ${PROJECT_NAME} PNAME_UPPER ) string( MAKE_C_IDENTIFIER "${PNAME_UPPER}" PNAME ) get_property( langs GLOBAL PROPERTY ENABLED_LANGUAGES ) foreach( lang ${langs} ) set( EC_${lang}_FLAGS "${CMAKE_${lang}_FLAGS} ${CMAKE_${lang}_FLAGS_${CMAKE_BUILD_TYPE_CAPS}}" ) endforeach() # ensure EC_HAVE_FORTRAN is defined for the header generation if(EC_HAVE_FORTRAN) set(EC_HAVE_FORTRAN 1) else() set(EC_HAVE_FORTRAN 0) endif() configure_file( ${ECBUILD_MACROS_DIR}/ecbuild_config.h.in ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}_ecbuild_config.h ) # install ecbuild configuration set( _destination ${INSTALL_INCLUDE_DIR} ) if( _p_DESTINATION ) set( _destination ${_p_DESTINATION} ) endif() install( FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}_ecbuild_config.h DESTINATION ${_destination} ) endfunction( ecbuild_generate_config_headers ) ecbuild-3.13.1/cmake/ecbuild_generate_fortran_interfaces.cmake000066400000000000000000000215051513706760700245260ustar00rootroot00000000000000# (C) Copyright 2011- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation nor # does it submit to any jurisdiction. ############################################################################## #.rst: # # ecbuild_generate_fortran_interfaces # =================================== # # Generates interfaces from Fortran source files. :: # # ecbuild_generate_fortran_interfaces( TARGET # DESTINATION # { DIRECTORIES [ ...] | FILES [ ...] } # [ PARALLEL ] # [ INCLUDE_DIRS ] # [ GENERATED ] # [ SOURCE_DIR ] # [ SUFFIX ] # [ FCM_CONFIG_FILE ] # ) # # Options # ------- # # TARGET : required # target name # # DESTINATION : required # sub-directory of ``CMAKE_CURRENT_BINARY_DIR`` to install target to # # DIRECTORIES | FILES : required # | list of directories in ``SOURCE_DIR`` in which to search for Fortran files to be processed, *or* # | list of Fortran files in ``SOURCE_DIR`` to be processed # # PARALLEL : optional, defaults to 1 # number of processes to use (always 1 on Darwin systems) # # INCLUDE_DIRS : optional # name of CMake variable to store the path to the include directory containing the resulting interfaces # # GENERATED : optional # name of CMake variable to store the list of generated interface files, including the full path to each # # SOURCE_DIR : optional, defaults to ``CMAKE_CURRENT_SOURCE_DIR`` # directory in which to look for the sub-directories or source files given as arguments to ``DIRECTORIES`` or ``FILES`` # # SUFFIX : optional, defaults to ".intfb.h" # suffix to apply to name of each interface file # # FCM_CONFIG_FILE : optional, defaults to the ``fcm-make-interfaces.cfg`` file in the ecbuild project # FCM configuration file to be used to generate interfaces # # Usage # _____ # # Given a list of directories, they will be recursively searched for Fortran # files of the form ``.[fF]``, ``.[fF]90``, ``.[fF]03`` or # ``.[fF]08``. Given a list of files, these must be an exact match and # contained within ``SOURCE_DIR``. Either ``DIRECTORIES`` or ``FILES`` (or # both) must be provided. For each matching file, a file ```` # will be created containing the interface blocks for all external subprograms # within it, where ```` is the value given to the ``SUFFIX`` option. If # a file contains no such subprograms, no interface file will be generated for # it. # ############################################################################## function( ecbuild_generate_fortran_interfaces ) find_program( FCM_EXECUTABLE fcm DOC "Fortran interface generator" HINTS ${CMAKE_SOURCE_DIR}/fcm ${CMAKE_BINARY_DIR}/fcm ${fcm_ROOT} ENV fcm_ROOT PATH_SUFFIXES bin ) if (NOT FCM_EXECUTABLE) include(FetchContent) set(ECBUILD_FCM_VERSION "2019.09.0" CACHE STRING "FCM version used to generate Fortran interfaces") FetchContent_Populate( fcm URL "https://github.com/metomi/fcm/archive/refs/tags/${ECBUILD_FCM_VERSION}.tar.gz" SOURCE_DIR ${CMAKE_BINARY_DIR}/fcm BINARY_DIR ${CMAKE_BINARY_DIR}/_deps/fcm-build SUBBUILD_DIR ${CMAKE_BINARY_DIR}/_deps/fcm-subbuild ) set( FCM_EXECUTABLE ${CMAKE_BINARY_DIR}/fcm/bin/fcm ) endif() if( NOT FCM_EXECUTABLE ) ecbuild_error( "ecbuild_generate_fortran_interfaces: fcm executable not found." ) endif() set( options ) set( single_value_args TARGET DESTINATION PARALLEL INCLUDE_DIRS GENERATED SOURCE_DIR SUFFIX FCM_CONFIG_FILE ) set( multi_value_args DIRECTORIES FILES ) cmake_parse_arguments( P "${options}" "${single_value_args}" "${multi_value_args}" ${_FIRST_ARG} ${ARGN} ) if( NOT DEFINED P_TARGET ) ecbuild_error( "ecbuild_generate_fortran_interfaces: TARGET argument missing" ) endif() if( NOT DEFINED P_DESTINATION ) ecbuild_error( "ecbuild_generate_fortran_interfaces: DESTINATION argument missing" ) endif() if( NOT DEFINED P_DIRECTORIES AND NOT DEFINED P_FILES ) ecbuild_error( "ecbuild_generate_fortran_interfaces: Neither DIRECTORIES nor FILES argument provided" ) endif() if( NOT DEFINED P_PARALLEL OR (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") ) set( P_PARALLEL 1 ) endif() ecbuild_debug_var( P_PARALLEL ) if( NOT DEFINED P_SOURCE_DIR ) set( P_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}" ) endif() if( NOT DEFINED P_SUFFIX ) set( P_SUFFIX ".intfb.h" ) endif() if( DEFINED P_FCM_CONFIG_FILE ) set( FCM_CONFIG_FILE ${P_FCM_CONFIG_FILE} ) endif() if( NOT FCM_CONFIG_FILE ) set( PROJECT_FCM_CONFIG_FILE "${PROJECT_SOURCE_DIR}/cmake/fcm-make-interfaces.cfg" ) if( EXISTS ${PROJECT_FCM_CONFIG_FILE} ) set( FCM_CONFIG_FILE ${PROJECT_FCM_CONFIG_FILE} ) ecbuild_debug( "ecbuild_generate_fortran_interfaces: fcm configuration found in ${PROJECT_FCM_CONFIG_FILE}" ) else() ecbuild_debug( "ecbuild_generate_fortran_interfaces: fcm configuration not found in ${PROJECT_FCM_CONFIG_FILE}" ) endif() endif() if( NOT FCM_CONFIG_FILE ) set( FCM_CONFIG_FILE "${ECBUILD_MACROS_DIR}/fcm-make-interfaces.cfg" ) set( FCM_CONFIG_FILE "${CMAKE_CURRENT_BINARY_DIR}/fcm-make-interfaces.${P_TARGET}.cfg" ) configure_file( "${ECBUILD_MACROS_DIR}/fcm-make-interfaces.cfg.in" "${FCM_CONFIG_FILE}" @ONLY ) endif() ecbuild_debug_var( FCM_CONFIG_FILE ) if( NOT EXISTS ${FCM_CONFIG_FILE} ) ecbuild_error( "ecbuild_generate_fortran_interfaces: needs fcm configuration in ${FCM_CONFIG_FILE}" ) endif() if( DEFINED P_DIRECTORIES ) foreach( _srcdir ${P_DIRECTORIES} ) if( _srcdir MATCHES "/$" ) ecbuild_critical("ecbuild_generate_fortran_interfaces: directory ${_srcdir} must not end with /") endif() ecbuild_list_add_pattern( LIST fortran_files SOURCE_DIR ${P_SOURCE_DIR} GLOB ${_srcdir}/*.[fF] ${_srcdir}/*.[fF]90 ${_srcdir}/*.[fF]03 ${_srcdir}/*.[fF]08 QUIET ) endforeach() string( REPLACE ";" " " _srcdirs "${P_DIRECTORIES}" ) endif() if( DEFINED P_FILES ) foreach( _srcfile ${P_FILES} ) ecbuild_list_add_pattern( LIST fortran_files SOURCE_DIR ${P_SOURCE_DIR} GLOB ${_srcfile} QUIET ) endforeach() string( REPLACE ";" " " _srcfiles "${P_FILES}" ) endif() string(JOIN " " _srcs "${_srcdirs}" "${_srcfiles}") set( _cnt 0 ) set( interface_files "" ) foreach( fortran_file ${fortran_files} ) #list( APPEND fullpath_fortran_files ${CMAKE_CURRENT_SOURCE_DIR}/${fortran_file} ) get_filename_component(base ${fortran_file} NAME_WE) set( interface_file "${CMAKE_CURRENT_BINARY_DIR}/${P_DESTINATION}/interfaces/include/${base}${P_SUFFIX}" ) list( APPEND interface_files ${interface_file} ) set_source_files_properties( ${interface_file} PROPERTIES GENERATED TRUE ) math(EXPR _cnt "${_cnt}+1") endforeach() ecbuild_info("Target ${P_TARGET} will generate ${_cnt} interface files using FCM") if( DEFINED P_GENERATED ) set( ${P_GENERATED} ${interface_files} PARENT_SCOPE ) endif() set( include_dir ${CMAKE_CURRENT_BINARY_DIR}/${P_DESTINATION}/interfaces/include ) set( ${P_INCLUDE_DIRS} ${include_dir} PARENT_SCOPE ) execute_process( COMMAND ${CMAKE_COMMAND} -E make_directory ${include_dir} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} ) set( _fcm_lock ${CMAKE_CURRENT_BINARY_DIR}/${P_DESTINATION}/fcm-make.lock ) set( _timestamp ${CMAKE_CURRENT_BINARY_DIR}/${P_DESTINATION}/generated.timestamp ) add_custom_command( OUTPUT ${_timestamp} COMMAND ${CMAKE_COMMAND} -E remove_directory ${_fcm_lock} COMMAND ${FCM_EXECUTABLE} make -j ${P_PARALLEL} --config-file=${FCM_CONFIG_FILE} interfaces.ns-incl=${_srcs} interfaces.source=${P_SOURCE_DIR} COMMAND ${CMAKE_COMMAND} -E touch ${_timestamp} DEPENDS ${fortran_files} COMMENT "[fcm] Generating ${_cnt} Fortran interface files for target ${P_TARGET} in ${CMAKE_CURRENT_BINARY_DIR}/${P_DESTINATION}/interfaces/include" WORKING_DIRECTORY ${P_DESTINATION} VERBATIM ) add_custom_target(${P_TARGET}_gen DEPENDS ${_timestamp} ) ecbuild_add_library(TARGET ${P_TARGET} TYPE INTERFACE DEPENDS ${P_TARGET}_gen) target_include_directories(${P_TARGET} INTERFACE $) endfunction( ecbuild_generate_fortran_interfaces ) ecbuild-3.13.1/cmake/ecbuild_generate_project_config.cmake000066400000000000000000000055621513706760700236500ustar00rootroot00000000000000# (C) Copyright 2019- ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation nor # does it submit to any jurisdiction. ############################################################################## #.rst: # # ecbuild_generate_project_config # =============================== # # Generate the -config.cmake file :: # # ecbuild_generate_project_config(