Logo AND Algorithmique Numérique Distribuée

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