Salome HOME
Synchronize adm files
[tools/documentation.git] / CMakeModules / SalomeSetupPlatform.cmake
1 # Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
2 #
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License, or (at your option) any later version.
7 #
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 # Lesser General Public License for more details.
12 #
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 #
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 #
19
20 ## Detect architecture
21 IF(WIN32)
22   SET(MACHINE WINDOWS)
23 ELSE()
24   SET(MACHINE PCLINUX)
25 ENDIF()
26
27 ## Test for 64 bits
28 IF(CMAKE_SIZEOF_VOID_P EQUAL 8)
29   SET(MACHINE_IS_64 TRUE)
30 ELSE()
31   SET(MACHINE_IS_64 FALSE)
32 ENDIF()
33
34 ## Force CMAKE_BUILD_TYPE to Release if not set
35 IF(NOT CMAKE_BUILD_TYPE)
36   SET(CMAKE_BUILD_TYPE $ENV{CMAKE_BUILD_TYPE})
37 ENDIF(NOT CMAKE_BUILD_TYPE)
38 IF(NOT CMAKE_BUILD_TYPE)
39   SET(CMAKE_BUILD_TYPE Release)
40 ENDIF(NOT CMAKE_BUILD_TYPE)
41
42 ## Define the log level according to the build type
43 IF(CMAKE_BUILD_TYPE STREQUAL "DEBUG" OR CMAKE_BUILD_TYPE STREQUAL "Debug")
44   SET(PYLOGLEVEL DEBUG)
45 ELSE()
46   SET(PYLOGLEVEL WARNING)
47 ENDIF()
48
49 ## Make all warnings errors on non-windows platforms
50 #  CURRENTLY DISABLED
51 IF(NOT (WIN32 OR APPLE))
52   SET(ADD_WERROR ON)
53   SET(NAMES ACCEPT_SALOME_WARNINGS ACCEPT_${MODULE}_WARNINGS I_AM_A_TROLL_I_DO_NOT_FIX_${MODULE}_WARNINGS)
54   FOREACH(name ${NAMES})
55     SET(VAL $ENV{${name}})
56     IF("${VAL}" STREQUAL "0")
57       SET(ADD_WERROR ON)
58     ENDIF()
59     IF("${VAL}" STREQUAL "1")
60       SET(ADD_WERROR OFF)
61     ENDIF()
62   ENDFOREACH()
63   
64   IF(ADD_WERROR)
65 #    SET(CMAKE_C_FLAGS "-Werror")
66 #    SET(CMAKE_CXX_FLAGS "-Werror")
67   ENDIF()
68 ENDIF()
69
70 ## TODO: remove this ?
71 #IF(WIN32)
72 #    MARK_AS_ADVANCED(CLEAR CMAKE_CONFIGURATION_TYPES)
73 #    SET(CMAKE_CONFIGURATION_TYPES ${CMAKE_BUILD_TYPE} CACHE STRING "compilation types" FORCE)
74 #ELSE()
75 #    IF(CMAKE_BUILD_TYPE STREQUAL Debug)
76 #      SET(CMAKE_C_FLAGS_DEBUG "-g")
77 #      SET(CMAKE_CXX_FLAGS_DEBUG "-g")
78 #    ENDIF(CMAKE_BUILD_TYPE STREQUAL Debug)
79 #    IF(CMAKE_BUILD_TYPE STREQUAL Release)
80 #      SET(CMAKE_C_FLAGS_RELEASE "-O1 -DNDEBUG")
81 #      SET(CMAKE_CXX_FLAGS_RELEASE "-O1 -DNDEBUG")
82 #    ENDIF(CMAKE_BUILD_TYPE STREQUAL Release)
83 #ENDIF()
84
85 IF(WIN32)
86   ## Windows specific:  
87   ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS)  # To disable windows warnings for strcpy, fopen, ...
88   ADD_DEFINITIONS(-D_SCL_SECURE_NO_WARNINGS)  # To disable windows warnings generated by checked iterators(e.g. std::copy, std::transform, ...)
89   ADD_DEFINITIONS(-DWNT -DWIN32)
90   ADD_DEFINITIONS(-D_WIN32_WINNT=0x0500)      # Windows 2000 or later API is required
91   ADD_DEFINITIONS(-DPPRO_NT)                  # For medfile
92   #ADD_DEFINITIONS(-D_USE_MATH_DEFINES)        # for MEDMEM
93     
94   SET(PLATFORM_LIBS Ws2_32.lib)
95   LIST(APPEND PLATFORM_LIBS Userenv.lib)      # At least for GEOM suit
96
97 ################################################################################################
98 #
99 # RNV: In the SALOME sometimes operating with STL collections is done in not fully valid way. 
100 #      To avoid run-time exception in Debug mode default values of the _SECURE_SCL, 
101 #      _SECURE_SCL_THROWS and _HAS_ITERATOR_DEBUGGING macros were redefined. It solved a problem 
102 #      then we used tne Microsoft Visual Studio 2008 to build SALOME on Windows platform.
103 #      But in the Microsoft Visual Studio 2010 these macros affect on the size of STL collection 
104 #      classes(in difference from the Microsoft Visual Studio 2008: in this version of MSVS size
105 #      of the STL collection  classes does not depend on these macros).
106 #      All pre-requisite products are built by MSVS 2010 in Debug mode with the default 
107 #      values of the metioned above macros (namely _SECURE_SCL=1, _HAS_ITERATOR_DEBUGGING=1 and
108 #      _SECURE_SCL_THROWS=1). So SALOME modules should be build in the same configuration.
109 #
110 ################################################################################################
111 #
112 #  # Disable iterator debugging on WINDOWS to avoid runtime error during checking iterators
113 #    # _SECURE_SCL
114 #    #             If defined as 1, unsafe iterator use causes a runtime error. 
115 #    #             If defined as 0, checked iterators are disabled.
116 #    #             The default value for _SECURE_SCL is 1
117 #    # _SECURE_SCL_THROWS
118 #    #             If defined as 1, an out of range iterator use causes an exception at runtime.
119 #    #             If defined as 0, the program is terminated by calling invalid_parameter. 
120 #    #             The default value for _SECURE_SCL_THROWS is 0
121 #  
122 #  ADD_DEFINITIONS(-D_SECURE_SCL=0 -D_SECURE_SCL_THROWS=0)
123 #
124 #    # The symbol _HAS_ITERATOR_DEBUGGING can be used to turn off the iterator debugging feature in a debug build
125 #    #             If defined as 1, iterator debugging is enabled. 
126 #    #             If defined as 0, iterator debugging is disabled.
127 #    #             The default value for _HAS_ITERATOR_DEBUGGING is 1
128 #
129 #  IF(NOT CMAKE_BUILD_TYPE STREQUAL "RELEASE" AND NOT CMAKE_BUILD_TYPE STREQUAL "Release")
130 #    ADD_DEFINITIONS(-D_HAS_ITERATOR_DEBUGGING=0)  
131 #  ENDIF(NOT CMAKE_BUILD_TYPE STREQUAL "RELEASE" AND NOT CMAKE_BUILD_TYPE STREQUAL "Release")
132 ################################################################################################
133   
134   IF(MACHINE_IS_64)
135     SET(SIZE_OF_LONG 4)                          # set sizeof(long) to 4 byte
136   ELSE()
137     SET(SIZE_OF_LONG ${CMAKE_SIZEOF_VOID_P})     # set sizeof(long) the same as size of pointers
138   ENDIF()
139 ELSE()
140   ## Linux specific:
141   SET(PLATFORM_LIBS dl)    # Dynamic loading (dlopen, dlsym)
142   IF(MACHINE_IS_64) 
143     ADD_DEFINITIONS(-DPCLINUX64)
144   ENDIF(MACHINE_IS_64)
145 ENDIF()
146
147 ## define _DEBUG_ macro
148 IF(NOT CMAKE_BUILD_TYPE STREQUAL "RELEASE" AND NOT CMAKE_BUILD_TYPE STREQUAL "Release")
149   ADD_DEFINITIONS(-D_DEBUG_)
150 ENDIF()
151
152 ## Apple specific:
153 IF(APPLE)
154   SET(CMAKE_C_COMPILER gcc)
155   SET(CMAKE_CXX_COMPILER g++)
156   # because default is clang(llvm) with mountain lion at least
157 ENDIF()
158
159 # Compiler flags for coverage testing
160 IF(NOT WIN32) 
161   OPTION(SALOME_BUILD_FOR_GCOV "Add the compilation flags for GCov/LCov" OFF)
162   MARK_AS_ADVANCED(SALOME_BUILD_FOR_GCOV)
163   IF(SALOME_BUILD_FOR_GCOV)
164     SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
165     SET(CMAKE_C_FLAGS    "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
166   ENDIF()
167 ENDIF()