summaryrefslogtreecommitdiffstats
path: root/Tests/GhsMulti/GhsMultiCompilerOptions/CMakeLists.txt
blob: 925070917b4797f2f8bb4d5036f34bcc3df17a6c (plain)
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.

cmake_minimum_required(VERSION 3.12 FATAL_ERROR)

project(test C)

message("Copy project")
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt.in
  ${CMAKE_CURRENT_BINARY_DIR}/src/CMakeLists.txt COPYONLY)

file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/test.c
  DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/src
)

message("Building project")
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
try_compile(RESULT
  ${CMAKE_CURRENT_BINARY_DIR}/build
  ${CMAKE_CURRENT_BINARY_DIR}/src
  test
  CMAKE_FLAGS
    -DRUN_TEST=${RUN_TEST}
    -DCMAKE_BUILD_TYPE=${RUN_TEST_BUILD_TYPE}
  OUTPUT_VARIABLE OUTPUT)

message("Output from build:\n${OUTPUT}")
if (RUN_TEST STREQUAL "RELEASE_FLAGS")
  find_file (fileName test_none.gpj
    ${CMAKE_CURRENT_BINARY_DIR}/build/test_none.dir
    )
  message("Parsing project file: ${fileName}")
  file(STRINGS ${fileName} fileText)
  set(opt "-unexpected_release_option")
  string(FIND "${fileText}" "${opt}" opt_found)
  if ( NOT opt_found EQUAL -1 )
    message(SEND_ERROR "Release option found: ${opt}")
  endif()
else()
  unset(fileName CACHE)
  find_file (fileName K1.gpj
    ${CMAKE_CURRENT_BINARY_DIR}/build/K1.dir
    )
  message("Parsing project file: ${fileName}")
  file(STRINGS ${fileName} fileText)
  set(opt "-required-debug-option")
  string(FIND "${fileText}" "${opt}" opt_found)
  if ( opt_found EQUAL -1 )
    message(SEND_ERROR "Missing debug option: ${opt}")
  endif()

  unset(fileName CACHE)
  find_file (fileName K2.gpj
    ${CMAKE_CURRENT_BINARY_DIR}/build/K2.dir
    )
  message("Parsing project file: ${fileName}")
  file(STRINGS ${fileName} fileText)
  set(opt "-required-debug-option")
  string(FIND "${fileText}" "${opt}" opt_found)
  if ( opt_found EQUAL -1 )
    message(SEND_ERROR "Missing debug option: ${opt}")
  endif()

  unset(fileName CACHE)
  find_file (fileName K3.gpj
    ${CMAKE_CURRENT_BINARY_DIR}/build/K3.dir
    )
  message("Parsing project file: ${fileName}")
  file(STRINGS ${fileName} fileText)
  set(opt "-required-debug-option")
  string(FIND "${fileText}" "${opt}" opt_found)
  if ( opt_found EQUAL -1 )
    message(SEND_ERROR "Missing debug option: ${opt}")
  endif()

  unset(fileName CACHE)
  find_file (fileName K4.gpj
    ${CMAKE_CURRENT_BINARY_DIR}/build/K4.dir
    )
  message("Parsing project file: ${fileName}")
  file(STRINGS ${fileName} fileText)
  set(opt "-required-debug-option")
  string(FIND "${fileText}" "${opt}" opt_found)
  if ( opt_found EQUAL -1 )
    message(SEND_ERROR "Missing debug option: ${opt}")
  endif()
endif()