Commit Graph

96 Commits

Author SHA1 Message Date
Kitware Robot
1772622772 LICENSE: Replace references to Copyright.txt with LICENSE.rst
```
git grep -lz 'Copyright.txt or https://cmake.org/licensing ' |
  while IFS= read -r -d $'\0' f ; do
    sed -i '/Copyright.txt or https:\/\/cmake.org\/licensing / {
              s/Copyright.txt/LICENSE.rst/
            }' "$f" ; done
```
2025-03-03 10:43:35 -05:00
Brad King
7afa58b15d Modules/Find*: Include FindPackageHandleStandardArgs normally
Since commit d74210a8bd (CMP0017: Remove support for OLD behavior,
2024-11-17) we can rely on CMP0017's NEW behavior unconditionally.
Calling `include(FindPackageHandleStandardArgs)` in a builtin module
will always get the builtin `FindPackageHandleStandardArgs`.
2025-01-30 08:53:12 -05:00
Peter Kokot
4e6a13f211 Use lower case style for commands
Where possible this syncs the CS for command names:

- check_c_source_compiles()
- check_cxx_compiler_flag()
- check_cxx_source_compiles()
- check_cxx_symbol_exists()
- check_include_file_cxx()
- check_include_file()
- check_include_files()
- check_library_exists()
- check_source_compiles()
- check_struct_has_member()
- check_symbol_exists()
- check_type_size()
- cmake_dependent_option()
- cmake_parse_arguments()
- feature_summary()
- file()
- find_package_handle_standard_args()
- if(), endif...
- install(FILES)
- list()
- message()
- pkg_check_modules()
- select_library_configurations()
- set_package_info()
- test_big_endian()
2025-01-28 13:51:46 -05:00
Harry Mallon
d7963aa9ee FindThreads: Filter -pthread out for compatibility with Swift linker 2023-01-31 09:11:08 +00:00
Brad King
0f688386ea Modules: Drop redundant check logging to CMakeOutput.log and CMakeError.log
`try_compile` and `try_run` now automatically log checks using them to
`CMakeConfigureLog.yaml`.

Add `LOG_DESCRIPTION` arguments to some `try_compile` calls to
replace the description previously written to the old logs.

Issue: #23200
2023-01-18 16:41:01 -05:00
Matthew Woehlke
db76876db5 Modules: Use new SOURCES_FROM_* try_compile (1/2)
Modify some modules that ship with CMake to use the new SOURCES_FROM_*
arguments to try_compile / try_run as added by commits cb14ae2b87
(try_compile: Add SOURCE_FROM_{ARG,VAR}, 2022-09-21) and 611d801790
(try_compile: Add SOURCE_FROM_FILE, 2022-09-22). This covers users which
previously either used an existing file (but sometimes needed to rename
it), or which wrote out their source in entirety. It does NOT cover
users that actually need configure_file functionality, as those will be
more involved to update and will thus be tackled in part 2.
2022-09-27 13:29:52 -04:00
Matthew Woehlke
2edf0fc6d7 Modules: Use new keyword-dispatched try_compile signature
Modify most of the modules that ship with CMake to use the new
try_compile / try_run signatures added by commit aa9220d3a0
(try_compile: Add keyword-dispatched signature, 2022-09-02). This
improves debugging by each invocation using its own directory so that
the results of multiple invocations can be retained.

This does not cover any invocations which provide an entire project, as
that flavor of try_compile has not yet been updated.
2022-09-14 07:52:16 -04:00
Brad King
7203963788 FindThreads: Skip check for -pthread flag when targeting the MSVC ABI
Since commit 3257c34073 (FindThreads: avoid failing in AIX when using
-D_XOPEN_SOURCE=500, 2022-04-30, v3.24.0-rc1~197^2) we no longer check
for `pthreads.h` before checking for the `-pthread` flag.  Compilers
targeting the MSVC ABI do not have such a flag, so avoid performing the
check unnecessarily.

