Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix lua platform script
[simgrid.git] / CMakeLists.txt
1 cmake_minimum_required(VERSION 2.6)
2
3 IF(CMAKE_BUILD_TYPE STREQUAL "ModelChecker")
4   SET(enable_coverage ON)
5   SET(enable_model-checking ON)
6   SET(enable_lua ON)
7   SET(enable_compile_optimization OFF)
8 ENDIF()
9
10 ### Need to set rc ccompiler before enable language
11 if(WIN32)
12   SET(CMAKE_RC_COMPILER "windres")
13 endif()
14 project(SimGrid C)
15 if (enable_gtnets OR enable_ns3)
16   enable_language(CXX)
17 endif()
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
57 set(SIMGRID_VERSION_MAJOR "3")
58 set(SIMGRID_VERSION_MINOR "9")
59 set(SIMGRID_VERSION_PATCH "0")
60
61 if(${SIMGRID_VERSION_PATCH} EQUAL "0")
62   set(release_version "${SIMGRID_VERSION_MAJOR}.${SIMGRID_VERSION_MINOR}")
63 else()
64   set(release_version "${SIMGRID_VERSION_MAJOR}.${SIMGRID_VERSION_MINOR}.${SIMGRID_VERSION_PATCH}")
65 endif()
66 set(libsimgrid_version "${release_version}")
67 set(libsmpi_version "${release_version}")
68 set(GCC_NEED_VERSION "4.0")
69 set(APPLE_NEED_GCC_VERSION "4.6")
70
71 ### SET THE LIBRARY EXTENSION AND GCC VERSION
72 if(APPLE) #MAC
73   set(LIB_EXE "dylib")
74 else()
75   if(WIN32) #WINDOWS
76     set(LIB_EXE "a")
77     set(BIN_EXE ".exe")
78   else() #UNIX
79     set(LIB_EXE "so")
80   endif()
81 endif()
82
83 string(REGEX MATCH "gcc" GCC "${CMAKE_C_COMPILER}")
84 if(GCC)
85   exec_program("${CMAKE_C_COMPILER} --version" OUTPUT_VARIABLE "COMPILER_C_VERSION")
86   exec_program("${CMAKE_CXX_COMPILER} --version" OUTPUT_VARIABLE "COMPILER_CXX_VERSION")
87   string(REGEX MATCH "[0-9].[0-9].[0-9]" COMPILER_C_VERSION "${COMPILER_C_VERSION}")
88   string(REGEX MATCH "[0-9].[0-9].[0-9]" COMPILER_CXX_VERSION "${COMPILER_CXX_VERSION}")
89
90   string(REGEX MATCH "^[0-9].[0-9]" COMPILER_C_VERSION_MAJOR_MINOR "${COMPILER_C_VERSION}")
91   string(REPLACE "${COMPILER_C_VERSION_MAJOR_MINOR}." "" COMPILER_C_VERSION_PATCH "${COMPILER_C_VERSION}")
92
93   if(${GCC_NEED_VERSION} GREATER  COMPILER_C_VERSION_MAJOR_MINOR)
94     message(FATAL_ERROR "Gcc must be to version ${GCC_NEED_VERSION} current version ${COMPILER_C_VERSION_MAJOR_MINOR}")
95   endif()
96 endif()
97
98 string(REGEX MATCH "cl.exe" VBC "${CMAKE_C_COMPILER}")
99 if(VBC)
100   message(FATAL_ERROR "VB is not yet supported by Simgrid.")
101 endif()
102
103 ### Find programs and paths
104 FIND_PROGRAM(GCOV_PATH gcov)
105 include(FindPerl)
106 if(NOT PERL_EXECUTABLE)
107   message(FATAL_ERROR "-- SimGrid cannot be compiled without Perl installed -- sorry. Bailling out.")
108 endif()
109
110 ### Set some variables for Cmake
111 SET(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib)
112
113 set(INCLUDES
114   ${CMAKE_HOME_DIRECTORY}
115   ${CMAKE_HOME_DIRECTORY}/include
116   ${CMAKE_HOME_DIRECTORY}/src
117   ${CMAKE_HOME_DIRECTORY}/src/include
118   ${CMAKE_BINARY_DIR}
119   ${CMAKE_BINARY_DIR}/include
120   ${CMAKE_BINARY_DIR}/src
121   )
122
123 if(WIN32)
124   set(INCLUDES ${INCLUDES} ${CMAKE_HOME_DIRECTORY}/include/xbt ${CMAKE_HOME_DIRECTORY}/src/xbt) #for win32_ucontext.[ch]
125 endif()
126 set(CMAKE_SOURCE_DIR ${PROJECT_SOURCE_DIRECTORY})
127
128 if(NOT CMAKE_CROSSCOMPILING AND EXISTS /usr/include/)
129   set(INCLUDES ${INCLUDES} /usr/include/)
130 endif()
131
132 ### Check 32bits or 64bits
133 INCLUDE (CheckTypeSize)
134 CHECK_TYPE_SIZE("void*" SIZEOF_VOIDSTAR)
135 IF(SIZEOF_VOIDSTAR EQUAL 4)
136   SET(ARCH_32_BITS 1)
137 ELSE()
138   SET(ARCH_32_BITS 0)
139 ENDIF()
140
141 if(WIN32)
142
143   #Need env INCLUDE
144   set(CMAKE_INCLUDE_WIN "${CMAKE_C_COMPILER}")
145   set(CMAKE_LIB_WIN "${CMAKE_C_COMPILER}")
146   string(REGEX REPLACE "/bin/gcc.*" "/include"  CMAKE_INCLUDE_WIN "${CMAKE_INCLUDE_WIN}")
147   string(REGEX REPLACE "/bin/gcc.*" "/lib"  CMAKE_LIB_WIN "${CMAKE_LIB_WIN}")
148   set(INCLUDES ${INCLUDES} ${CMAKE_INCLUDE_WIN})
149
150   if(CMAKE_COMPILER_IS_GNUCC)
151     set(__GNUC__ 1)
152     exec_program("${CMAKE_C_COMPILER} --version" OUTPUT_VARIABLE "COMPILER_C_VERSION")
153     string(REGEX MATCH "[0-9].[0-9].[0-9]" COMPILER_C_VERSION "${COMPILER_C_VERSION}")
154     string(REGEX MATCH "^[0-9]" COMPILER_C_MAJOR_VERSION "${COMPILER_C_VERSION}")
155     string(REGEX MATCH "^[0-9].[0-9]" COMPILER_C_MINOR_VERSION "${COMPILER_C_VERSION}")
156     string(REGEX REPLACE "^${COMPILER_C_MAJOR_VERSION}." "" COMPILER_C_MINOR_VERSION "${COMPILER_C_MINOR_VERSION}")
157     if(COMPILER_C_MAJOR_VERSION)
158       # set(__GNUC__ ${COMPILER_C_MAJOR_VERSION})
159     endif()
160     if(COMPILER_C_MINOR_VERSION)
161       # set(__GNUC_MINOR__ ${COMPILER_C_MINOR_VERSION})
162     endif()
163     set(MSVC 0)
164     set(BORLAND 0)
165   else()
166     message(FATAL_ERROR "Please use MinGW to compile SimGrid!")
167   endif()
168
169   if(ARCH_32_BITS)      ### Arch 32bits
170     set(_WIN32 1)
171   else()        ### Arch 64bits
172     set(_WIN64 1)
173   endif()
174
175   set(NSIS_WIN_VERSION $ENV{PROCESSOR_ARCHITEW6432})
176   if(NSIS_WIN_VERSION MATCHES "")
177     set(NSIS_WIN_VERSION $ENV{PROCESSOR_ARCHITECTURE})
178   endif()
179   string(TOLOWER ${NSIS_WIN_VERSION} NSIS_WIN_VERSION)
180
181   set(_XBT_WIN32 1)
182
183   message(STATUS "C_COMPILER                    ${CMAKE_C_COMPILER} ${COMPILER_C_VERSION}")
184   message(STATUS "CXX_COMPILER                  ${CMAKE_CXX_COMPILER} ${COMPILER_CXX_VERSION}")
185   message(STATUS "CMAKE_RC_COMPILER             ${CMAKE_RC_COMPILER}")
186   message(STATUS "INCLUDE                       ${CMAKE_INCLUDE_WIN}")
187   message(STATUS "LIB                           ${CMAKE_LIB_WIN}")
188   message(STATUS "MAKE_PROGRAM                  ${CMAKE_MAKE_PROGRAM}")
189   message(STATUS "CMAKE_BUILD_TOOL              ${CMAKE_BUILD_TOOL}")
190   message(STATUS "LINKER                        ${CMAKE_LINKER}")
191   message(STATUS "CMAKE_GENERATOR               ${CMAKE_GENERATOR}")
192   message(STATUS "BORLAND                       ${BORLAND}")
193   message(STATUS "VISUALC                       ${MSVC}")
194   message(STATUS "GNUC                          ${CMAKE_COMPILER_IS_GNUCC}")
195
196 endif()
197
198 include_directories(${INCLUDES})
199
200 ### Determine the assembly flavor that we need today
201 include(CMakeDetermineSystem)
202 set(PROCESSOR_${CMAKE_SYSTEM_PROCESSOR} 1)
203
204 ### Setup Options
205 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/Option.cmake)
206
207 ### Make the *.h files with *.h.in files
208 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/CompleteInFiles.cmake)
209
210 ### Define source packages for Libs
211 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/DefinePackages.cmake)
212
213 ### Build some Maintainer files
214 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/MaintainerMode.cmake)
215 if(NOT WIN32)
216   include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/UnitTesting.cmake)
217 endif()
218
219 ### Setup gcc flags
220 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/Flags.cmake)
221
222 ### Make Libs
223 if(NOT WIN32)
224   include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/MakeLib.cmake)
225 else()
226   include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/MakeLibWin.cmake)
227 endif()
228
229 ### Make Exes
230 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/MakeExe.cmake)
231
232 ### Make tests
233 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/AddTests.cmake)
234 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/CTestConfig.cmake)
235
236 ### Setup the distrib
237 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/Distrib.cmake)
238
239 ### Pipol compilation
240 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/Pipol.cmake)
241
242 ### Build the doc
243 if(NOT WIN32)
244   include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/GenerateDoc.cmake)
245 else()
246   include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/GenerateDocWin.cmake)
247 endif()
248
249 ### Print ARGS
250 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/PrintArgs.cmake)
251
252 INCLUDE(Dart)