File: dcmtkTryCompile.cmake

package info (click to toggle)
dcmtk 3.6.5-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 54,900 kB
  • sloc: cpp: 274,805; ansic: 47,345; makefile: 5,313; sh: 4,250; perl: 277; xml: 182; lex: 103
file content (43 lines) | stat: -rw-r--r-- 1,742 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#
# Check if a given C++ source code compiles
#
# VAR - Variable to set to 1 or 0, depending on the result
# MESSAGE - Description of the thing that we are checking for
# SOURCE - Code to compile
#
# All extra arguments are passed to try_compile().
#

macro(DCMTK_TRY_COMPILE VAR MESSAGE SOURCE)
    set(DCMTK_TRY_COMPILE_FILE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src.cxx")

    # Do nothing if the variable is already set
    if(NOT DEFINED "${VAR}")
        message(STATUS "Checking whether ${MESSAGE}")
        file(WRITE "${DCMTK_TRY_COMPILE_FILE}" "${SOURCE}\n")
        if(DCMTK_TRY_COMPILE_REQUIRED_CMAKE_FLAGS)
            set(DCMTK_TRY_COMPILE_CMAKE_FLAGS CMAKE_FLAGS ${DCMTK_TRY_COMPILE_REQUIRED_CMAKE_FLAGS})
        else()
            DCMTK_UNSET(DCMTK_TRY_COMPILE_CMAKE_FLAGS)
        endif()
        try_compile(${VAR}
                    "${CMAKE_BINARY_DIR}"
                    "${DCMTK_TRY_COMPILE_FILE}"
                    ${DCMTK_TRY_COMPILE_CMAKE_FLAGS}
                    OUTPUT_VARIABLE OUTPUT
                    ${ARGN})
        if(${VAR})
            message(STATUS "Checking whether ${MESSAGE} -- yes")
            set(${VAR} 1 CACHE INTERNAL "${MESSAGE}")
            file(APPEND "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log"
                 "${MESSAGE} passed with the following output:\n"
                 "${OUTPUT}\n")
        else()
            message(STATUS "Checking whether ${MESSAGE} -- no")
            set(${VAR} 0 CACHE INTERNAL "${MESSAGE}")
            file(APPEND "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log"
                 "${MESSAGE} failed with the following output:\n"
                 "${OUTPUT}\n")
        endif()
    endif()
endmacro()