Fixes: #23829
2022-08-08 12:41:57 -04:00
Carlo Marcelo Arenas Belón
3257c34073 FindThreads: avoid failing in AIX when using -D_XOPEN_SOURCE=500
Current FindThreads fails in AIX (tested on 7.1 and 7.2) when using
additional compilation flags (ex: -D_XOPEN_SOURCE=500) because the
linker might need additional flags to link and those aren't yet known
by the time check_include("pthread.h") is run (which is also the first
test).

Remove the check for it and all supporting code and rely instead on
the compilation test that will be done later to find the correct
syntax to use, and that confirms it exists implicitly.
2022-05-03 12:26:18 -04:00
Brad King
c53748a377 FindThreads: Factor out helper macro for libc check 2022-04-26 13:54:53 -04:00
Brad King
564385194b FindThreads: Avoid repeating check for -pthread flag
When `THREADS_PREFER_PTHREAD_FLAG` is enabled, we check for it before
the thread libraries.  We do not need to check after them too.
2022-04-26 13:54:53 -04:00
Brad King
41ef904e81 FindThreads: Simplify conditions for not-in-libc checks
If `CMAKE_HAVE_LIBC_PTHREAD` is true, we also set `Threads_FOUND` to
true, which blocks all the other checks from running.
2022-04-26 13:54:53 -04:00
Brad King
cbe7550d99 FindThreads: Remove unnecessary condition
The `THREADS_HAVE_PTHREAD_ARG` cache entry cannot be defined unless
FindThreads has already been executed, perhaps by a previous run of
CMake, or a previous `find_package(Threads)` call.  In that case, the
other alternatives will also already have been checked and results
cached.
2022-04-26 13:54:53 -04:00
Brad King
1ee8c545dd FindThreads: Clarify internal helper macro names 2022-04-26 13:54:53 -04:00
Brad King
5b5cd92363 FindThreads: Drop strange SunOS+pthread.h+thr_create combination
Solaris has provided pthreads for a long time, so we probably never
get to this combination anyway.
2022-04-26 13:54:53 -04:00
Brad King
c9bd462c08 FindThreads: Drop unused internal CMAKE_HAVE_THREADS_LIBRARY variable
This internal variable has not been used since commit 46368eddfd
(FindThreads: move checking of the -pthread compiler flag into a macro,
2014-10-06, v3.1.0-rc1~21^2~2).  It has never been documented for public
use.
2022-04-26 13:54:53 -04:00
Brad King
2e67438cb2 Merge topic 'FindThreads-revert-libc-pthread-flag'
c6da90bd39 FindThreads: Revert "Honor THREADS_PREFER_PTHREAD_FLAG when ... in libc"

Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: buildbot <buildbot@kitware.com>
Merge-request: !7025
2022-03-01 08:38:00 -05:00
Brad King
c6da90bd39 FindThreads: Revert "Honor THREADS_PREFER_PTHREAD_FLAG when ... in libc"
Revert commit 5efb6fb516 (FindThreads: Honor THREADS_PREFER_PTHREAD_FLAG
when pthread is found in libc, 2021-11-03, v3.21.5~4^2).  The check for
the `-pthread` flag can pass on compilers like XL, that interprets it as
`-p -t hread` and returns zero.  Prior to that commit, we did not use
the check in the `CMAKE_HAVE_LIBC_PTHREAD` code path.  Now we do, it
succeeds, and we incorrectly add the `-pthread` flag for XL.

This change was backported to the 3.21 and 3.22 release series long
after they initially came out.  Since there may be more cases where we
now add `-pthread` incorrectly, it is simplest to revert the change in
all release series pending further investigation.

