Logo AND Algorithmique Numérique Distribuée

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