Logo AND Algorithmique Numérique Distribuée

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