Fixes: #23270
2022-02-28 12:53:15 -05:00
Mattias Ellert
5efb6fb516 FindThreads: Honor THREADS_PREFER_PTHREAD_FLAG when pthread is found in libc
The `-pthread` flag tells the compiler/linker to link to additional
libraries needed for thread support (e.g. libatomic on riscv64). The
flag therefore should be used if requested using
`THREADS_PREFER_PTHREAD_FLAG` also when the pthread functions are
found in libc.
2022-01-26 08:50:16 -05:00
Mattias Ellert
68285bc8a9 FindThreads: Honor THREADS_PREFER_PTHREAD_FLAG when pthread is found in libc
The `-pthread` flag tells the compiler/linker to link to additional
libraries needed for thread support (e.g. libatomic on riscv64). The
flag therefore should be used if requested using
`THREADS_PREFER_PTHREAD_FLAG` also when the pthread functions are
found in libc.
2021-11-10 14:29:09 +01:00
Mattias Ellert
d897391782 Fix typo in comment
The comment lists -lpthread twice, when "-lpthreads, -lpthread" is meant.
Also the grammar (did not found) is incorrect.
2021-09-06 06:54:51 +02:00
Orgad Shaneh
ddcd1469e8 MSYS: Add support for running under MSYS runtime environment
Detect MSYS as CYGWIN, with the required adaptations.
2021-04-26 14:27:34 -04:00
Robert Maynard
d6da6784bf FindThreads: Reduce amount of false positive error logging
When a CMake based project fails, users start looking at
CMakeError.log and think that the FindThread output is
the problem, but it is a false positive.

Now FindThreads only logs to `CMakeError.log` when it fails
to find a suitable flag, reducing the amount of false positives in `CMakeError.log`.

Fixes #16540, Fixes #19344
2021-04-06 15:51:34 -04:00
Nikita Nemkin
8fea95319b Help: Add .. versionadded directives to module docs
Issue: #19715
2020-12-02 21:00:30 +05:00
Pavel Otchertsov
6ef64013ba
FindThreads: Add missing static keyword in pthread test code
When CMAKE_C_FLAGS contains '-Werror -Wmissing-prototypes'
the pthread test code check fails with error:
"src.c:3:7: error: no previous prototype for 'test_func' [-Werror=missing-prototypes]".
Adding 'static' keyword to 'test_func' fixes it.
2020-09-18 23:24:56 +03:00
Tobias Ribizel
80d37167fe Find{Threads,MPI}: Add support for CUDA with Clang
Currently CMake passes `-Xcompiler -pthread` flags to CUDA compilers
irrespective of the actual CUDA compiler ID.  This makes sure the
additional `-Xcompiler` flag is only used with nvcc.
2020-05-25 11:17:52 -04:00
Rolf Eike Beer
1502f281dd FindThreads: Improve documentation
Issue: #19823
2020-03-16 11:46:38 -04:00
Cristian Morales Vega
b328cbaadb FindThreads: Add pthread_cancel to program to test for pthreads in libc
When using ThreadSanitizer our existing CMAKE_HAVE_LIBC_PTHREAD test
program links using symbols from the tsan library.  Among the symbols
not provided by that library, `pthread_cancel()` seems to be the less
risky symbol to add to the check.

Fixes: #19981
2019-12-11 09:26:39 -05:00
Brad King
625b120572 Merge topic 'FindThreads-lib-flag'
f7ffefea7c FindThreads: Restore hard-coded '-l' flag on library name

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !4112
2019-12-05 11:40:35 -05:00
Brad King
f7ffefea7c FindThreads: Restore hard-coded '-l' flag on library name
Revert commit de5f123d3a (FindThreads: Do not hard-code '-l' flag on
library name, 2019-09-23, v3.16.0-rc1~71^2).  Some clients depend
on the value of `CMAKE_THREAD_LIBS_INIT` to contain a valid flag.

