Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
finish the s/smurf/popping/ renaming
[simgrid.git] / CMakeLists.txt
1 cmake_minimum_required(VERSION 2.6)
2 ### Need to set rc ccompiler before enable language
3 if(WIN32)
4   SET(CMAKE_RC_COMPILER "windres")
5 endif()
6 project(SimGrid C)
7 if (enable_gtnets OR enable_ns3 OR enable_model-checking)
8   enable_language(CXX)
9 endif()
10
11 enable_language(CXX)
12
13 if (APPLE) #MAC
14   set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
15   set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
16 endif()
17
18 if (NOT DEFINED enable_smpi OR enable_smpi) # smpi is enabled by default
19   # Call enable_language(Fortran) in order to load the build rules for
20   # this language, needed by teshsuite/smpi/mpich-test/.  Use
21   # CMAKE_FORCE_Fortran_COMPILER to bypass checks for a working
22   # compiler (smpiff don't exist at configure time).
23   include(CMakeForceCompiler)
24   if(NOT COMMAND CMAKE_FORCE_Fortran_COMPILER)
25     MACRO(CMAKE_FORCE_Fortran_COMPILER compiler id)
26       SET(CMAKE_Fortran_COMPILER "${compiler}")
27       SET(CMAKE_Fortran_COMPILER_ID_RUN TRUE)
28       SET(CMAKE_Fortran_COMPILER_ID ${id})
29       SET(CMAKE_Fortran_COMPILER_WORKS TRUE)
30       SET(CMAKE_Fortran_COMPILER_FORCED TRUE)
31
32       # Set old compiler id variables.
33       IF("${CMAKE_Fortran_COMPILER_ID}" MATCHES "GNU")
34         SET(CMAKE_COMPILER_IS_GNUG77 1)
35       ENDIF("${CMAKE_Fortran_COMPILER_ID}" MATCHES "GNU")
36     ENDMACRO(CMAKE_FORCE_Fortran_COMPILER)
37   endif()
38   CMAKE_FORCE_Fortran_COMPILER(smpiff smpiff)
39   enable_language(Fortran OPTIONAL)
40 endif()
41
42 set(CMAKE_C_FLAGS "" CACHE TYPE INTERNAL FORCE)
43 set(CMAKE_CXX_FLAGS "" CACHE TYPE INTERNAL FORCE)
44 set(CMAKE_EXE_LINKER_FLAGS "" CACHE TYPE INTERNAL FORCE)
45 set(CMAKE_C_LINK_FLAGS "" CACHE TYPE INTERNAL FORCE)
46 set(CMAKE_Fortran_FLAGS "" CACHE TYPE INTERNAL FORCE)
47 set(CMAKE_Fortran_LINK_FLAGS "" CACHE TYPE INTERNAL FORCE)
48 ## Mapping version number -> version name
49 # 3.5.99 -> alpha1 (oops)
50 # 3.5.9{1,2} -> beta{1,2}
51 # 3.5.9{3,4,5} -> rc{1,2,3}
52 # 3.6.{0,1,2} -> release 3.6, 3.6.1, 3.6.2
53 # 3.7.{0,1} -> release 3.7, 3.7.1
54 # 3.8.{0,1} -> release 3.8, 3.8.1
55 # 3.9.0 -> release 3.9
56 # 3.9.90 -> release 3.10pre1
57 # 3.10.0 -> release 3.10
58 # 3.11.0 -> release 3.11
59 # 3.12.0 -> release 3.12
60
61 set(SIMGRID_VERSION_MAJOR "3")
62 set(SIMGRID_VERSION_MINOR "12")
63 set(SIMGRID_VERSION_PATCH "0")
64 set(SIMGRID_VERSION_EXTRA "-devel") # Extra words to add to version string (e.g. -rc1)
65
66 set(SIMGRID_VERSION_DATE  "2014") # Year for copyright information
67
68 if(${SIMGRID_VERSION_PATCH} EQUAL "0")
69   set(release_version "${SIMGRID_VERSION_MAJOR}.${SIMGRID_VERSION_MINOR}")
70 else()
71   set(release_version "${SIMGRID_VERSION_MAJOR}.${SIMGRID_VERSION_MINOR}.${SIMGRID_VERSION_PATCH}")
72 endif()
73
74 set(SIMGRID_VERSION_STRING
75   "SimGrid version ${release_version}${SIMGRID_VERSION_EXTRA}\\nCopyright (c) 2004-${SIMGRID_VERSION_DATE}. The Simgrid Team.")
76
77 set(libsimgrid_version "${release_version}")
78 set(libsimgrid-java_version "${release_version}")
79 set(GCC_NEED_VERSION "4.0")
80 set(APPLE_NEED_GCC_VERSION "4.6")
81
82 ### SET THE LIBRARY EXTENSION AND GCC VERSION
83 if(APPLE) #MAC
84   set(LIB_EXE "dylib")
85 else()
86   if(WIN32) #WINDOWS
87     set(LIB_EXE "a")
88     set(BIN_EXE ".exe")
89   else() #UNIX
90     set(LIB_EXE "so")
91   endif()
92 endif()
93
94 if(${CMAKE_C_COMPILER_ID} STREQUAL "GNU")
95   exec_program("${CMAKE_C_COMPILER} --version" OUTPUT_VARIABLE "COMPILER_C_VERSION")
96   exec_program("${CMAKE_CXX_COMPILER} --version" OUTPUT_VARIABLE "COMPILER_CXX_VERSION")
97   string(REGEX MATCH "[0-9].[0-9].[0-9]" COMPILER_C_VERSION "${COMPILER_C_VERSION}")
98   string(REGEX MATCH "[0-9].[0-9].[0-9]" COMPILER_CXX_VERSION "${COMPILER_CXX_VERSION}")
99
100   string(REGEX MATCH "^[0-9].[0-9]" COMPILER_C_VERSION_MAJOR_MINOR "${COMPILER_C_VERSION}")
101   string(REPLACE "${COMPILER_C_VERSION_MAJOR_MINOR}." "" COMPILER_C_VERSION_PATCH "${COMPILER_C_VERSION}")
102
103   if(${GCC_NEED_VERSION} GREATER  COMPILER_C_VERSION_MAJOR_MINOR)
104     message(FATAL_ERROR "Gcc must be to version ${GCC_NEED_VERSION} current version ${COMPILER_C_VERSION_MAJOR_MINOR}")
105   endif()
106   
107   if(COMPILER_C_VERSION_MAJOR_MINOR STRGREATER "4.8")
108     set (CMAKE_AR gcc-ar)
109     set (CMAKE_RANLIB gcc-ranlib)
110   endif()
111   
112 endif()
113
114 exec_program("${CMAKE_LINKER} --version" OUTPUT_VARIABLE "LINKER_VERSION")
115 string(REGEX MATCH "[0-9].[0-9]*" LINKER_VERSION "${LINKER_VERSION}")
116
117 string(REGEX MATCH "cl.exe" VBC "${CMAKE_C_COMPILER}")
118 if(VBC)
119   message(FATAL_ERROR "VB is not yet supported by Simgrid.")
120 endif()
121
122 ### Find programs and paths
123 FIND_PROGRAM(GCOV_PATH gcov)
124 include(FindPerl)
125 if(NOT PERL_EXECUTABLE)
126   message(FATAL_ERROR "-- SimGrid cannot be compiled without Perl installed -- sorry. Bailling out.")
127 endif()
128
129 ### Set some variables for Cmake
130 SET(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib)
131
132 set(INCLUDES
133   ${CMAKE_HOME_DIRECTORY}
134   ${CMAKE_HOME_DIRECTORY}/include
135   ${CMAKE_HOME_DIRECTORY}/src
136   ${CMAKE_HOME_DIRECTORY}/src/include
137   ${CMAKE_BINARY_DIR}
138   ${CMAKE_BINARY_DIR}/include
139   ${CMAKE_BINARY_DIR}/src
140   )
141
142 if(WIN32)
143   set(INCLUDES ${INCLUDES} ${CMAKE_HOME_DIRECTORY}/include/xbt ${CMAKE_HOME_DIRECTORY}/src/xbt) #for win32_ucontext.[ch]
144 endif()
145 set(CMAKE_SOURCE_DIR ${PROJECT_SOURCE_DIRECTORY})
146
147 if(NOT CMAKE_CROSSCOMPILING AND EXISTS /usr/include/)
148   set(INCLUDES ${INCLUDES} /usr/include/)
149 endif()
150
151 ### Check 32bits or 64bits
152 INCLUDE (CheckTypeSize)
153 CHECK_TYPE_SIZE("void*" SIZEOF_VOIDSTAR)
154 IF(SIZEOF_VOIDSTAR EQUAL 4)
155   SET(ARCH_32_BITS 1)
156 ELSE()
157   SET(ARCH_32_BITS 0)
158 ENDIF()
159
160 if(WIN32)
161
162   #Need env INCLUDE
163   set(CMAKE_INCLUDE_WIN "${CMAKE_C_COMPILER}")
164   set(CMAKE_LIB_WIN "${CMAKE_C_COMPILER}")
165   string(REGEX REPLACE "/bin/gcc.*" "/include"  CMAKE_INCLUDE_WIN "${CMAKE_INCLUDE_WIN}")
166   string(REGEX REPLACE "/bin/gcc.*" "/lib"  CMAKE_LIB_WIN "${CMAKE_LIB_WIN}")
167   set(INCLUDES ${INCLUDES} ${CMAKE_INCLUDE_WIN})
168
169   if(CMAKE_COMPILER_IS_GNUCC)
170     set(__GNUC__ 1)
171     exec_program("${CMAKE_C_COMPILER} --version" OUTPUT_VARIABLE "COMPILER_C_VERSION")
172     string(REGEX MATCH "[0-9].[0-9].[0-9]" COMPILER_C_VERSION "${COMPILER_C_VERSION}")
173     string(REGEX MATCH "^[0-9]" COMPILER_C_MAJOR_VERSION "${COMPILER_C_VERSION}")
174     string(REGEX MATCH "^[0-9].[0-9]" COMPILER_C_MINOR_VERSION "${COMPILER_C_VERSION}")
175     string(REGEX REPLACE "^${COMPILER_C_MAJOR_VERSION}." "" COMPILER_C_MINOR_VERSION "${COMPILER_C_MINOR_VERSION}")
176     if(COMPILER_C_MAJOR_VERSION)
177       # set(__GNUC__ ${COMPILER_C_MAJOR_VERSION})
178     endif()
179     if(COMPILER_C_MINOR_VERSION)
180       # set(__GNUC_MINOR__ ${COMPILER_C_MINOR_VERSION})
181     endif()
182     set(MSVC 0)
183     set(BORLAND 0)
184   else()
185     message(FATAL_ERROR "Please use MinGW to compile SimGrid!")
186   endif()
187
188   if(ARCH_32_BITS)      ### Arch 32bits
189     set(_WIN32 1)
190   else()        ### Arch 64bits
191     set(_WIN64 1)
192   endif()
193
194   set(NSIS_WIN_VERSION $ENV{PROCESSOR_ARCHITEW6432})
195   if(NSIS_WIN_VERSION MATCHES "")
196     set(NSIS_WIN_VERSION $ENV{PROCESSOR_ARCHITECTURE})
197   endif()
198   string(TOLOWER ${NSIS_WIN_VERSION} NSIS_WIN_VERSION)
199
200   set(_XBT_WIN32 1)
201
202   message(STATUS "C_COMPILER                    ${CMAKE_C_COMPILER} ${COMPILER_C_VERSION}")
203   message(STATUS "CXX_COMPILER                  ${CMAKE_CXX_COMPILER} ${COMPILER_CXX_VERSION}")
204   message(STATUS "CMAKE_RC_COMPILER             ${CMAKE_RC_COMPILER}")
205   message(STATUS "INCLUDE                       ${CMAKE_INCLUDE_WIN}")
206   message(STATUS "LIB                           ${CMAKE_LIB_WIN}")
207   message(STATUS "MAKE_PROGRAM                  ${CMAKE_MAKE_PROGRAM}")
208   message(STATUS "CMAKE_BUILD_TOOL              ${CMAKE_BUILD_TOOL}")
209   message(STATUS "LINKER                        ${CMAKE_LINKER}")
210   message(STATUS "CMAKE_GENERATOR               ${CMAKE_GENERATOR}")
211   message(STATUS "BORLAND                       ${BORLAND}")
212   message(STATUS "VISUALC                       ${MSVC}")
213   message(STATUS "GNUC                          ${CMAKE_COMPILER_IS_GNUCC}")
214
215 endif()
216
217 include_directories(${INCLUDES})
218
219 ### Setup Options
220 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/Option.cmake)
221
222 ### Make the *.h files with *.h.in files
223 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/CompleteInFiles.cmake)
224
225 ### Define source packages for Libs
226 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/DefinePackages.cmake)
227
228 ### Build some Maintainer files
229 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/MaintainerMode.cmake)
230 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/UnitTesting.cmake)
231
232 ### Setup gcc flags
233 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/Flags.cmake)
234
235 ### Make Libs
236 if(NOT WIN32)
237   include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/MakeLib.cmake)
238 else()
239   include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/MakeLibWin.cmake)
240 endif()
241
242 ### Make Exes
243 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/MakeExe.cmake)
244
245 ### Make tests
246 if(enable_memcheck_xml)
247   set(enable_memcheck true)
248 endif()
249
250 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/AddTests.cmake)
251 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/CTestConfig.cmake)
252
253 ### Setup the distrib
254 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/Distrib.cmake)
255
256 ### Pipol compilation
257 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/Pipol.cmake)
258
259 ### Build the doc
260 if(NOT WIN32)
261   include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/GenerateDoc.cmake)
262 else()
263   include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/GenerateDocWin.cmake)
264 endif()
265
266 ### Print ARGS
267 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/PrintArgs.cmake)
268
269 INCLUDE(Dart)