Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
New XBT module: file
[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 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 ### Find programs and paths
141 FIND_PROGRAM(GCOV_PATH gcov)
142 include(FindPerl)
143 if(NOT PERL_EXECUTABLE)
144   message(FATAL_ERROR "-- SimGrid cannot be compiled without Perl installed -- sorry. Bailling out.")
145 endif()
146
147 if (APPLE)
148   set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
149   set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
150 endif()
151
152 ### Set some variables for Cmake
153 SET(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib)
154
155 set(INCLUDES
156   ${CMAKE_HOME_DIRECTORY}
157   ${CMAKE_HOME_DIRECTORY}/include
158   ${CMAKE_HOME_DIRECTORY}/src
159   ${CMAKE_HOME_DIRECTORY}/src/include
160   ${CMAKE_BINARY_DIR}
161   ${CMAKE_BINARY_DIR}/include
162   ${CMAKE_BINARY_DIR}/src
163   )
164
165 if(WIN32)
166   set(INCLUDES ${INCLUDES} ${CMAKE_HOME_DIRECTORY}/include/xbt ${CMAKE_HOME_DIRECTORY}/src/xbt) #for win32_ucontext.[ch]
167 endif()
168 set(CMAKE_SOURCE_DIR ${PROJECT_SOURCE_DIRECTORY})
169
170 if(NOT CMAKE_CROSSCOMPILING AND EXISTS /usr/include/)
171   set(INCLUDES ${INCLUDES} /usr/include/)
172 endif()
173
174 ### Check 32bits or 64bits
175 INCLUDE (CheckTypeSize)
176 CHECK_TYPE_SIZE("void*" SIZEOF_VOIDSTAR)
177 IF(SIZEOF_VOIDSTAR EQUAL 4)
178   SET(ARCH_32_BITS 1)
179 ELSE()
180   SET(ARCH_32_BITS 0)
181 ENDIF()
182
183 if(WIN32)
184
185   #Need env INCLUDE
186   set(CMAKE_INCLUDE_WIN "${CMAKE_C_COMPILER}")
187   set(CMAKE_LIB_WIN "${CMAKE_C_COMPILER}")
188   string(REGEX REPLACE "/bin/gcc.*" "/include"  CMAKE_INCLUDE_WIN "${CMAKE_INCLUDE_WIN}")
189   string(REGEX REPLACE "/bin/gcc.*" "/lib"  CMAKE_LIB_WIN "${CMAKE_LIB_WIN}")
190   set(INCLUDES ${INCLUDES} ${CMAKE_INCLUDE_WIN})
191
192   if(CMAKE_COMPILER_IS_GNUCC)
193     set(__GNUC__ 1)
194     exec_program("${CMAKE_C_COMPILER} --version" OUTPUT_VARIABLE "COMPILER_C_VERSION")
195     string(REGEX MATCH "[0-9].[0-9].[0-9]" COMPILER_C_VERSION "${COMPILER_C_VERSION}")
196     string(REGEX MATCH "^[0-9]" COMPILER_C_MAJOR_VERSION "${COMPILER_C_VERSION}")
197     string(REGEX MATCH "^[0-9].[0-9]" COMPILER_C_MINOR_VERSION "${COMPILER_C_VERSION}")
198     string(REGEX REPLACE "^${COMPILER_C_MAJOR_VERSION}." "" COMPILER_C_MINOR_VERSION "${COMPILER_C_MINOR_VERSION}")
199     if(COMPILER_C_MAJOR_VERSION)
200       # set(__GNUC__ ${COMPILER_C_MAJOR_VERSION})
201     endif()
202     if(COMPILER_C_MINOR_VERSION)
203       # set(__GNUC_MINOR__ ${COMPILER_C_MINOR_VERSION})
204     endif()
205   endif()
206
207   set(NSIS_WIN_VERSION $ENV{PROCESSOR_ARCHITEW6432})
208   if(NSIS_WIN_VERSION MATCHES "")
209     set(NSIS_WIN_VERSION $ENV{PROCESSOR_ARCHITECTURE})
210   endif()
211   if(${NSIS_WIN_VERSION})
212     string(TOLOWER ${NSIS_WIN_VERSION} NSIS_WIN_VERSION)
213   endif()
214
215   set(_XBT_WIN32 1)
216
217   message(STATUS "C_COMPILER                    ${CMAKE_C_COMPILER} ${COMPILER_C_VERSION_MAJOR_MINOR}")
218   message(STATUS "CXX_COMPILER                  ${CMAKE_CXX_COMPILER} ${COMPILER_CXX_VERSION_MAJOR_MINOR}")
219   message(STATUS "CMAKE_RC_COMPILER             ${CMAKE_RC_COMPILER}")
220   message(STATUS "INCLUDE                       ${CMAKE_INCLUDE_WIN}")
221   message(STATUS "LIB                           ${CMAKE_LIB_WIN}")
222   message(STATUS "MAKE_PROGRAM                  ${CMAKE_MAKE_PROGRAM}")
223   message(STATUS "CMAKE_BUILD_TOOL              ${CMAKE_BUILD_TOOL}")
224   message(STATUS "LINKER                        ${CMAKE_LINKER}")
225   message(STATUS "CMAKE_GENERATOR               ${CMAKE_GENERATOR}")
226   message(STATUS "GNUC                          ${CMAKE_COMPILER_IS_GNUCC}")
227
228 endif()
229
230 include_directories(${INCLUDES})
231
232 ### Setup Options
233 include(${CMAKE_HOME_DIRECTORY}/tools/cmake/Option.cmake)
234
235 ### Make the *.h files with *.h.in files
236 include(${CMAKE_HOME_DIRECTORY}/tools/cmake/CompleteInFiles.cmake)
237
238 ### Define source packages for Libs
239 include(${CMAKE_HOME_DIRECTORY}/tools/cmake/DefinePackages.cmake)
240
241 ### Build some Maintainer files
242 include(${CMAKE_HOME_DIRECTORY}/tools/cmake/MaintainerMode.cmake)
243 include(${CMAKE_HOME_DIRECTORY}/tools/cmake/UnitTesting.cmake)
244
245 ### Setup gcc & clang flags
246 if (NOT MSVC)
247   include(${CMAKE_HOME_DIRECTORY}/tools/cmake/Flags.cmake)
248 endif()
249
250 ### Make Libs
251 if(NOT WIN32)
252   include(${CMAKE_HOME_DIRECTORY}/tools/cmake/MakeLib.cmake)
253 else()
254   include(${CMAKE_HOME_DIRECTORY}/tools/cmake/MakeLibWin.cmake)
255 endif()
256
257 if(enable_java)
258   include(${CMAKE_HOME_DIRECTORY}/tools/cmake/MakeJava.cmake)
259 endif()
260
261 ### Make Exes
262 include(${CMAKE_HOME_DIRECTORY}/tools/cmake/MakeExe.cmake)
263
264 ### Make tests
265 if(enable_memcheck_xml)
266   set(enable_memcheck true)
267 endif()
268
269 include(${CMAKE_HOME_DIRECTORY}/tools/cmake/AddTests.cmake)
270 include(${CMAKE_HOME_DIRECTORY}/tools/cmake/CTestConfig.cmake)
271
272 ### Setup the distrib
273 include(${CMAKE_HOME_DIRECTORY}/tools/cmake/Distrib.cmake)
274
275 ### Pipol compilation
276 include(${CMAKE_HOME_DIRECTORY}/tools/cmake/Pipol.cmake)
277
278 ### Build the doc
279 if(NOT WIN32)
280   include(${CMAKE_HOME_DIRECTORY}/tools/cmake/GenerateDoc.cmake)
281 else()
282   include(${CMAKE_HOME_DIRECTORY}/tools/cmake/GenerateDocWin.cmake)
283 endif()
284
285 ### Print ARGS
286 include(${CMAKE_HOME_DIRECTORY}/tools/cmake/PrintArgs.cmake)
287
288 INCLUDE(Dart)