Logo AND Algorithmique Numérique Distribuée

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