Logo AND Algorithmique Numérique Distribuée

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