0026993: Configuration, CMake - use the abstraction level of VTK instead CSF_VTK...
[occt.git] / adm / cmake / occt_defs_flags.cmake
CommitLineData
e713baee 1##
2
3if(FLAGS_ALREADY_INCLUDED)
4 return()
5endif()
6set(FLAGS_ALREADY_INCLUDED 1)
7
9f33b387 8
9if (MSVC)
10 add_definitions(/fp:precise)
11endif()
12
13# set compiler short name and choose SSE2 option for appropriate MSVC compilers
14# ONLY for 32-bit
15if (NOT CMAKE_SIZEOF_VOID_P EQUAL 8)
16 if (MSVC80 OR MSVC90 OR MSVC10)
17 add_definitions(/arch:SSE2)
18 endif()
19endif()
20
9f33b387 21if (WIN32)
57c28b61 22 add_definitions (-wd4996)
9f33b387 23elseif (APPLE)
57c28b61 24 add_definitions (-fexceptions -fPIC -DOCC_CONVERT_SIGNALS)
9f33b387 25else()
57c28b61 26 add_definitions (-fexceptions -fPIC -DOCC_CONVERT_SIGNALS)
9f33b387 27endif()
28
29# enable structured exceptions for MSVC
30string (REGEX MATCH "EHsc" ISFLAG "${CMAKE_CXX_FLAGS}")
31if (ISFLAG)
32 string (REGEX REPLACE "EHsc" "EHa" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
33elseif (WIN32)
34 set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -EHa")
35endif()
36
57c28b61 37# remove _WINDOWS flag if it exists
38string (REGEX MATCH "/D_WINDOWS" IS_WINDOWSFLAG "${CMAKE_CXX_FLAGS}")
39if (IS_WINDOWSFLAG)
a6874708 40 message (STATUS "Info: /D_WINDOWS has been removed from CMAKE_CXX_FLAGS")
57c28b61 41 string (REGEX REPLACE "/D_WINDOWS" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
42endif()
43
44# remove WIN32 flag if it exists
45string (REGEX MATCH "/DWIN32" IS_WIN32FLAG "${CMAKE_CXX_FLAGS}")
46if (IS_WIN32FLAG)
a6874708 47 message (STATUS "Info: /DWIN32 has been removed from CMAKE_CXX_FLAGS")
57c28b61 48 string (REGEX REPLACE "/DWIN32" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
49endif()
50
51# remove _WINDOWS flag if it exists
52string (REGEX MATCH "/D_WINDOWS" IS_WINDOWSFLAG "${CMAKE_C_FLAGS}")
53if (IS_WINDOWSFLAG)
a6874708 54 message (STATUS "Info: /D_WINDOWS has been removed from CMAKE_C_FLAGS")
57c28b61 55 string (REGEX REPLACE "/D_WINDOWS" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
56endif()
57
58# remove WIN32 flag if it exists
59string (REGEX MATCH "/DWIN32" IS_WIN32FLAG "${CMAKE_C_FLAGS}")
60if (IS_WIN32FLAG)
a6874708 61 message (STATUS "Info: /DWIN32 has been removed from CMAKE_C_FLAGS")
57c28b61 62 string (REGEX REPLACE "/DWIN32" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
63endif()
64
9f33b387 65# remove DEBUG flag if it exists
66string (REGEX MATCH "-DDEBUG" IS_DEBUG_CXX "${CMAKE_CXX_FLAGS_DEBUG}")
67if (IS_DEBUG_CXX)
a6874708 68 message (STATUS "Info: -DDEBUG has been removed from CMAKE_CXX_FLAGS_DEBUG")
9f33b387 69 string (REGEX REPLACE "-DDEBUG" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
70endif()
71
72string (REGEX MATCH "-DDEBUG" IS_DEBUG_C "${CMAKE_C_FLAGS_DEBUG}")
73if (IS_DEBUG_C)
a6874708 74 message (STATUS "Info: -DDEBUG has been removed from CMAKE_C_FLAGS_DEBUG")
9f33b387 75 string (REGEX REPLACE "-DDEBUG" "" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}")
76endif()
9f33b387 77# enable parallel compilation on MSVC 9 and above
78if (MSVC AND NOT MSVC70 AND NOT MSVC80)
79 set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -MP")
80endif()
81
82# generate a single response file which enlist all of the object files
83SET(CMAKE_C_USE_RESPONSE_FILE_FOR_OBJECTS 1)
84SET(CMAKE_CXX_USE_RESPONSE_FILE_FOR_OBJECTS 1)
7dc2c165 85# increase compiler warnings level (-W4 for MSVC, -Wextra for GCC)
9f33b387 86if (MSVC)
87 if (CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
88 string (REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
89 else()
90 set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
91 endif()
a082e7d0 92elseif (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
7dc2c165 93 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
9f33b387 94endif()
95
19286d7c 96if (DEFINED CMAKE_COMPILER_IS_GNUCXX OR "x${CMAKE_CXX_COMPILER_ID}" STREQUAL "xClang")
97 set (CMAKE_CXX_FLAGS "-std=c++0x ${CMAKE_CXX_FLAGS}")
98endif()
99
41ec04db 100# Optimize size of binaries
4d8eca1d 101if (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX OR MINGW)
41ec04db 102 set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -s")
103 set (CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -s")
104endif()
105
9f33b387 106set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DNo_Exception")
57c28b61 107set (CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -DNo_Exception")