Skip to content

Commit

Permalink
Support parallel builds with make (shibatch#491)
Browse files Browse the repository at this point in the history
Individual COMMANDS in define_custom_command are not guaranteed to
execute sequentially, meaning that the inline headers may be broken if
doing a parallel build with make. Each command is extracted into its
own custom_command (some are merged, such as subsequent sed calls) so
that CMake can properly make sense of the dependencies and generate
consistent headers in parallel.

* Atomise creation of inline header, alias, dispscalar, simd disp, sleefquad header and build
* Reuse existing atomic inline libm header generation for CUDA

Now that custom_commands are atomic, parallel builds should be
supported with make.

* Use CMake cat instead of shell cat

This requires minimum CMake 3.18, which is not particularly
recent. This provides a better cross-platform way of concatenating
files.
  • Loading branch information
joeramsay committed Dec 13, 2023
1 parent c0976bc commit ba403c0
Show file tree
Hide file tree
Showing 5 changed files with 308 additions and 374 deletions.
25 changes: 19 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,24 @@ function(command_arguments PROPNAME)
set(${PROPNAME} ${quoted_args} PARENT_SCOPE)
endfunction()

# Helper function for concatenating several files
function(sleef_concat_files)
cmake_parse_arguments(concat_required "" "OUTPUT" "SOURCES" ${ARGN})
if("${concat_required_OUTPUT}" STREQUAL "")
message(FATAL_ERROR "Must pass OUTPUT to sleef_concat_files")
endif()

if(NOT concat_required_SOURCES)
message(FATAL_ERROR "sleef_concat_files not passed any SOURCES")
endif()

add_custom_command(
OUTPUT ${concat_required_OUTPUT}
COMMAND ${CMAKE_COMMAND} -E cat ${concat_required_SOURCES} > ${concat_required_OUTPUT}
DEPENDS ${concat_required_SOURCES}
COMMAND_EXPAND_LISTS)
endfunction()

# Settings

set(SLEEF_ALL_SUPPORTED_EXTENSIONS
Expand Down Expand Up @@ -94,7 +112,7 @@ set(COSTOVERRIDE_RVVM2NOFMA 20)

#

cmake_minimum_required(VERSION 3.4.3)
cmake_minimum_required(VERSION 3.18)

if(${CMAKE_VERSION} VERSION_GREATER "3.14.99")
cmake_policy(SET CMP0091 NEW)
Expand Down Expand Up @@ -318,8 +336,3 @@ if(SLEEF_SHOW_CONFIG)
endif()
endif(SLEEF_SHOW_CONFIG)

if (NOT CMAKE_MAKE_PROGRAM MATCHES "ninja")
message("")
message("*** Note: Parallel build is only supported with Ninja ***")
message("")
endif()
4 changes: 2 additions & 2 deletions doc/build-with-cmake.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ Before using CMake you will need to install/build the binaries on your system.
Most systems have cmake already installed or provided by the standard package
manager. If that is not the case for you, please
[download](https://cmake.org/download/) and install now.
For building SLEEF, version 3.4.3 is the minimum required.
For building SLEEF, version 3.18 is the minimum required.

# Quick start

1. Make sure cmake is available on the command-line.
```
$ cmake --version
(should display a version number greater than or equal to 3.4.3)
(should display a version number greater than or equal to 3.18)
```

2. Download the tar from the
Expand Down
4 changes: 0 additions & 4 deletions doc/html/compile.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,6 @@ $ make test
$ sudo make install</pre>
</p>

<p>
<b style="color:red">Parallel build is only supported with Ninja.</b>
</p>

<br/>

<p>
Expand Down
Loading

0 comments on commit ba403c0

Please sign in to comment.