Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[travis] detect linux as we should
[simgrid.git] / CMakeLists.txt
1 cmake_minimum_required(VERSION 2.6)
2 # Java requires 2.8.6
3
4 project(SimGrid C CXX)
5
6 #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
7 #     Check for the compiler        #
8 #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
9
10 ### Need to set rc ccompiler before enable language
11 if(WIN32)
12   SET(CMAKE_RC_COMPILER "windres")
13 endif()
14
15 ## 
16 ## Check the C/C++ standard that we need
17 ##   See also tools/cmake/Flags.cmake that sets our paranoid warning flags
18 INCLUDE(CheckCCompilerFlag)
19 CHECK_C_COMPILER_FLAG(-fstack-cleaner HAVE_C_STACK_CLEANER)
20
21 ## Request full debugging flags
22 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g3")
23 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g3")
24 set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -g")
25
26 if (CMAKE_COMPILER_IS_GNUCC)
27   if (COMPILER_CXX_VERSION_MAJOR_MINOR STRLESS "4.7")
28     message(FATAL_ERROR
29             "SimGrid needs at least g++ version 4.7 to compile "
30             "(c++11 support of previous versions is too limited).")
31   endif()
32 endif()
33
34 ## We need a decent support of the c++11 standard
35 include(CheckCXXCompilerFlag)
36 CHECK_CXX_COMPILER_FLAG("-std=gnu++11" COMPILER_SUPPORTS_CXX11)
37 if(COMPILER_SUPPORTS_CXX11)
38   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
39 else() 
40   message(FATAL_ERROR 
41           "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. "
42           "Please use a decent C++ compiler.")
43 endif()
44
45 ### And we need C11 standard, too
46 include(CheckCCompilerFlag)
47 CHECK_C_COMPILER_FLAG("-std=gnu11" COMPILER_SUPPORTS_C11)
48 if(COMPILER_SUPPORTS_C11)
49   set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu11")
50 else()
51   message(FATAL_ERROR 
52           "The compiler ${CMAKE_C_COMPILER} has no C11 support. "
53           "Please use a decent C compiler "
54           "(note that c++11 support of ${CMAKE_CXX_COMPILER} seems ok).")
55 endif()
56 if(APPLE AND ("4.6" GREATER COMPILER_C_VERSION_MAJOR_MINOR))
57     ### gcc 4.[1-5] cannot compile ucontext on OSX
58     message(STATUS "Ucontext can't be used with this version of gcc (must be greater than 4.5)")
59     set(HAVE_UCONTEXT_H 0)
60 endif()
61
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 set(SIMGRID_VERSION_MAJOR "3")
93 set(SIMGRID_VERSION_MINOR "12")
94 set(SIMGRID_VERSION_PATCH "0")
95 set(SIMGRID_VERSION_EXTRA "-devel") # Extra words to add to version string (e.g. -rc1)
96
97 set(SIMGRID_VERSION_DATE  "2015") # Year for copyright information
98
99 if(${SIMGRID_VERSION_PATCH} EQUAL "0")
100   set(release_version "${SIMGRID_VERSION_MAJOR}.${SIMGRID_VERSION_MINOR}")
101 else()
102   set(release_version "${SIMGRID_VERSION_MAJOR}.${SIMGRID_VERSION_MINOR}.${SIMGRID_VERSION_PATCH}")
103 endif()
104
105 set(SIMGRID_VERSION_STRING "SimGrid version ${release_version}${SIMGRID_VERSION_EXTRA}")
106 set(SIMGRID_VERSION_BANNER
107   "SIMGRID_VERSION_STRING\\nCopyright (c) 2004-${SIMGRID_VERSION_DATE}. The Simgrid Team.")
108
109 set(libsimgrid_version "${release_version}")
110 set(libsimgrid-java_version "${release_version}")
111
112 ### SET THE LIBRARY EXTENSION 
113 if(APPLE) #MAC
114   set(LIB_EXE "dylib")
115 else()
116   if(WIN32) #WINDOWS
117     set(LIB_EXE "a")
118     set(BIN_EXE ".exe")
119   else() #UNIX
120     set(LIB_EXE "so")
121   endif()
122 endif()
123
124 if(${CMAKE_C_COMPILER_ID} STREQUAL "GNU")
125   exec_program("${CMAKE_C_COMPILER} --version" OUTPUT_VARIABLE "COMPILER_C_VERSION")
126   exec_program("${CMAKE_CXX_COMPILER} --version" OUTPUT_VARIABLE "COMPILER_CXX_VERSION")
127   string(REGEX MATCH "[0-9].[0-9].[0-9]" COMPILER_C_VERSION "${COMPILER_C_VERSION}")
128   string(REGEX MATCH "[0-9].[0-9].[0-9]" COMPILER_CXX_VERSION "${COMPILER_CXX_VERSION}")
129
130   string(REGEX MATCH "^[0-9].[0-9]" COMPILER_C_VERSION_MAJOR_MINOR "${COMPILER_C_VERSION}")
131   string(REPLACE "${COMPILER_C_VERSION_MAJOR_MINOR}." "" COMPILER_C_VERSION_PATCH "${COMPILER_C_VERSION}")  
132 endif()
133
134 exec_program("${CMAKE_LINKER} --version" OUTPUT_VARIABLE "LINKER_VERSION")
135 string(REGEX MATCH "[0-9].[0-9]*" LINKER_VERSION "${LINKER_VERSION}")
136
137 string(REGEX MATCH "cl.exe" VBC "${CMAKE_C_COMPILER}")
138 if(VBC)
139   message("VB is not yet supported by Simgrid. Proceed with extrem caution")
140 endif()
141
142 ### Find programs and paths
143 FIND_PROGRAM(GCOV_PATH gcov)
144 include(FindPerl)
145 if(NOT PERL_EXECUTABLE)
146   message(FATAL_ERROR "-- SimGrid cannot be compiled without Perl installed -- sorry. Bailling out.")
147 endif()
148
149 if (APPLE)
150   set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
151   set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
152 endif()
153
154 ### Set some variables for Cmake
155 SET(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib)
156
157 set(INCLUDES
158   ${CMAKE_HOME_DIRECTORY}
159   ${CMAKE_HOME_DIRECTORY}/include
160   ${CMAKE_HOME_DIRECTORY}/src
161   ${CMAKE_HOME_DIRECTORY}/src/include
162   ${CMAKE_BINARY_DIR}
163   ${CMAKE_BINARY_DIR}/include
164   ${CMAKE_BINARY_DIR}/src
165   )
166
167 if(WIN32)
168   set(INCLUDES ${INCLUDES} ${CMAKE_HOME_DIRECTORY}/include/xbt ${CMAKE_HOME_DIRECTORY}/src/xbt) #for win32_ucontext.[ch]
169 endif()
170 set(CMAKE_SOURCE_DIR ${PROJECT_SOURCE_DIRECTORY})
171
172 if(NOT CMAKE_CROSSCOMPILING AND EXISTS /usr/include/)
173   set(INCLUDES ${INCLUDES} /usr/include/)
174 endif()
175
176 ### Check 32bits or 64bits
177 INCLUDE (CheckTypeSize)
178 CHECK_TYPE_SIZE("void*" SIZEOF_VOIDSTAR)
179 IF(SIZEOF_VOIDSTAR EQUAL 4)
180   SET(ARCH_32_BITS 1)
181 ELSE()
182   SET(ARCH_32_BITS 0)
183 ENDIF()
184
185 if(WIN32)
186
187   #Need env INCLUDE
188   set(CMAKE_INCLUDE_WIN "${CMAKE_C_COMPILER}")
189   set(CMAKE_LIB_WIN "${CMAKE_C_COMPILER}")
190   string(REGEX REPLACE "/bin/gcc.*" "/include"  CMAKE_INCLUDE_WIN "${CMAKE_INCLUDE_WIN}")
191   string(REGEX REPLACE "/bin/gcc.*" "/lib"  CMAKE_LIB_WIN "${CMAKE_LIB_WIN}")
192   set(INCLUDES ${INCLUDES} ${CMAKE_INCLUDE_WIN})
193
194   if(CMAKE_COMPILER_IS_GNUCC)
195     set(__GNUC__ 1)
196     exec_program("${CMAKE_C_COMPILER} --version" OUTPUT_VARIABLE "COMPILER_C_VERSION")
197     string(REGEX MATCH "[0-9].[0-9].[0-9]" COMPILER_C_VERSION "${COMPILER_C_VERSION}")
198     string(REGEX MATCH "^[0-9]" COMPILER_C_MAJOR_VERSION "${COMPILER_C_VERSION}")
199     string(REGEX MATCH "^[0-9].[0-9]" COMPILER_C_MINOR_VERSION "${COMPILER_C_VERSION}")
200     string(REGEX REPLACE "^${COMPILER_C_MAJOR_VERSION}." "" COMPILER_C_MINOR_VERSION "${COMPILER_C_MINOR_VERSION}")
201     if(COMPILER_C_MAJOR_VERSION)
202       # set(__GNUC__ ${COMPILER_C_MAJOR_VERSION})
203     endif()
204     if(COMPILER_C_MINOR_VERSION)
205       # set(__GNUC_MINOR__ ${COMPILER_C_MINOR_VERSION})
206     endif()
207   else()
208     message("You REALLY should use MinGW to compile SimGrid on Windows!")
209   endif()
210
211   set(NSIS_WIN_VERSION $ENV{PROCESSOR_ARCHITEW6432})
212   if(NSIS_WIN_VERSION MATCHES "")
213     set(NSIS_WIN_VERSION $ENV{PROCESSOR_ARCHITECTURE})
214   endif()
215   if(${NSIS_WIN_VERSION})
216     string(TOLOWER ${NSIS_WIN_VERSION} NSIS_WIN_VERSION)
217   endif()
218
219   set(_XBT_WIN32 1)
220
221   message(STATUS "C_COMPILER                    ${CMAKE_C_COMPILER} ${COMPILER_C_VERSION_MAJOR_MINOR}")
222   message(STATUS "CXX_COMPILER                  ${CMAKE_CXX_COMPILER} ${COMPILER_CXX_VERSION_MAJOR_MINOR}")
223   message(STATUS "CMAKE_RC_COMPILER             ${CMAKE_RC_COMPILER}")
224   message(STATUS "INCLUDE                       ${CMAKE_INCLUDE_WIN}")
225   message(STATUS "LIB                           ${CMAKE_LIB_WIN}")
226   message(STATUS "MAKE_PROGRAM                  ${CMAKE_MAKE_PROGRAM}")
227   message(STATUS "CMAKE_BUILD_TOOL              ${CMAKE_BUILD_TOOL}")
228   message(STATUS "LINKER                        ${CMAKE_LINKER}")
229   message(STATUS "CMAKE_GENERATOR               ${CMAKE_GENERATOR}")
230   message(STATUS "GNUC                          ${CMAKE_COMPILER_IS_GNUCC}")
231
232 endif()
233
234 include_directories(${INCLUDES})
235
236 ### Setup Options
237 include(${CMAKE_HOME_DIRECTORY}/tools/cmake/Option.cmake)
238
239 ### Make the *.h files with *.h.in files
240 include(${CMAKE_HOME_DIRECTORY}/tools/cmake/CompleteInFiles.cmake)
241
242 ### Define source packages for Libs
243 include(${CMAKE_HOME_DIRECTORY}/tools/cmake/DefinePackages.cmake)
244
245 ### Build some Maintainer files
246 include(${CMAKE_HOME_DIRECTORY}/tools/cmake/MaintainerMode.cmake)
247 include(${CMAKE_HOME_DIRECTORY}/tools/cmake/UnitTesting.cmake)
248
249 ### Setup gcc flags
250 include(${CMAKE_HOME_DIRECTORY}/tools/cmake/Flags.cmake)
251
252 ### Make Libs
253 if(NOT WIN32)
254   include(${CMAKE_HOME_DIRECTORY}/tools/cmake/MakeLib.cmake)
255 else()
256   include(${CMAKE_HOME_DIRECTORY}/tools/cmake/MakeLibWin.cmake)
257 endif()
258
259 if(enable_java)
260   include(${CMAKE_HOME_DIRECTORY}/tools/cmake/MakeJava.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)