Logo AND Algorithmique Numérique Distribuée

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