Fixes: #20061, #20065
2019-12-04 13:58:44 -05:00
Alex Turbov
7b2dd9dedc
Refactor: Use added message types in various modules
Co-Authored-By: Craig Scott <craig.scott@crascit.com>
2019-11-02 14:10:09 +02:00
Alan W. Irwin
de5f123d3a FindThreads: Do not hard-code '-l' flag on library name
When not using the `-pthread` flag we instead return a library to link
by name.  Previously we hard-coded the `-l` flag before the library
name.  When used with `target_link_libraries`, the hard-coded `-l` flag
is preserved rather than transformed into the link option preferred by
the toolchain in use.  Drop the explicit `-l` part to let CMake's
generators produce the proper way to link the threads library for the
current toolchain.

Fixes: #19747
2019-09-23 10:43:27 -04:00
Brad King
dfd2e0a4ed Merge topic 'FindThreads-doc-c++'
a38b63c1bb FindThreads: Drop incorrect docs about usage with C++

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !3391
2019-05-28 11:58:07 -04:00
Brad King
a38b63c1bb FindThreads: Drop incorrect docs about usage with C++
Drop the sentence added by commit 5a5a1d90f0 (Help: FindThreads not
needed with modern C++., 2019-01-09, v3.14.0-rc1~186^2) about not
needing the module with modern C++.  The module is often still needed.

Fixes: #19297
2019-05-28 11:36:27 -04:00
Naren Manimohan
2c43fb5be3 FindThreads: Fix pthread library check in GHS Multi Generator 2019-03-21 12:57:44 -04:00
JerryShih
d53317130e FindThreads: Use complete program to test for pthreads in libc
Our check for just `pthread_create` is not sufficient because there are
cases where that symbol may be found in libc but not all of pthreads.
We first tried to address this in commit e9a1ddc594 (FindThreads:
Replace the pthread symbol checking in libc., 2018-11-18,
v3.14.0-rc1~292^2) by switching to `pthread_kill`, but that had to be
reverted by commit 18320230ec (FindThreads: Revert libc symbol check to
pthread_create, 2019-02-27, v3.14.0-rc3~6^2) because there are other
cases where `pthread_kill` is in libc but the rest of pthreads is not.
Update our check to try a complete program using pthreads as an actual
application might.

Fixes: #18994
2019-03-06 11:16:32 +08:00
Brad King
18320230ec FindThreads: Revert libc symbol check to pthread_create
Since commit e9a1ddc594 (FindThreads: Replace the pthread symbol
checking in libc., 2018-11-18, v3.14.0-rc1~292^2) we check libc for
`pthread_kill` instead of `pthread_create`.  However, on FreeBSD
`pthread_kill` is in libc but not `pthread_create`.  Discussion in the
original merge request for the above commit also considered
`pthread_key_create`, `pthread_self`, and `pthread_attr_init`.  Every
symbol seems to have some reason it is not an appropriate choice.

Revert to the pre-3.14 behavior of using `pthread_create` pending
further investigation.
2019-02-27 07:33:31 -05:00
Brad King
e0267eb1d3 FindThreads: Fix libc check to use proper header for pthread_kill
In commit e9a1ddc594 (FindThreads: Replace the pthread symbol checking
in libc., 2018-11-18, v3.14.0-rc1~292^2) we switched to checking for
`pthread_kill` in libc but did not update the symbol check's header file
to match.  Add `signal.h` to get `pthread_kill`.  Keep `pthread.h`
anyway since the purpose of the check is to verify that the pthread API
works.

Fixes: #18984
2019-02-26 07:51:52 -05:00
Joachim Wuttke (o)
5a5a1d90f0 Help: FindThreads not needed with modern C++. 2019-01-09 11:03:44 +01:00
Brad King
83dab0c123 FindThreads: Drop IRIX-specific options and results
We do not need to support IRIX anymore, so drop relevant parts.  In
particular, the `CMAKE_THREAD_PREFER_PTHREAD` is frequently confused
with `THREADS_PREFER_PTHREAD_FLAG`.

