Logo AND Algorithmique Numérique Distribuée

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