Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
avoid problem when freeing pointer with lb!=0
[simgrid.git] / CMakeLists.txt
1 cmake_minimum_required(VERSION 2.6)
2 ### Need to set rc ccompiler before enable language
3 if(WIN32)
4   SET(CMAKE_RC_COMPILER "windres")
5 endif()
6 project(SimGrid C)
7 if (enable_gtnets OR enable_ns3 OR enable_model-checking)
8   enable_language(CXX)
9 endif()
10
11 enable_language(CXX)
12
13 INCLUDE(CheckCCompilerFlag)
14 CHECK_C_COMPILER_FLAG(-fstack-cleaner HAVE_C_STACK_CLEANER)
15
16 if (APPLE) #MAC
17   set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
18   set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
19 endif()
20
21 if (NOT DEFINED enable_smpi OR enable_smpi) # smpi is enabled by default
22   # Call enable_language(Fortran) in order to load the build rules for
23   # this language, needed by teshsuite/smpi/mpich-test/.  Use
24   # CMAKE_FORCE_Fortran_COMPILER to bypass checks for a working
25   # compiler (smpiff don't exist at configure time).
26   include(CMakeForceCompiler)
27   if(NOT COMMAND CMAKE_FORCE_Fortran_COMPILER)
28     MACRO(CMAKE_FORCE_Fortran_COMPILER compiler id)
29       SET(CMAKE_Fortran_COMPILER "${compiler}")
30       SET(CMAKE_Fortran_COMPILER_ID_RUN TRUE)
31       SET(CMAKE_Fortran_COMPILER_ID ${id})
32       SET(CMAKE_Fortran_COMPILER_WORKS TRUE)
33       SET(CMAKE_Fortran_COMPILER_FORCED TRUE)
34
35       # Set old compiler id variables.
36       IF("${CMAKE_Fortran_COMPILER_ID}" MATCHES "GNU")
37         SET(CMAKE_COMPILER_IS_GNUG77 1)
38       ENDIF("${CMAKE_Fortran_COMPILER_ID}" MATCHES "GNU")
39     ENDMACRO(CMAKE_FORCE_Fortran_COMPILER)
40   endif()
41   CMAKE_FORCE_Fortran_COMPILER(smpiff smpiff)
42   enable_language(Fortran OPTIONAL)
43 endif()
44
45 set(CMAKE_C_FLAGS "" CACHE TYPE INTERNAL FORCE)
46 set(CMAKE_CXX_FLAGS "" CACHE TYPE INTERNAL FORCE)
47 set(CMAKE_EXE_LINKER_FLAGS "" CACHE TYPE INTERNAL FORCE)
48 set(CMAKE_C_LINK_FLAGS "" CACHE TYPE INTERNAL FORCE)
49 set(CMAKE_Fortran_FLAGS "" CACHE TYPE INTERNAL FORCE)
50 set(CMAKE_Fortran_LINK_FLAGS "" CACHE TYPE INTERNAL FORCE)
51 ## Mapping version number -> version name
52 # 3.5.99 -> alpha1 (oops)
53 # 3.5.9{1,2} -> beta{1,2}
54 # 3.5.9{3,4,5} -> rc{1,2,3}
55 # 3.6.{0,1,2} -> release 3.6, 3.6.1, 3.6.2
56 # 3.7.{0,1} -> release 3.7, 3.7.1
57 # 3.8.{0,1} -> release 3.8, 3.8.1
58 # 3.9.0 -> release 3.9
59 # 3.9.90 -> release 3.10pre1
60 # 3.10.0 -> release 3.10
61 # 3.11.0 -> release 3.11
62 # 3.12.0 -> release 3.12
63
64 set(SIMGRID_VERSION_MAJOR "3")
65 set(SIMGRID_VERSION_MINOR "12")
66 set(SIMGRID_VERSION_PATCH "0")
67 set(SIMGRID_VERSION_EXTRA "-devel") # Extra words to add to version string (e.g. -rc1)
68
69 set(SIMGRID_VERSION_DATE  "2014") # Year for copyright information
70
71 if(${SIMGRID_VERSION_PATCH} EQUAL "0")
72   set(release_version "${SIMGRID_VERSION_MAJOR}.${SIMGRID_VERSION_MINOR}")
73 else()
74   set(release_version "${SIMGRID_VERSION_MAJOR}.${SIMGRID_VERSION_MINOR}.${SIMGRID_VERSION_PATCH}")
75 endif()
76
77 set(SIMGRID_VERSION_STRING
78   "SimGrid version ${release_version}${SIMGRID_VERSION_EXTRA}\\nCopyright (c) 2004-${SIMGRID_VERSION_DATE}. The Simgrid Team.")
79
80 set(libsimgrid_version "${release_version}")
81 set(libsimgrid-java_version "${release_version}")
82 set(GCC_NEED_VERSION "4.0")
83 set(APPLE_NEED_GCC_VERSION "4.6")
84
85 ### SET THE LIBRARY EXTENSION AND GCC VERSION
86 if(APPLE) #MAC
87   set(LIB_EXE "dylib")
88 else()
89   if(WIN32) #WINDOWS
90     set(LIB_EXE "a")
91     set(BIN_EXE ".exe")
92   else() #UNIX
93     set(LIB_EXE "so")
94   endif()
95 endif()
96
97 if(${CMAKE_C_COMPILER_ID} STREQUAL "GNU")
98   exec_program("${CMAKE_C_COMPILER} --version" OUTPUT_VARIABLE "COMPILER_C_VERSION")
99   exec_program("${CMAKE_CXX_COMPILER} --version" OUTPUT_VARIABLE "COMPILER_CXX_VERSION")
100   string(REGEX MATCH "[0-9].[0-9].[0-9]" COMPILER_C_VERSION "${COMPILER_C_VERSION}")
101   string(REGEX MATCH "[0-9].[0-9].[0-9]" COMPILER_CXX_VERSION "${COMPILER_CXX_VERSION}")
102
103   string(REGEX MATCH "^[0-9].[0-9]" COMPILER_C_VERSION_MAJOR_MINOR "${COMPILER_C_VERSION}")
104   string(REPLACE "${COMPILER_C_VERSION_MAJOR_MINOR}." "" COMPILER_C_VERSION_PATCH "${COMPILER_C_VERSION}")
105
106   if(${GCC_NEED_VERSION} GREATER  COMPILER_C_VERSION_MAJOR_MINOR)
107     message(FATAL_ERROR "Gcc must be to version ${GCC_NEED_VERSION} current version ${COMPILER_C_VERSION_MAJOR_MINOR}")
108   endif()
109   
110   if(COMPILER_C_VERSION_MAJOR_MINOR STRGREATER "4.8")
111     set (CMAKE_AR gcc-ar)
112     set (CMAKE_RANLIB gcc-ranlib)
113   endif()
114   
115 endif()
116
117 exec_program("${CMAKE_LINKER} --version" OUTPUT_VARIABLE "LINKER_VERSION")
118 string(REGEX MATCH "[0-9].[0-9]*" LINKER_VERSION "${LINKER_VERSION}")
119
120 string(REGEX MATCH "cl.exe" VBC "${CMAKE_C_COMPILER}")
121 if(VBC)
122   message(FATAL_ERROR "VB is not yet supported by Simgrid.")
123 endif()
124
125 ### Find programs and paths
126 FIND_PROGRAM(GCOV_PATH gcov)
127 include(FindPerl)
128 if(NOT PERL_EXECUTABLE)
129   message(FATAL_ERROR "-- SimGrid cannot be compiled without Perl installed -- sorry. Bailling out.")
130 endif()
131
132 ### Set some variables for Cmake
133 SET(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib)
134
135 set(INCLUDES
136   ${CMAKE_HOME_DIRECTORY}
137   ${CMAKE_HOME_DIRECTORY}/include
138   ${CMAKE_HOME_DIRECTORY}/src
139   ${CMAKE_HOME_DIRECTORY}/src/include
140   ${CMAKE_BINARY_DIR}
141   ${CMAKE_BINARY_DIR}/include
142   ${CMAKE_BINARY_DIR}/src
143   )
144
145 if(WIN32)
146   set(INCLUDES ${INCLUDES} ${CMAKE_HOME_DIRECTORY}/include/xbt ${CMAKE_HOME_DIRECTORY}/src/xbt) #for win32_ucontext.[ch]
147 endif()
148 set(CMAKE_SOURCE_DIR ${PROJECT_SOURCE_DIRECTORY})
149
150 if(NOT CMAKE_CROSSCOMPILING AND EXISTS /usr/include/)
151   set(INCLUDES ${INCLUDES} /usr/include/)
152 endif()
153
154 ### Check 32bits or 64bits
155 INCLUDE (CheckTypeSize)
156 CHECK_TYPE_SIZE("void*" SIZEOF_VOIDSTAR)
157 IF(SIZEOF_VOIDSTAR EQUAL 4)
158   SET(ARCH_32_BITS 1)
159 ELSE()
160   SET(ARCH_32_BITS 0)
161 ENDIF()
162
163 if(WIN32)
164
165   #Need env INCLUDE
166   set(CMAKE_INCLUDE_WIN "${CMAKE_C_COMPILER}")
167   set(CMAKE_LIB_WIN "${CMAKE_C_COMPILER}")
168   string(REGEX REPLACE "/bin/gcc.*" "/include"  CMAKE_INCLUDE_WIN "${CMAKE_INCLUDE_WIN}")
169   string(REGEX REPLACE "/bin/gcc.*" "/lib"  CMAKE_LIB_WIN "${CMAKE_LIB_WIN}")
170   set(INCLUDES ${INCLUDES} ${CMAKE_INCLUDE_WIN})
171
172   if(CMAKE_COMPILER_IS_GNUCC)
173     set(__GNUC__ 1)
174     exec_program("${CMAKE_C_COMPILER} --version" OUTPUT_VARIABLE "COMPILER_C_VERSION")
175     string(REGEX MATCH "[0-9].[0-9].[0-9]" COMPILER_C_VERSION "${COMPILER_C_VERSION}")
176     string(REGEX MATCH "^[0-9]" COMPILER_C_MAJOR_VERSION "${COMPILER_C_VERSION}")
177     string(REGEX MATCH "^[0-9].[0-9]" COMPILER_C_MINOR_VERSION "${COMPILER_C_VERSION}")
178     string(REGEX REPLACE "^${COMPILER_C_MAJOR_VERSION}." "" COMPILER_C_MINOR_VERSION "${COMPILER_C_MINOR_VERSION}")
179     if(COMPILER_C_MAJOR_VERSION)
180       # set(__GNUC__ ${COMPILER_C_MAJOR_VERSION})
181     endif()
182     if(COMPILER_C_MINOR_VERSION)
183       # set(__GNUC_MINOR__ ${COMPILER_C_MINOR_VERSION})
184     endif()
185     set(MSVC 0)
186     set(BORLAND 0)
187   else()
188     message(FATAL_ERROR "Please use MinGW to compile SimGrid!")
189   endif()
190
191   if(ARCH_32_BITS)      ### Arch 32bits
192     set(_WIN32 1)
193   else()        ### Arch 64bits
194     set(_WIN64 1)
195   endif()
196
197   set(NSIS_WIN_VERSION $ENV{PROCESSOR_ARCHITEW6432})
198   if(NSIS_WIN_VERSION MATCHES "")
199     set(NSIS_WIN_VERSION $ENV{PROCESSOR_ARCHITECTURE})
200   endif()
201   string(TOLOWER ${NSIS_WIN_VERSION} NSIS_WIN_VERSION)
202
203   set(_XBT_WIN32 1)
204
205   message(STATUS "C_COMPILER                    ${CMAKE_C_COMPILER} ${COMPILER_C_VERSION}")
206   message(STATUS "CXX_COMPILER                  ${CMAKE_CXX_COMPILER} ${COMPILER_CXX_VERSION}")
207   message(STATUS "CMAKE_RC_COMPILER             ${CMAKE_RC_COMPILER}")
208   message(STATUS "INCLUDE                       ${CMAKE_INCLUDE_WIN}")
209   message(STATUS "LIB                           ${CMAKE_LIB_WIN}")
210   message(STATUS "MAKE_PROGRAM                  ${CMAKE_MAKE_PROGRAM}")
211   message(STATUS "CMAKE_BUILD_TOOL              ${CMAKE_BUILD_TOOL}")
212   message(STATUS "LINKER                        ${CMAKE_LINKER}")
213   message(STATUS "CMAKE_GENERATOR               ${CMAKE_GENERATOR}")
214   message(STATUS "BORLAND                       ${BORLAND}")
215   message(STATUS "VISUALC                       ${MSVC}")
216   message(STATUS "GNUC                          ${CMAKE_COMPILER_IS_GNUCC}")
217
218 endif()
219
220 include_directories(${INCLUDES})
221
222 ### Setup Options
223 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/Option.cmake)
224
225 ### Make the *.h files with *.h.in files
226 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/CompleteInFiles.cmake)
227
228 ### Define source packages for Libs
229 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/DefinePackages.cmake)
230
231 ### Build some Maintainer files
232 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/MaintainerMode.cmake)
233 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/UnitTesting.cmake)
234
235 ### Setup gcc flags
236 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/Flags.cmake)
237
238 ### Make Libs
239 if(NOT WIN32)
240   include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/MakeLib.cmake)
241 else()
242   include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/MakeLibWin.cmake)
243 endif()
244
245 ### Make Exes
246 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/MakeExe.cmake)
247
248 ### Make tests
249 if(enable_memcheck_xml)
250   set(enable_memcheck true)
251 endif()
252
253 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/AddTests.cmake)
254 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/CTestConfig.cmake)
255
256 ### Setup the distrib
257 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/Distrib.cmake)
258
259 ### Pipol compilation
260 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/Pipol.cmake)
261
262 ### Build the doc
263 if(NOT WIN32)
264   include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/GenerateDoc.cmake)
265 else()
266   include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/GenerateDocWin.cmake)
267 endif()
268
269 ### Print ARGS
270 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/PrintArgs.cmake)
271
272 INCLUDE(Dart)