From 9cc7be60d7004a45a1c87880f808144df9f58254 Mon Sep 17 00:00:00 2001 From: Sean Bryan Date: Mon, 4 Mar 2024 17:07:20 +1100 Subject: [PATCH] Add support for specifying CMake targets --- CMakeLists.txt | 4 ++-- build.bash | 18 +++++++++++++++++- documentation/docs/user_guide/installation.md | 8 ++++---- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f0f7c2c5b..b290aee93 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -145,7 +145,7 @@ add_executable( ) target_compile_options(cable PRIVATE ${CABLE_Fortran_FLAGS}) target_link_libraries(cable PRIVATE PkgConfig::NETCDF) -install(TARGETS cable RUNTIME) +install(TARGETS cable RUNTIME OPTIONAL) if(MPI_Fortran_FOUND) add_executable( @@ -159,5 +159,5 @@ if(MPI_Fortran_FOUND) ) target_compile_options(cable-mpi PRIVATE ${CABLE_Fortran_FLAGS}) target_link_libraries(cable-mpi PRIVATE PkgConfig::NETCDF MPI::MPI_Fortran) - install(TARGETS cable-mpi RUNTIME) + install(TARGETS cable-mpi RUNTIME OPTIONAL) endif() diff --git a/build.bash b/build.bash index aaec757f2..ddab76698 100755 --- a/build.bash +++ b/build.bash @@ -1,6 +1,7 @@ #!/bin/bash nproc_default=4 +targets_default=(all) script_name=$(basename "${0}") @@ -17,6 +18,10 @@ Options: Specify the compiler to use. -j Specify the number of parallel jobs in the compilation. By default this value is set to $nproc_default. + -t , --target + Build the CMake target instead of the default target + (${targets_default[*]}). This option may be used more than once + to specify multiple targets. -h, --help Show this screen. Enabling debug mode: @@ -29,6 +34,12 @@ Enabling verbose output from Makefile builds: To enable more verbose output from Makefile builds, specify the CMake option -DCMAKE_VERBOSE_MAKEFILE=ON when invoking $script_name. +Enabling serial only or MPI only builds: + + Serial only or MPI only builds can be done by specifying the --target + option when invoking $script_name where is the name + of either the serial or MPI executable. + EOF } @@ -48,6 +59,10 @@ while [ $# -gt 0 ]; do CMAKE_BUILD_PARALLEL_LEVEL=$2 shift ;; + -t|--target) + targets+=("$2") + shift + ;; -h|--help) show_help exit @@ -88,7 +103,8 @@ if hostname -f | grep gadi.nci.org.au > /dev/null; then fi export CMAKE_BUILD_PARALLEL_LEVEL="${CMAKE_BUILD_PARALLEL_LEVEL:=$nproc_default}" +: "${targets:=${targets_default[*]}}" cmake -S . -B build "${cmake_args[@]}" &&\ -cmake --build build &&\ +cmake --build build --target "${targets[@]}" &&\ cmake --install build --prefix . diff --git a/documentation/docs/user_guide/installation.md b/documentation/docs/user_guide/installation.md index 766556195..e6e389fbb 100644 --- a/documentation/docs/user_guide/installation.md +++ b/documentation/docs/user_guide/installation.md @@ -88,7 +88,7 @@ To execute the build, run: ./build.bash -This loads the required build dependencies and invokes CMake. Both serial and parallel (MPI) applications are built with a single invocation of CMake. **Note** the MPI executable will only be built if CMake can find the location of the installed MPI libraries. +This loads the required build dependencies and invokes CMake. Both serial and parallel (MPI) applications are built by default with a single invocation of CMake. **Note** the MPI executable will only be built if CMake can find the location of the installed MPI libraries. ### Cleaning the build @@ -106,9 +106,9 @@ The release build is default. To enable debug mode, specify the CMake option `-D To enable more verbose output from Makefile builds, specify the CMake option `-DCMAKE_VERBOSE_MAKEFILE=ON` when invoking `build.bash`. -### Parallel compilation +### Enabling serial only or MPI only builds: -By default, the compilation is done in parallel. The number of parallel jobs can be overwritten by setting the environment variable [`CMAKE_BUILD_PARALLEL_LEVEL`](https://cmake.org/cmake/help/latest/envvar/CMAKE_BUILD_PARALLEL_LEVEL.html). +Serial only or MPI only builds can be done by specifying the `--target ` option when invoking `build.bash` where `` is the name of either the serial or MPI executable. ???+ tip Run `./build.bash --help` for information on supported options. @@ -120,4 +120,4 @@ By default, the compilation is done in parallel. The number of parallel jobs can [build.bash-hostname-check]: https://github.com/CABLE-LSM/CABLE/blob/main/build.bash#L45-L55 [clean-build]: installation.md/#cleaning-the-build [build-system]: ../developer_guide/other_resources/build_system.md -[hive-forum-cable]: https://forum.access-hive.org.au/c/land/cable/18 \ No newline at end of file +[hive-forum-cable]: https://forum.access-hive.org.au/c/land/cable/18