Changeset View
Changeset View
Standalone View
Standalone View
modules/ECMCheckLinkerFlags.cmake
- This file was added.
1 | #.rest: | ||||
---|---|---|---|---|---|
2 | # CheckLinkerFlags | ||||
3 | # ---------------- | ||||
4 | # | ||||
5 | # Check support of a given linker flag | ||||
6 | # | ||||
7 | # ecm_check_linker_flags(flags, result) | ||||
8 | # | ||||
9 | # * result will be set to TRUE or FALSE if the linker accepts the flags. | ||||
10 | # | ||||
11 | #============================================================================= | ||||
12 | # Copyright 2018 Tobias C. Berner <tcberner@FreeBSD.org> | ||||
13 | # | ||||
14 | # Redistribution and use in source and binary forms, with or without | ||||
15 | # modification, are permitted provided that the following conditions | ||||
16 | # are met: | ||||
17 | # | ||||
18 | # 1. Redistributions of source code must retain the copyright | ||||
19 | # notice, this list of conditions and the following disclaimer. | ||||
20 | # 2. Redistributions in binary form must reproduce the copyright | ||||
21 | # notice, this list of conditions and the following disclaimer in the | ||||
22 | # documentation and/or other materials provided with the distribution. | ||||
23 | # | ||||
24 | # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | ||||
25 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||||
26 | # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||||
27 | # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | ||||
28 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||||
29 | # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||||
30 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||||
31 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||||
32 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||||
33 | # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||||
34 | #============================================================================= | ||||
35 | | ||||
36 | function(ecm_check_linker_flags linker_flags result) | ||||
37 | cmake_policy(SET CMP0056 NEW) | ||||
38 | set(CMAKE_EXE_LINKER_FLAGS "${linker_flags}") | ||||
39 | set(TEST_PROGRAM "int main() { return 0 ; }") | ||||
40 | set(TEST_FILE "${CMAKE_CURRENT_BINARY_DIR}/test_linker_flags.cc") | ||||
41 | file(WRITE "${TEST_FILE}" "${TEST_PROGRAM}") | ||||
42 | message(STATUS "Checking whether the linker supports '${linker_flags}' ...") | ||||
43 | try_compile(SUPPORTED | ||||
44 | "${CMAKE_CURRENT_BINARY_DIR}/test_linker_flags" | ||||
45 | "${TEST_FILE}" | ||||
46 | ) | ||||
47 | message(STATUS " supports '${linker_flags}': ${SUPPORTED}") | ||||
48 | if(SUPPORTED) | ||||
49 | set(${result} TRUE) | ||||
50 | else() | ||||
51 | set(${result} FALSE) | ||||
52 | endif() | ||||
53 | endfunction() |