Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Prevent warning message 'config elem ... registered twice'
[simgrid.git] / CMakeLists.txt
1 cmake_minimum_required(VERSION 2.6)
2 # Java requires 2.8.6
3 message(STATUS "Cmake version ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}")
4
5 project(SimGrid C CXX)
6
7 #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
8 #     Check for the compiler        #
9 #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
10
11 ### Need to set rc ccompiler before enable language
12 if(WIN32)
13   SET(CMAKE_RC_COMPILER "windres")
14 endif()
15
16 ## 
17 ## Check the C/C++ standard that we need
18 ##   See also tools/cmake/GCCFlags.cmake that sets our paranoid warning flags
19 if (MSVC)
20   message("-- You are compiling SimGrid with MicroSoft Visual C. Good luck.")
21
22   set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_SCL_SECURE_NO_WARNINGS")
23   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_SCL_SECURE_NO_WARNINGS")
24 else() # gcc or clang
25   INCLUDE(CheckCCompilerFlag)
26   CHECK_C_COMPILER_FLAG(-fstack-cleaner HAVE_C_STACK_CLEANER)
27
28   ## Request full debugging flags
29   set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g3")
30   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g3")
31   set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -g")
32
33   if (CMAKE_COMPILER_IS_GNUCC)
34     if (COMPILER_CXX_VERSION_MAJOR_MINOR STRLESS "4.7")
35       message(FATAL_ERROR
36               "SimGrid needs at least g++ version 4.7 to compile "
37               "(c++11 support of previous versions is too limited).")
38     endif()
39   endif()
40
41   ## We need a decent support of the c++11 standard
42   include(CheckCXXCompilerFlag)
43   CHECK_CXX_COMPILER_FLAG("-std=gnu++11" COMPILER_SUPPORTS_CXX11)
44   if(COMPILER_SUPPORTS_CXX11)
45     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
46   else() 
47     message(FATAL_ERROR 
48             "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. "
49             "Please use a decent C++ compiler.")
50   endif()
51
52   ### And we need C11 standard, too
53   include(CheckCCompilerFlag)
54   CHECK_C_COMPILER_FLAG("-std=gnu11" COMPILER_SUPPORTS_C11)
55   if(COMPILER_SUPPORTS_C11)
56     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu11")
57   else()
58     message(FATAL_ERROR 
59             "The compiler ${CMAKE_C_COMPILER} has no C11 support. "
60             "Please use a decent C compiler "
61             "(note that c++11 support of ${CMAKE_CXX_COMPILER} seems ok).")
62   endif()
63   if(APPLE AND ("4.6" GREATER COMPILER_C_VERSION_MAJOR_MINOR))
64       ### gcc 4.[1-5] cannot compile ucontext on OSX
65       message(STATUS "Ucontext can't be used with this version of gcc (must be greater than 4.5)")
66       set(HAVE_UCONTEXT_H 0)
67   endif()
68 endif() # NOT MSVC
69
70 ### SMPI vs. Fortran
71 if ((NOT DEFINED enable_smpi OR enable_smpi) AND NOT APPLE) # smpi is enabled by default
72   # Call enable_language(Fortran) in order to load the build rules for
73   # this language, needed by teshsuite/smpi/mpich-test/.  Use
74   # CMAKE_FORCE_Fortran_COMPILER to bypass checks for a working
75   # compiler (smpiff don't exist at configure time).
76   include(CMakeForceCompiler)
77   if(NOT COMMAND CMAKE_FORCE_Fortran_COMPILER)
78     MACRO(CMAKE_FORCE_Fortran_COMPILER compiler id)
79       SET(CMAKE_Fortran_COMPILER "${compiler}")
80       SET(CMAKE_Fortran_COMPILER_ID_RUN TRUE)
81       SET(CMAKE_Fortran_COMPILER_ID ${id})
82       SET(CMAKE_Fortran_COMPILER_WORKS TRUE)
83       SET(CMAKE_Fortran_COMPILER_FORCED TRUE)
84
85       # Set old compiler id variables.
86       IF("${CMAKE_Fortran_COMPILER_ID}" MATCHES "GNU")
87         SET(CMAKE_COMPILER_IS_GNUG77 1)
88       ENDIF("${CMAKE_Fortran_COMPILER_ID}" MATCHES "GNU")
89     ENDMACRO(CMAKE_FORCE_Fortran_COMPILER)
90   endif()
91   CMAKE_FORCE_Fortran_COMPILER(smpiff smpiff)
92   enable_language(Fortran OPTIONAL)
93 endif()
94
95 #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
96 #     Build the version number      #
97 #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
98
99 set(SIMGRID_VERSION_MAJOR "3")
100 set(SIMGRID_VERSION_MINOR "13")
101 set(SIMGRID_VERSION_PATCH "0")
102 set(SIMGRID_VERSION_EXTRA "-devel") # Extra words to add to version string (e.g. -rc1)
103
104 set(SIMGRID_VERSION_DATE  "2015") # Year for copyright information
105
106 if(${SIMGRID_VERSION_PATCH} EQUAL "0")
107   set(release_version "${SIMGRID_VERSION_MAJOR}.${SIMGRID_VERSION_MINOR}")
108 else()
109   set(release_version "${SIMGRID_VERSION_MAJOR}.${SIMGRID_VERSION_MINOR}.${SIMGRID_VERSION_PATCH}")
110 endif()
111
112 set(SIMGRID_VERSION_STRING "SimGrid version ${release_version}${SIMGRID_VERSION_EXTRA}")
113 set(SIMGRID_VERSION_BANNER
114   "SIMGRID_VERSION_STRING\\nCopyright (c) 2004-${SIMGRID_VERSION_DATE}. The Simgrid Team.")
115
116 set(libsimgrid_version "${release_version}")
117 set(libsimgrid-java_version "${release_version}")
118
119 ### SET THE LIBRARY EXTENSION 
120 if(APPLE) #MAC
121   set(LIB_EXE "dylib")
122 else()
123   if(WIN32) #WINDOWS
124     set(LIB_EXE "a")
125     set(BIN_EXE ".exe")
126   else() #UNIX
127     set(LIB_EXE "so")
128   endif()
129 endif()
130
131 if(${CMAKE_C_COMPILER_ID} STREQUAL "GNU")
132   exec_program("${CMAKE_C_COMPILER} --version" OUTPUT_VARIABLE "COMPILER_C_VERSION")
133   exec_program("${CMAKE_CXX_COMPILER} --version" OUTPUT_VARIABLE "COMPILER_CXX_VERSION")
134   string(REGEX MATCH "[0-9].[0-9].[0-9]" COMPILER_C_VERSION "${COMPILER_C_VERSION}")
135   string(REGEX MATCH "[0-9].[0-9].[0-9]" COMPILER_CXX_VERSION "${COMPILER_CXX_VERSION}")
136
137   string(REGEX MATCH "^[0-9].[0-9]" COMPILER_C_VERSION_MAJOR_MINOR "${COMPILER_C_VERSION}")
138   string(REPLACE "${COMPILER_C_VERSION_MAJOR_MINOR}." "" COMPILER_C_VERSION_PATCH "${COMPILER_C_VERSION}")  
139 endif()
140
141 exec_program("${CMAKE_LINKER} --version" OUTPUT_VARIABLE "LINKER_VERSION")
142 string(REGEX MATCH "[0-9].[0-9]*" LINKER_VERSION "${LINKER_VERSION}")
143
144 ### Find programs and paths
145 FIND_PROGRAM(GCOV_PATH gcov)
146 include(FindPerl)
147 if(NOT PERL_EXECUTABLE)
148   message(FATAL_ERROR "-- SimGrid cannot be compiled without Perl installed -- sorry. Bailling out.")
149 endif()
150
151 if (APPLE)
152   set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
153   set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
154 endif()
155
156 ### Set some variables for Cmake
157 SET(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib)
158
159 set(INCLUDES
160   ${CMAKE_HOME_DIRECTORY}
161   ${CMAKE_HOME_DIRECTORY}/include
162   ${CMAKE_HOME_DIRECTORY}/src
163   ${CMAKE_HOME_DIRECTORY}/src/include
164   ${CMAKE_BINARY_DIR}
165   ${CMAKE_BINARY_DIR}/include
166   ${CMAKE_BINARY_DIR}/src
167   )
168
169 if(WIN32)
170   set(INCLUDES ${INCLUDES} ${CMAKE_HOME_DIRECTORY}/include/xbt ${CMAKE_HOME_DIRECTORY}/src/xbt) #for win32_ucontext.[ch]
171 endif()
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/GCCFlags.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/Java.cmake)
266 endif()
267
268 ### Make tests
269 if(enable_memcheck_xml)
270   set(enable_memcheck true)
271 endif()
272
273 INCLUDE(CTest)
274 ENABLE_TESTING()
275 include(${CMAKE_HOME_DIRECTORY}/tools/cmake/Tests.cmake)
276 include(${CMAKE_HOME_DIRECTORY}/tools/cmake/CTestConfig.cmake)
277
278 ### Define subdirectories
279 include(${CMAKE_HOME_DIRECTORY}/tools/cmake/MakeExe.cmake)
280
281 ### Setup the distrib
282 include(${CMAKE_HOME_DIRECTORY}/tools/cmake/Distrib.cmake)
283
284 ### Build the doc (Windows downloads the doc instead of regenerating)
285 #
286 if(NOT WIN32)
287   include(${CMAKE_HOME_DIRECTORY}/tools/cmake/Documentation.cmake)
288 else()
289   find_program(WGET_PROGRAM  NAMES wget)
290   message(STATUS "wget: ${WGET_PROGRAM}")
291   if(WGET_PROGRAM)
292     ADD_CUSTOM_TARGET(simgrid_documentation
293       COMMENT "Downloading the SimGrid documentation..."
294       COMMAND ${WGET_PROGRAM} -r -np -nH -nd http://simgrid.gforge.inria.fr/simgrid/${release_version}/doc/
295       WORKING_DIRECTORY ${CMAKE_HOME_DIRECTORY}/doc/html
296     )
297   endif()
298 endif()
299
300 ### Print ARGS
301 include(${CMAKE_HOME_DIRECTORY}/tools/cmake/PrintArgs.cmake)
302
303 INCLUDE(Dart)