Logo AND Algorithmique Numérique Distribuée

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