Logo AND Algorithmique Numérique Distribuée

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