Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Remove ; after SG_BEGIN_DECL().
[simgrid.git] / CMakeLists.txt
1 cmake_minimum_required(VERSION 2.8)
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 get_filename_component(TRUE_CMAKE_HOME_DIRECTORY "${CMAKE_HOME_DIRECTORY}" REALPATH)
53 get_filename_component(TRUE_CMAKE_BINARY_DIR "${CMAKE_BINARY_DIR}" REALPATH)
54 if(${TRUE_CMAKE_HOME_DIRECTORY} STREQUAL ${CMAKE_HOME_DIRECTORY})
55 else(${TRUE_CMAKE_HOME_DIRECTORY} STREQUAL ${CMAKE_HOME_DIRECTORY})
56         message(STATUS "Change link path '${CMAKE_HOME_DIRECTORY}' to true path '${TRUE_CMAKE_HOME_DIRECTORY}'")
57         set(CMAKE_HOME_DIRECTORY "${TRUE_CMAKE_HOME_DIRECTORY}" CACHE TYPE INTERNAL FORCE)
58         set(CMAKE_SOURCE_DIR "${TRUE_CMAKE_HOME_DIRECTORY}" CACHE TYPE INTERNAL FORCE)
59 endif(${TRUE_CMAKE_HOME_DIRECTORY} STREQUAL ${CMAKE_HOME_DIRECTORY})
60
61 if(${TRUE_CMAKE_BINARY_DIR} STREQUAL ${CMAKE_BINARY_DIR})
62 else(${TRUE_CMAKE_BINARY_DIR} STREQUAL ${CMAKE_BINARY_DIR})
63         message(STATUS "Change link path '${CMAKE_BINARY_DIR}' to true path '${TRUE_CMAKE_BINARY_DIR}'")
64         set(CMAKE_BINARY_DIR "${TRUE_CMAKE_BINARY_DIR}" CACHE TYPE INTERNAL FORCE)
65 endif(${TRUE_CMAKE_BINARY_DIR} STREQUAL ${CMAKE_BINARY_DIR})    
66
67 ### Set some variables for Cmake
68 SET(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib)
69
70 if("${CMAKE_BINARY_DIR}" STREQUAL "${CMAKE_HOME_DIRECTORY}")
71         set(INCLUDES
72         ${CMAKE_HOME_DIRECTORY}
73         ${CMAKE_HOME_DIRECTORY}/include
74         ${CMAKE_HOME_DIRECTORY}/src
75         ${CMAKE_HOME_DIRECTORY}/src/include
76         )
77 else("${CMAKE_BINARY_DIR}" STREQUAL "${CMAKE_HOME_DIRECTORY}")
78         set(INCLUDES
79         ${CMAKE_HOME_DIRECTORY}
80         ${CMAKE_HOME_DIRECTORY}/include
81         ${CMAKE_HOME_DIRECTORY}/src
82         ${CMAKE_HOME_DIRECTORY}/src/include
83         ${CMAKE_BINARY_DIR}
84         ${CMAKE_BINARY_DIR}/include
85         ${CMAKE_BINARY_DIR}/src
86         )
87 endif("${CMAKE_BINARY_DIR}" STREQUAL "${CMAKE_HOME_DIRECTORY}")
88
89 set(INCLUDES ${INCLUDES} ${CMAKE_HOME_DIRECTORY} ${CMAKE_HOME_DIRECTORY}/include ${CMAKE_HOME_DIRECTORY}/src/include ${CMAKE_HOME_DIRECTORY}/src ${CMAKE_BINARY_DIR}/src)
90 if(WIN32)
91     set(INCLUDES ${INCLUDES} ${CMAKE_HOME_DIRECTORY}/include/xbt ${CMAKE_HOME_DIRECTORY}/src/xbt) #for win32_ucontext.[ch]
92 endif(WIN32)
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(NOT CMAKE_CROSSCOMPILING AND EXISTS /usr/include/)
98
99 ### Check 32bits or 64bits
100 INCLUDE (CheckTypeSize)
101 CHECK_TYPE_SIZE("long" SIZEOF_LONG)
102 IF(SIZEOF_LONG EQUAL 4)
103   SET(ARCH_32_BITS 1)
104 ELSE(SIZEOF_LONG EQUAL 4)
105   SET(ARCH_32_BITS 0)
106 ENDIF(SIZEOF_LONG EQUAL 4)
107
108 if(WIN32)
109
110         set(INCLUDES_MORE $ENV{INCLUDE})
111         string(REPLACE "\\" "/" INCLUDES_MORE "${INCLUDES_MORE}")
112         foreach(include_dir ${INCLUDES_MORE})
113             if(IS_DIRECTORY ${include_dir})
114                 string(REGEX MATCH ".*[ ].*" testoki "${include_dir}")
115                 if(testoki)
116                         string(REPLACE " " "\\ " include_dir "${include_dir}")
117                     set(INCLUDES ${INCLUDES} \"${include_dir}\")
118                 else(testoki)
119                     set(INCLUDES ${INCLUDES} ${include_dir})
120                 endif(testoki)
121             else(IS_DIRECTORY ${include_dir})
122                 message(FATAL_ERROR "${include_dir} not find")
123             endif(IS_DIRECTORY ${include_dir})
124         endforeach(include_dir ${INCLUDES_MORE})
125
126     if(BORLAND)                 ### BORLAND COMPILER
127             set(__BORLANDC__ 1)
128             set(CMAKE_COMPILER_IS_GNUCC 0)
129             set(MSVC 0)
130             set(_XBT_BORLANDC_COMPILER 1)
131     endif(BORLAND)
132     
133     if(MSVC)    ### MicroSoftVisualC COMPILER
134             set(__VISUALC__ 1)
135             set(BORLAND 0)
136             set(CMAKE_COMPILER_IS_GNUCC 0)
137             set(_XBT_VISUALC_COMPILER 1)
138             set(_MSC_VER 1)
139         set(__STRICT_ANSI__ 1)
140         set(_M_IX86 1)
141     endif(MSVC)
142     
143     if(CMAKE_COMPILER_IS_GNUCC)
144         set(__GNUC__ 1)
145         exec_program("${CMAKE_C_COMPILER} --version" OUTPUT_VARIABLE "COMPILER_C_VERSION")
146         string(REGEX MATCH "[0-9].[0-9].[0-9]" COMPILER_C_VERSION "${COMPILER_C_VERSION}")
147         string(REGEX MATCH "^[0-9]" COMPILER_C_MAJOR_VERSION "${COMPILER_C_VERSION}")
148         string(REGEX MATCH "^[0-9].[0-9]" COMPILER_C_MINOR_VERSION "${COMPILER_C_VERSION}")
149         string(REGEX REPLACE "^${COMPILER_C_MAJOR_VERSION}." "" COMPILER_C_MINOR_VERSION "${COMPILER_C_MINOR_VERSION}")
150         if(COMPILER_C_MAJOR_VERSION)
151            # set(__GNUC__ ${COMPILER_C_MAJOR_VERSION})
152         endif(COMPILER_C_MAJOR_VERSION)
153         if(COMPILER_C_MINOR_VERSION)
154            # set(__GNUC_MINOR__ ${COMPILER_C_MINOR_VERSION})
155         endif(COMPILER_C_MINOR_VERSION)
156         set(MSVC 0)
157             set(BORLAND 0)
158     endif(CMAKE_COMPILER_IS_GNUCC)
159     
160     if(ARCH_32_BITS)    ### Arch 32bits
161         set(_WIN32 1)
162     else(ARCH_32_BITS)  ### Arch 64bits
163         set(_WIN64 1)
164     endif(ARCH_32_BITS)
165     
166     set(_XBT_WIN32 1)
167     
168     message(STATUS "C_COMPILER                  $ENV{CC}")
169     message(STATUS "CXX_COMPILER                        $ENV{CXX}")    
170     message(STATUS "INCLUDE                     $ENV{INCLUDE}")
171     message(STATUS "LIB                         $ENV{LIB}")
172     message(STATUS "MAKE_PROGRAM                        ${CMAKE_MAKE_PROGRAM}")
173     message(STATUS "CMAKE_BUILD_TOOL            ${CMAKE_BUILD_TOOL}")
174     message(STATUS "LINKER                      ${CMAKE_LINKER}")
175     message(STATUS "CMAKE_GENERATOR             ${CMAKE_GENERATOR}")
176     message(STATUS "BORLAND                     ${BORLAND}")
177     message(STATUS "VISUALC                     ${MSVC}")
178     message(STATUS "GNUC                                ${CMAKE_COMPILER_IS_GNUCC}")
179    
180 endif(WIN32)
181
182 include_directories(${INCLUDES})
183
184 ### Determine the assembly flavor that we need today
185 include(CMakeDetermineSystem)
186 set(PROCESSOR_${CMAKE_SYSTEM_PROCESSOR} 1)
187
188 ### Setup Options
189 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/Option.cmake)
190
191 ### Make the *.h files with *.h.in files
192 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/CompleteInFiles.cmake)
193
194 ### Define source packages for Libs 
195 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/DefinePackages.cmake)
196
197 ### Build some Maintainer files
198 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/MaintainerMode.cmake)
199 if(NOT WIN32)
200 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/UnitTesting.cmake)
201 endif(NOT WIN32)
202
203 ### Setup gcc flags
204 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/Flags.cmake)
205
206 ### Make Libs
207 if(NOT WIN32)
208 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/MakeLib.cmake)
209 else(NOT WIN32)
210 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/MakeLibWin.cmake)
211 endif(NOT WIN32)
212
213 ### Make Exes
214 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/MakeExe.cmake)
215
216 ### Make Simgrid.jar and Java examples
217 if(HAVE_JAVA)
218         include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/MakeJava.cmake)
219 endif(HAVE_JAVA)
220
221 ### Make tests
222 if(NOT WIN32)
223 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/AddTests.cmake)
224 else(NOT WIN32)
225
226 endif(NOT WIN32)
227
228 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/CTestConfig.cmake)
229
230 ### Setup the distrib
231 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/Distrib.cmake)
232
233 ### Pipol compilation
234 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/Pipol.cmake)
235
236 if(NOT WIN32)
237 ### Build the doc
238 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/GenerateDoc.cmake)
239 endif(NOT WIN32)
240 ### Print ARGS
241 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/PrintArgs.cmake)
242
243 INCLUDE(Dart)