Also remove references to the IRIX-specific options and results
from other modules and tests.
2018-12-07 13:33:01 -05:00
JerryShih
e9a1ddc594 FindThreads: Replace the pthread symbol checking in libc.
With asan build, we will have the pthread_create() symbol in libc. However,
libasan doesn't have full pthread implementation. We can't assume that we
have the pthread implementation in libc using pthread_create() symbol.
Replace the pthread_create() with pthread_kill() as a quick fix.
2018-12-03 16:05:59 +08:00
Brad King
69275d3b6a Merge topic 'cuda-thread-flags'
2cc050b53b CUDA: Add test for device linking when host linking uses threads
83c13ca44f FindThreads: Pass -pthread to CUDA compiler through -Xcompiler
cf92fd9ae9 Merge branch 'cuda-filter-device-link-items' into cuda-thread-flags
e768d96c74 CUDA: Filter out host link flags during device linking

Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: Kelly (KT) Thompson <kgt@lanl.gov>
Merge-request: !2512
2018-10-25 07:26:24 -04:00
Rolf Eike Beer
83c13ca44f FindThreads: Pass -pthread to CUDA compiler through -Xcompiler
Fixes: #18008
2018-10-24 10:15:41 -04:00
Kitware Robot
df4ed1e9ff Help: Convert remaining modules to block-style comments 2018-10-22 11:09:34 -04:00
Steffen Dettmer
d4e551a90b FindThreads: Drop try_run to improve cross-compiling support
Use `try_compile` instead of `try_run`.  It is not clear why `try_run`
was ever needed, and it does not work during cross-compiling.

Update the check's source file to remove code associated with actually
running things.  Also remove the ancient `__CLASSIC_C__` code path and
use a simple `int main(void)` as in `Modules/CheckIncludeFile.c.in`.

Fixes: #16920
2017-08-30 11:15:26 -04:00
Brad King
86578eccf2 Simplify CMake per-source license notices
Per-source copyright/license notice headers that spell out copyright holder
names and years are hard to maintain and often out-of-date or plain wrong.
Precise contributor information is already maintained automatically by the
version control tool.  Ultimately it is the receiver of a file who is
responsible for determining its licensing status, and per-source notices are
merely a convenience.  Therefore it is simpler and more accurate for
each source to have a generic notice of the license name and references to
more detailed information on copyright holders and full license terms.

Our `Copyright.txt` file now contains a list of Contributors whose names
appeared source-level copyright notices.  It also references version control
history for more precise information.  Therefore we no longer need to spell
out the list of Contributors in each source file notice.

Replace CMake per-source copyright/license notice headers with a short
description of the license and links to `Copyright.txt` and online information
available from "https://cmake.org/licensing".  The online URL also handles
cases of modules being copied out of our source into other projects, so we
can drop our notices about replacing links with full license text.

Run the `Utilities/Scripts/filter-notices.bash` script to perform the majority
of the replacements mechanically.  Manually fix up shebang lines and trailing
newlines in a few files.  Manually update the notices in a few files that the
script does not handle.
2016-09-27 15:14:44 -04:00
Felix Geyer
49e82c15d5 Fix spelling typos in comments and documentation (#16037)
The Debian package checker tool (lintian) detected several typos in
CMake.
2016-03-29 14:31:02 -04:00
Rolf Eike Beer
0b38424cf2 FindThreads: make the call to try_run() work also if only C++ is enabled
This isn't enough to make the whole module work with only C++ enabled.
2015-09-25 10:08:05 -04:00
Rolf Eike Beer
9924a212f6 FindThreads: replace CheckIncludeFiles by CheckIncludeFile
While at it, also add a branch using CheckIncludeFileCXX. Also give a better
error message if no supported language is enabled. C++ support isn't working
yet, but it has never worked.
2015-09-25 10:08:05 -04:00
Rolf Eike Beer
b7e5c5a23a FindThreads: introduce THREADS_PREFER_PTHREAD_FLAG (#14767) 2014-10-08 17:57:34 +02:00