Logo AND Algorithmique Numérique Distribuée

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