Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
try to please clang. No idea of why it fails on mac but works on linux...
[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 if (MSVC)
19   message("-- You are compiling SimGrid with MicroSoft Visual C. Good luck.")
20
21   set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_SCL_SECURE_NO_WARNINGS")
22   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_SCL_SECURE_NO_WARNINGS")
23 else() # gcc or clang
24   INCLUDE(CheckCCompilerFlag)
25   CHECK_C_COMPILER_FLAG(-fstack-cleaner HAVE_C_STACK_CLEANER)
26
27   ## Request full debugging flags
28   set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g3")
29   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g3")
30   set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -g")
31
32   if (CMAKE_COMPILER_IS_GNUCC)
33     if (COMPILER_CXX_VERSION_MAJOR_MINOR STRLESS "4.7")
34       message(FATAL_ERROR
35               "SimGrid needs at least g++ version 4.7 to compile "
36               "(c++11 support of previous versions is too limited).")
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   if(APPLE AND ("4.6" GREATER COMPILER_C_VERSION_MAJOR_MINOR))
63       ### gcc 4.[1-5] cannot compile ucontext on OSX
64       message(STATUS "Ucontext can't be used with this version of gcc (must be greater than 4.5)")
65       set(HAVE_UCONTEXT_H 0)
66   endif()
67 endif() # NOT MSVC
68
69 ### SMPI vs. Fortran
70 if ((NOT DEFINED enable_smpi OR enable_smpi) AND NOT APPLE) # smpi is enabled by default
71   # Call enable_language(Fortran) in order to load the build rules for
72   # this language, needed by teshsuite/smpi/mpich-test/.  Use
73   # CMAKE_FORCE_Fortran_COMPILER to bypass checks for a working
74   # compiler (smpiff don't exist at configure time).
75   include(CMakeForceCompiler)
76   if(NOT COMMAND CMAKE_FORCE_Fortran_COMPILER)
77     MACRO(CMAKE_FORCE_Fortran_COMPILER compiler id)
78       SET(CMAKE_Fortran_COMPILER "${compiler}")
79       SET(CMAKE_Fortran_COMPILER_ID_RUN TRUE)
80       SET(CMAKE_Fortran_COMPILER_ID ${id})
81       SET(CMAKE_Fortran_COMPILER_WORKS TRUE)
82       SET(CMAKE_Fortran_COMPILER_FORCED TRUE)
83
84       # Set old compiler id variables.
85       IF("${CMAKE_Fortran_COMPILER_ID}" MATCHES "GNU")
86         SET(CMAKE_COMPILER_IS_GNUG77 1)
87       ENDIF("${CMAKE_Fortran_COMPILER_ID}" MATCHES "GNU")
88     ENDMACRO(CMAKE_FORCE_Fortran_COMPILER)
89   endif()
90   CMAKE_FORCE_Fortran_COMPILER(smpiff smpiff)
91   enable_language(Fortran OPTIONAL)
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 ### Find programs and paths
144 FIND_PROGRAM(GCOV_PATH gcov)
145 include(FindPerl)
146 if(NOT PERL_EXECUTABLE)
147   message(FATAL_ERROR "-- SimGrid cannot be compiled without Perl installed -- sorry. Bailling out.")
148 endif()
149
150 if (APPLE)
151   set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
152   set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
153 endif()
154
155 ### Set some variables for Cmake
156 SET(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib)
157
158 set(INCLUDES
159   ${CMAKE_HOME_DIRECTORY}
160   ${CMAKE_HOME_DIRECTORY}/include
161   ${CMAKE_HOME_DIRECTORY}/src
162   ${CMAKE_HOME_DIRECTORY}/src/include
163   ${CMAKE_BINARY_DIR}
164   ${CMAKE_BINARY_DIR}/include
165   ${CMAKE_BINARY_DIR}/src
166   )
167
168 if(WIN32)
169   set(INCLUDES ${INCLUDES} ${CMAKE_HOME_DIRECTORY}/include/xbt ${CMAKE_HOME_DIRECTORY}/src/xbt) #for win32_ucontext.[ch]
170 endif()
171 set(CMAKE_SOURCE_DIR ${PROJECT_SOURCE_DIRECTORY})
172
173 if(NOT CMAKE_CROSSCOMPILING AND EXISTS /usr/include/)
174   set(INCLUDES ${INCLUDES} /usr/include/)
175 endif()
176
177 ### Check 32bits or 64bits
178 INCLUDE (CheckTypeSize)
179 CHECK_TYPE_SIZE("int" SIZEOF_INT)
180 CHECK_TYPE_SIZE("long" SIZEOF_LONG)
181 CHECK_TYPE_SIZE("long long" SIZEOF_LONGLONG)
182 CHECK_TYPE_SIZE("void*" SIZEOF_VOIDSTAR)
183 message ("   Data model: (int)=${SIZEOF_INT} (long)=${SIZEOF_LONG} (long long)=${SIZEOF_LONGLONG} (void*)=${SIZEOF_VOIDSTAR}")
184 IF(SIZEOF_VOIDSTAR EQUAL 4)
185   SET(ARCH_32_BITS 1)
186 ELSE()
187   SET(ARCH_32_BITS 0)
188 ENDIF()
189
190 if(WIN32)
191
192   #Need env INCLUDE
193   set(CMAKE_INCLUDE_WIN "${CMAKE_C_COMPILER}")
194   set(CMAKE_LIB_WIN "${CMAKE_C_COMPILER}")
195   string(REGEX REPLACE "/bin/gcc.*" "/include"  CMAKE_INCLUDE_WIN "${CMAKE_INCLUDE_WIN}")
196   string(REGEX REPLACE "/bin/gcc.*" "/lib"  CMAKE_LIB_WIN "${CMAKE_LIB_WIN}")
197   set(INCLUDES ${INCLUDES} ${CMAKE_INCLUDE_WIN})
198
199   if(CMAKE_COMPILER_IS_GNUCC)
200     set(__GNUC__ 1)
201     exec_program("${CMAKE_C_COMPILER} --version" OUTPUT_VARIABLE "COMPILER_C_VERSION")
202     string(REGEX MATCH "[0-9].[0-9].[0-9]" COMPILER_C_VERSION "${COMPILER_C_VERSION}")
203     string(REGEX MATCH "^[0-9]" COMPILER_C_MAJOR_VERSION "${COMPILER_C_VERSION}")
204     string(REGEX MATCH "^[0-9].[0-9]" COMPILER_C_MINOR_VERSION "${COMPILER_C_VERSION}")
205     string(REGEX REPLACE "^${COMPILER_C_MAJOR_VERSION}." "" COMPILER_C_MINOR_VERSION "${COMPILER_C_MINOR_VERSION}")
206     if(COMPILER_C_MAJOR_VERSION)
207       # set(__GNUC__ ${COMPILER_C_MAJOR_VERSION})
208     endif()
209     if(COMPILER_C_MINOR_VERSION)
210       # set(__GNUC_MINOR__ ${COMPILER_C_MINOR_VERSION})
211     endif()
212   endif()
213
214   set(NSIS_WIN_VERSION $ENV{PROCESSOR_ARCHITEW6432})
215   if(NSIS_WIN_VERSION MATCHES "")
216     set(NSIS_WIN_VERSION $ENV{PROCESSOR_ARCHITECTURE})
217   endif()
218   if(${NSIS_WIN_VERSION})
219     string(TOLOWER ${NSIS_WIN_VERSION} NSIS_WIN_VERSION)
220   endif()
221
222   set(_XBT_WIN32 1)
223
224   message(STATUS "C_COMPILER                    ${CMAKE_C_COMPILER} ${COMPILER_C_VERSION_MAJOR_MINOR}")
225   message(STATUS "CXX_COMPILER                  ${CMAKE_CXX_COMPILER} ${COMPILER_CXX_VERSION_MAJOR_MINOR}")
226   message(STATUS "CMAKE_RC_COMPILER             ${CMAKE_RC_COMPILER}")
227   message(STATUS "INCLUDE                       ${CMAKE_INCLUDE_WIN}")
228   message(STATUS "LIB                           ${CMAKE_LIB_WIN}")
229   message(STATUS "MAKE_PROGRAM                  ${CMAKE_MAKE_PROGRAM}")
230   message(STATUS "CMAKE_BUILD_TOOL              ${CMAKE_BUILD_TOOL}")
231   message(STATUS "LINKER                        ${CMAKE_LINKER}")
232   message(STATUS "CMAKE_GENERATOR               ${CMAKE_GENERATOR}")
233   message(STATUS "GNUC                          ${CMAKE_COMPILER_IS_GNUCC}")
234
235 endif()
236
237 include_directories(${INCLUDES})
238
239 ### Setup Options
240 include(${CMAKE_HOME_DIRECTORY}/tools/cmake/Option.cmake)
241
242 ### Make the *.h files with *.h.in files
243 include(${CMAKE_HOME_DIRECTORY}/tools/cmake/CompleteInFiles.cmake)
244
245 ### Define source packages for Libs
246 include(${CMAKE_HOME_DIRECTORY}/tools/cmake/DefinePackages.cmake)
247
248 ### Build some Maintainer files
249 include(${CMAKE_HOME_DIRECTORY}/tools/cmake/MaintainerMode.cmake)
250 include(${CMAKE_HOME_DIRECTORY}/tools/cmake/UnitTesting.cmake)
251
252 ### Setup gcc & clang flags
253 if (NOT MSVC)
254   include(${CMAKE_HOME_DIRECTORY}/tools/cmake/Flags.cmake)
255 endif()
256
257 ### Make Libs
258 if(NOT WIN32)
259   include(${CMAKE_HOME_DIRECTORY}/tools/cmake/MakeLib.cmake)
260 else()
261   include(${CMAKE_HOME_DIRECTORY}/tools/cmake/MakeLibWin.cmake)
262 endif()
263
264 if(enable_java)
265   include(${CMAKE_HOME_DIRECTORY}/tools/cmake/MakeJava.cmake)
266 endif()
267
268 ### Make Exes
269 include(${CMAKE_HOME_DIRECTORY}/tools/cmake/MakeExe.cmake)
270
271 ### Make tests
272 if(enable_memcheck_xml)
273   set(enable_memcheck true)
274 endif()
275
276 include(${CMAKE_HOME_DIRECTORY}/tools/cmake/AddTests.cmake)
277 include(${CMAKE_HOME_DIRECTORY}/tools/cmake/CTestConfig.cmake)
278
279 ### Setup the distrib
280 include(${CMAKE_HOME_DIRECTORY}/tools/cmake/Distrib.cmake)
281
282 ### Pipol compilation
283 include(${CMAKE_HOME_DIRECTORY}/tools/cmake/Pipol.cmake)
284
285 ### Build the doc
286 if(NOT WIN32)
287   include(${CMAKE_HOME_DIRECTORY}/tools/cmake/GenerateDoc.cmake)
288 else()
289   include(${CMAKE_HOME_DIRECTORY}/tools/cmake/GenerateDocWin.cmake)
290 endif()
291
292 ### Print ARGS
293 include(${CMAKE_HOME_DIRECTORY}/tools/cmake/PrintArgs.cmake)
294
295 INCLUDE(Dart)