Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
don't give gcc flags to MSVC
[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("MicroSoft Visual C detected.")
20 else() # gcc or clang
21   INCLUDE(CheckCCompilerFlag)
22   CHECK_C_COMPILER_FLAG(-fstack-cleaner HAVE_C_STACK_CLEANER)
23
24   ## Request full debugging flags
25   set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g3")
26   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g3")
27   set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -g")
28
29   if (CMAKE_COMPILER_IS_GNUCC)
30     if (COMPILER_CXX_VERSION_MAJOR_MINOR STRLESS "4.7")
31       message(FATAL_ERROR
32               "SimGrid needs at least g++ version 4.7 to compile "
33               "(c++11 support of previous versions is too limited).")
34     endif()
35   endif()
36
37   ## We need a decent support of the c++11 standard
38   include(CheckCXXCompilerFlag)
39   CHECK_CXX_COMPILER_FLAG("-std=gnu++11" COMPILER_SUPPORTS_CXX11)
40   if(COMPILER_SUPPORTS_CXX11)
41     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
42   else() 
43     message(FATAL_ERROR 
44             "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. "
45             "Please use a decent C++ compiler.")
46   endif()
47
48   ### And we need C11 standard, too
49   include(CheckCCompilerFlag)
50   CHECK_C_COMPILER_FLAG("-std=gnu11" COMPILER_SUPPORTS_C11)
51   if(COMPILER_SUPPORTS_C11)
52     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu11")
53   else()
54     message(FATAL_ERROR 
55             "The compiler ${CMAKE_C_COMPILER} has no C11 support. "
56             "Please use a decent C compiler "
57             "(note that c++11 support of ${CMAKE_CXX_COMPILER} seems ok).")
58   endif()
59   if(APPLE AND ("4.6" GREATER COMPILER_C_VERSION_MAJOR_MINOR))
60       ### gcc 4.[1-5] cannot compile ucontext on OSX
61       message(STATUS "Ucontext can't be used with this version of gcc (must be greater than 4.5)")
62       set(HAVE_UCONTEXT_H 0)
63   endif()
64 endif() # NOT MSVC
65
66 ### SMPI vs. Fortran
67 if ((NOT DEFINED enable_smpi OR enable_smpi) AND NOT APPLE) # smpi is enabled by default
68   # Call enable_language(Fortran) in order to load the build rules for
69   # this language, needed by teshsuite/smpi/mpich-test/.  Use
70   # CMAKE_FORCE_Fortran_COMPILER to bypass checks for a working
71   # compiler (smpiff don't exist at configure time).
72   include(CMakeForceCompiler)
73   if(NOT COMMAND CMAKE_FORCE_Fortran_COMPILER)
74     MACRO(CMAKE_FORCE_Fortran_COMPILER compiler id)
75       SET(CMAKE_Fortran_COMPILER "${compiler}")
76       SET(CMAKE_Fortran_COMPILER_ID_RUN TRUE)
77       SET(CMAKE_Fortran_COMPILER_ID ${id})
78       SET(CMAKE_Fortran_COMPILER_WORKS TRUE)
79       SET(CMAKE_Fortran_COMPILER_FORCED TRUE)
80
81       # Set old compiler id variables.
82       IF("${CMAKE_Fortran_COMPILER_ID}" MATCHES "GNU")
83         SET(CMAKE_COMPILER_IS_GNUG77 1)
84       ENDIF("${CMAKE_Fortran_COMPILER_ID}" MATCHES "GNU")
85     ENDMACRO(CMAKE_FORCE_Fortran_COMPILER)
86   endif()
87   CMAKE_FORCE_Fortran_COMPILER(smpiff smpiff)
88   enable_language(Fortran OPTIONAL)
89 endif()
90
91 #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
92 #     Build the version number      #
93 #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
94
95 set(SIMGRID_VERSION_MAJOR "3")
96 set(SIMGRID_VERSION_MINOR "12")
97 set(SIMGRID_VERSION_PATCH "0")
98 set(SIMGRID_VERSION_EXTRA "-devel") # Extra words to add to version string (e.g. -rc1)
99
100 set(SIMGRID_VERSION_DATE  "2015") # Year for copyright information
101
102 if(${SIMGRID_VERSION_PATCH} EQUAL "0")
103   set(release_version "${SIMGRID_VERSION_MAJOR}.${SIMGRID_VERSION_MINOR}")
104 else()
105   set(release_version "${SIMGRID_VERSION_MAJOR}.${SIMGRID_VERSION_MINOR}.${SIMGRID_VERSION_PATCH}")
106 endif()
107
108 set(SIMGRID_VERSION_STRING "SimGrid version ${release_version}${SIMGRID_VERSION_EXTRA}")
109 set(SIMGRID_VERSION_BANNER
110   "SIMGRID_VERSION_STRING\\nCopyright (c) 2004-${SIMGRID_VERSION_DATE}. The Simgrid Team.")
111
112 set(libsimgrid_version "${release_version}")
113 set(libsimgrid-java_version "${release_version}")
114
115 ### SET THE LIBRARY EXTENSION 
116 if(APPLE) #MAC
117   set(LIB_EXE "dylib")
118 else()
119   if(WIN32) #WINDOWS
120     set(LIB_EXE "a")
121     set(BIN_EXE ".exe")
122   else() #UNIX
123     set(LIB_EXE "so")
124   endif()
125 endif()
126
127 if(${CMAKE_C_COMPILER_ID} STREQUAL "GNU")
128   exec_program("${CMAKE_C_COMPILER} --version" OUTPUT_VARIABLE "COMPILER_C_VERSION")
129   exec_program("${CMAKE_CXX_COMPILER} --version" OUTPUT_VARIABLE "COMPILER_CXX_VERSION")
130   string(REGEX MATCH "[0-9].[0-9].[0-9]" COMPILER_C_VERSION "${COMPILER_C_VERSION}")
131   string(REGEX MATCH "[0-9].[0-9].[0-9]" COMPILER_CXX_VERSION "${COMPILER_CXX_VERSION}")
132
133   string(REGEX MATCH "^[0-9].[0-9]" COMPILER_C_VERSION_MAJOR_MINOR "${COMPILER_C_VERSION}")
134   string(REPLACE "${COMPILER_C_VERSION_MAJOR_MINOR}." "" COMPILER_C_VERSION_PATCH "${COMPILER_C_VERSION}")  
135 endif()
136
137 exec_program("${CMAKE_LINKER} --version" OUTPUT_VARIABLE "LINKER_VERSION")
138 string(REGEX MATCH "[0-9].[0-9]*" LINKER_VERSION "${LINKER_VERSION}")
139
140 string(REGEX MATCH "cl.exe" VBC "${CMAKE_C_COMPILER}")
141 if(VBC)
142   message("VB is not yet supported by Simgrid. Proceed with extrem caution")
143 endif()
144
145 ### Find programs and paths
146 FIND_PROGRAM(GCOV_PATH gcov)
147 include(FindPerl)
148 if(NOT PERL_EXECUTABLE)
149   message(FATAL_ERROR "-- SimGrid cannot be compiled without Perl installed -- sorry. Bailling out.")
150 endif()
151
152 if (APPLE)
153   set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
154   set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
155 endif()
156
157 ### Set some variables for Cmake
158 SET(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib)
159
160 set(INCLUDES
161   ${CMAKE_HOME_DIRECTORY}
162   ${CMAKE_HOME_DIRECTORY}/include
163   ${CMAKE_HOME_DIRECTORY}/src
164   ${CMAKE_HOME_DIRECTORY}/src/include
165   ${CMAKE_BINARY_DIR}
166   ${CMAKE_BINARY_DIR}/include
167   ${CMAKE_BINARY_DIR}/src
168   )
169
170 if(WIN32)
171   set(INCLUDES ${INCLUDES} ${CMAKE_HOME_DIRECTORY}/include/xbt ${CMAKE_HOME_DIRECTORY}/src/xbt) #for win32_ucontext.[ch]
172 endif()
173 set(CMAKE_SOURCE_DIR ${PROJECT_SOURCE_DIRECTORY})
174
175 if(NOT CMAKE_CROSSCOMPILING AND EXISTS /usr/include/)
176   set(INCLUDES ${INCLUDES} /usr/include/)
177 endif()
178
179 ### Check 32bits or 64bits
180 INCLUDE (CheckTypeSize)
181 CHECK_TYPE_SIZE("void*" SIZEOF_VOIDSTAR)
182 IF(SIZEOF_VOIDSTAR EQUAL 4)
183   SET(ARCH_32_BITS 1)
184 ELSE()
185   SET(ARCH_32_BITS 0)
186 ENDIF()
187
188 if(WIN32)
189
190   #Need env INCLUDE
191   set(CMAKE_INCLUDE_WIN "${CMAKE_C_COMPILER}")
192   set(CMAKE_LIB_WIN "${CMAKE_C_COMPILER}")
193   string(REGEX REPLACE "/bin/gcc.*" "/include"  CMAKE_INCLUDE_WIN "${CMAKE_INCLUDE_WIN}")
194   string(REGEX REPLACE "/bin/gcc.*" "/lib"  CMAKE_LIB_WIN "${CMAKE_LIB_WIN}")
195   set(INCLUDES ${INCLUDES} ${CMAKE_INCLUDE_WIN})
196
197   if(CMAKE_COMPILER_IS_GNUCC)
198     set(__GNUC__ 1)
199     exec_program("${CMAKE_C_COMPILER} --version" OUTPUT_VARIABLE "COMPILER_C_VERSION")
200     string(REGEX MATCH "[0-9].[0-9].[0-9]" COMPILER_C_VERSION "${COMPILER_C_VERSION}")
201     string(REGEX MATCH "^[0-9]" COMPILER_C_MAJOR_VERSION "${COMPILER_C_VERSION}")
202     string(REGEX MATCH "^[0-9].[0-9]" COMPILER_C_MINOR_VERSION "${COMPILER_C_VERSION}")
203     string(REGEX REPLACE "^${COMPILER_C_MAJOR_VERSION}." "" COMPILER_C_MINOR_VERSION "${COMPILER_C_MINOR_VERSION}")
204     if(COMPILER_C_MAJOR_VERSION)
205       # set(__GNUC__ ${COMPILER_C_MAJOR_VERSION})
206     endif()
207     if(COMPILER_C_MINOR_VERSION)
208       # set(__GNUC_MINOR__ ${COMPILER_C_MINOR_VERSION})
209     endif()
210   else()
211     message("You REALLY should use MinGW to compile SimGrid on Windows!")
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)