~ubuntu-branches/debian/sid/simpleitk/sid

« back to all changes in this revision

Viewing changes to CMake/sitkCheckRequiredFlags.cmake

  • Committer: Package Import Robot
  • Author(s): Ghislain Antony Vaillant
  • Date: 2017-11-02 08:49:18 UTC
  • Revision ID: package-import@ubuntu.com-20171102084918-7hs09ih668xq87ej
Tags: upstream-1.0.1
ImportĀ upstreamĀ versionĀ 1.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#
 
2
# Sets the following variables:
 
3
#   SimpleITK_PRIVATE_COMPILE_OPTIONS
 
4
#   SimpleITK_PUBLIC_COMPILE_OPTIONS
 
5
#
 
6
# In particular, this marks the "-std=", and the "-stdlib=" as
 
7
# required, if present and check if c++11 is needed.
 
8
 
 
9
set( SimpleITK_PUBLIC_COMPILE_OPTIONS "")
 
10
set( SimpleITK_PRIVATE_COMPILE_OPTIONS "")
 
11
 
 
12
include(CheckCXXCompilerFlag)
 
13
 
 
14
if(MSVC)
 
15
  # /bigobj is required for windows builds because of the size of
 
16
  # some object files (CastImage for instance)
 
17
  # Also supress the pesky warning about std::vector not being marked
 
18
  # for export in the dll
 
19
  list(APPEND SimpleITK_PRIVATE_COMPILE_OPTIONS /bigobj /wd4251 )
 
20
 
 
21
  # Avoid some warnings
 
22
  add_definitions ( -D_SCL_SECURE_NO_WARNINGS )
 
23
 
 
24
 
 
25
  # force debug linking not to be incremental
 
26
  foreach( _varName
 
27
      CMAKE_EXE_LINKER_FLAGS_DEBUG
 
28
      CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO
 
29
      CMAKE_MODULE_LINKER_FLAGS_DEBUG
 
30
      CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO
 
31
      CMAKE_SHARED_LINKER_FLAGS_DEBUG
 
32
      CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO )
 
33
    if(DEFINED ${_varName})
 
34
      STRING(REGEX REPLACE "INCREMENTAL(:[a-zA-Z]+)?" "INCREMENTAL:NO" ${_varName} ${${_varName}})
 
35
    endif()
 
36
  endforeach()
 
37
 
 
38
endif()
 
39
 
 
40
if(MINGW)
 
41
  list(APPEND SimpleITK_PRIVATE_COMPILE_OPTIONS "-Wa,-mbig-obj" )
 
42
endif()
 
43
 
 
44
 
 
45
#
 
46
# Search CMAKE_CXX_FLAGS for flags that should be considered required,
 
47
# and propagated to other projects, via the
 
48
# SimpleITK_PUBLIC_COMPILE_OPTIONS variable.
 
49
#
 
50
 
 
51
string(REPLACE " " ";" cmake_cxx_flags_list "${CMAKE_CXX_FLAGS}")
 
52
 
 
53
# list of regular expressions flags that are to be required flags for SimpleITK
 
54
set(required_flags_regex_to_test
 
55
  "^-stdlib="
 
56
  "^-std=" # required to be last
 
57
)
 
58
 
 
59
foreach(f ${cmake_cxx_flags_list})
 
60
  foreach( _r ${required_flags_regex_to_test} )
 
61
    string(REGEX MATCH  ${_r} _HAS_FLAG ${f} )
 
62
    if (_HAS_FLAG )
 
63
      list(APPEND SimpleITK_PUBLIC_COMPILE_OPTIONS ${f})
 
64
    endif()
 
65
  endforeach()
 
66
endforeach()
 
67
 
 
68
#
 
69
# Check if we need to enable C++11 with a compiler flag
 
70
#
 
71
 
 
72
if(NOT _HAS_FLAG)
 
73
 
 
74
  check_cxx_compiler_flag( "-std=c++11" CXX_HAS_stdcxx11)
 
75
  if (CXX_HAS_stdcxx11)
 
76
 
 
77
    message(STATUS "Checking if c++11 is required...")
 
78
    try_compile(SITK_CHECK_CXX11
 
79
      "${PROJECT_BINARY_DIR}/CMakeTmp"
 
80
      "${CMAKE_CURRENT_LIST_DIR}/sitk_check_cxx11_required.cxx"
 
81
      OUTPUT_VARIABLE OUTPUT)
 
82
    if(${SITK_CHECK_CXX11})
 
83
      message(STATUS "Checking if c++11 is required... NO" )
 
84
    else()
 
85
      message(STATUS "Checking if c++11 is required... YES" )
 
86
      file(APPEND ${CMAKE_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/CMakeError.log
 
87
        "Checking if C++11 required try_compile failed with the following output:\n"
 
88
        "${OUTPUT}\n")
 
89
      list(APPEND SimpleITK_PUBLIC_COMPILE_OPTIONS "-std=c++11")
 
90
      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
 
91
    endif()
 
92
 
 
93
  endif()
 
94
 
 
95
endif()
 
96
 
 
97
list(REMOVE_DUPLICATES SimpleITK_PUBLIC_COMPILE_OPTIONS)
 
98
list(REMOVE_DUPLICATES SimpleITK_PRIVATE_COMPILE_OPTIONS)