Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Action replayer: don't hardcode the usage of raw contextes
[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 ## Mapping version number -> version name
11 # 3.5.99 -> alpha1 (oops)
12 # 3.5.91 -> beta1
13 # 3.5.92 -> beta2
14 ### Version 3.5.91, aka 3.6 beta1
15 set(SIMGRID_VERSION_MAJOR "3")
16 set(SIMGRID_VERSION_MINOR "5")
17 set(SIMGRID_VERSION_PATCH "92")
18 set(release_version "${SIMGRID_VERSION_MAJOR}.${SIMGRID_VERSION_MINOR}")
19 set(libsimgrid_version "${release_version}")
20 set(libgras_version "${release_version}")
21 set(libsmpi_version "${release_version}")
22 set(GCC_NEED_VERSION "4.0")
23
24 ### SET THE LIBRARY EXTENSION AND GCC VERSION
25 if(APPLE) #MAC
26         set(LIB_EXE "dylib")
27 else(APPLE)
28     if(WIN32) #WINDOWS
29         set(LIB_EXE "a")
30     else(WIN32) #UNIX
31             set(LIB_EXE "so")
32     endif(WIN32)
33 endif(APPLE)
34
35 string(REGEX MATCH "gcc" GCC "${CMAKE_C_COMPILER}")
36 if(GCC)
37         exec_program("${CMAKE_C_COMPILER} --version" OUTPUT_VARIABLE "COMPILER_C_VERSION")
38         exec_program("${CMAKE_CXX_COMPILER} --version" OUTPUT_VARIABLE "COMPILER_CXX_VERSION")
39         string(REGEX MATCH "[0-9].[0-9].[0-9]" COMPILER_C_VERSION "${COMPILER_C_VERSION}")
40         string(REGEX MATCH "[0-9].[0-9].[0-9]" COMPILER_CXX_VERSION "${COMPILER_CXX_VERSION}")
41         
42         string(REGEX MATCH "^[0-9].[0-9]" COMPILER_C_VERSION_MAJOR_MINOR "${COMPILER_C_VERSION}")
43         string(REPLACE "${COMPILER_C_VERSION_MAJOR_MINOR}." "" COMPILER_C_VERSION_PATCH "${COMPILER_C_VERSION}")
44         
45         if(${GCC_NEED_VERSION} GREATER  COMPILER_C_VERSION_MAJOR_MINOR)
46             message(FATAL_ERROR "Gcc must be to version ${GCC_NEED_VERSION} current version ${COMPILER_C_VERSION_MAJOR_MINOR}")
47         endif(${GCC_NEED_VERSION} GREATER  COMPILER_C_VERSION_MAJOR_MINOR)
48 endif(GCC)
49
50 string(REGEX MATCH "cl.exe" VBC "${CMAKE_C_COMPILER}")
51 if(VBC)
52     message(FATAL_ERROR "VB is not yet supported by Simgrid.")
53 endif(VBC)
54
55 ### Find programs and paths
56 FIND_PROGRAM(GCOV_PATH gcov)
57 include(FindPerl)
58 if(NOT PERL_EXECUTABLE)
59         message(FATAL_ERROR "-- SimGrid cannot be compiled without Perl installed -- sorry. Bailling out.")
60 endif(NOT PERL_EXECUTABLE)
61
62 if(CMAKE_CACHE_MAJOR_VERSION EQUAL "2" AND CMAKE_CACHE_MINOR_VERSION GREATER "7") #need cmake version 2.8
63         get_filename_component(TRUE_CMAKE_HOME_DIRECTORY "${CMAKE_HOME_DIRECTORY}" REALPATH)
64         get_filename_component(TRUE_CMAKE_BINARY_DIR "${CMAKE_BINARY_DIR}" REALPATH)
65         if(${TRUE_CMAKE_HOME_DIRECTORY} STREQUAL ${CMAKE_HOME_DIRECTORY})
66         else(${TRUE_CMAKE_HOME_DIRECTORY} STREQUAL ${CMAKE_HOME_DIRECTORY})
67                 message(STATUS "Change link path '${CMAKE_HOME_DIRECTORY}' to true path '${TRUE_CMAKE_HOME_DIRECTORY}'")
68                 set(CMAKE_HOME_DIRECTORY "${TRUE_CMAKE_HOME_DIRECTORY}" CACHE TYPE INTERNAL FORCE)
69                 set(CMAKE_SOURCE_DIR "${TRUE_CMAKE_HOME_DIRECTORY}" CACHE TYPE INTERNAL FORCE)
70         endif(${TRUE_CMAKE_HOME_DIRECTORY} STREQUAL ${CMAKE_HOME_DIRECTORY})
71         
72         if(${TRUE_CMAKE_BINARY_DIR} STREQUAL ${CMAKE_BINARY_DIR})
73         else(${TRUE_CMAKE_BINARY_DIR} STREQUAL ${CMAKE_BINARY_DIR})
74                 message(STATUS "Change link path '${CMAKE_BINARY_DIR}' to true path '${TRUE_CMAKE_BINARY_DIR}'")
75                 set(CMAKE_BINARY_DIR "${TRUE_CMAKE_BINARY_DIR}" CACHE TYPE INTERNAL FORCE)
76         endif(${TRUE_CMAKE_BINARY_DIR} STREQUAL ${CMAKE_BINARY_DIR})    
77 endif(CMAKE_CACHE_MAJOR_VERSION EQUAL "2" AND CMAKE_CACHE_MINOR_VERSION GREATER "7")
78
79 ### Set some variables for Cmake
80 SET(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib)
81
82 if("${CMAKE_BINARY_DIR}" STREQUAL "${CMAKE_HOME_DIRECTORY}")
83         set(INCLUDES
84         ${CMAKE_HOME_DIRECTORY}
85         ${CMAKE_HOME_DIRECTORY}/include
86         ${CMAKE_HOME_DIRECTORY}/src
87         ${CMAKE_HOME_DIRECTORY}/src/include
88         )
89 else("${CMAKE_BINARY_DIR}" STREQUAL "${CMAKE_HOME_DIRECTORY}")
90         set(INCLUDES
91         ${CMAKE_HOME_DIRECTORY}
92         ${CMAKE_HOME_DIRECTORY}/include
93         ${CMAKE_HOME_DIRECTORY}/src
94         ${CMAKE_HOME_DIRECTORY}/src/include
95         ${CMAKE_BINARY_DIR}
96         ${CMAKE_BINARY_DIR}/include
97         ${CMAKE_BINARY_DIR}/src
98         )
99 endif("${CMAKE_BINARY_DIR}" STREQUAL "${CMAKE_HOME_DIRECTORY}")
100
101 set(INCLUDES ${INCLUDES} ${CMAKE_HOME_DIRECTORY} ${CMAKE_HOME_DIRECTORY}/include ${CMAKE_HOME_DIRECTORY}/src/include ${CMAKE_HOME_DIRECTORY}/src ${CMAKE_BINARY_DIR}/src)
102 if(WIN32)
103     set(INCLUDES ${INCLUDES} ${CMAKE_HOME_DIRECTORY}/include/xbt ${CMAKE_HOME_DIRECTORY}/src/xbt) #for win32_ucontext.[ch]
104 endif(WIN32)
105 set(CMAKE_SOURCE_DIR ${PROJECT_SOURCE_DIRECTORY})
106
107 if(NOT CMAKE_CROSSCOMPILING AND EXISTS /usr/include/)
108         set(INCLUDES ${INCLUDES} /usr/include/)
109 endif(NOT CMAKE_CROSSCOMPILING AND EXISTS /usr/include/)
110
111 ### Check 32bits or 64bits
112 INCLUDE (CheckTypeSize)
113 CHECK_TYPE_SIZE("long" SIZEOF_LONG)
114 IF(SIZEOF_LONG EQUAL 4)
115   SET(ARCH_32_BITS 1)
116 ELSE(SIZEOF_LONG EQUAL 4)
117   SET(ARCH_32_BITS 0)
118 ENDIF(SIZEOF_LONG EQUAL 4)
119
120 if(WIN32)
121
122     #Need env INCLUDE 
123     set(CMAKE_INCLUDE_WIN "${CMAKE_C_COMPILER}")
124     set(CMAKE_LIB_WIN "${CMAKE_C_COMPILER}")
125     string(REGEX REPLACE "/bin/gcc.*" "/include"  CMAKE_INCLUDE_WIN "${CMAKE_INCLUDE_WIN}")
126     string(REGEX REPLACE "/bin/gcc.*" "/lib"  CMAKE_LIB_WIN "${CMAKE_LIB_WIN}")
127     set(INCLUDES ${INCLUDES} ${CMAKE_INCLUDE_WIN})
128     
129     if(BORLAND)                 ### BORLAND COMPILER
130             set(__BORLANDC__ 1)
131             set(CMAKE_COMPILER_IS_GNUCC 0)
132             set(MSVC 0)
133             set(_XBT_BORLANDC_COMPILER 1)
134     endif(BORLAND)
135     
136     if(MSVC)    ### MicroSoftVisualC COMPILER
137             set(__VISUALC__ 1)
138             set(BORLAND 0)
139             set(CMAKE_COMPILER_IS_GNUCC 0)
140             set(_XBT_VISUALC_COMPILER 1)
141             set(_MSC_VER 1)
142         set(__STRICT_ANSI__ 1)
143         set(_M_IX86 1)
144     endif(MSVC)
145     
146     if(CMAKE_COMPILER_IS_GNUCC)
147         set(__GNUC__ 1)
148         exec_program("${CMAKE_C_COMPILER} --version" OUTPUT_VARIABLE "COMPILER_C_VERSION")
149         string(REGEX MATCH "[0-9].[0-9].[0-9]" COMPILER_C_VERSION "${COMPILER_C_VERSION}")
150         string(REGEX MATCH "^[0-9]" COMPILER_C_MAJOR_VERSION "${COMPILER_C_VERSION}")
151         string(REGEX MATCH "^[0-9].[0-9]" COMPILER_C_MINOR_VERSION "${COMPILER_C_VERSION}")
152         string(REGEX REPLACE "^${COMPILER_C_MAJOR_VERSION}." "" COMPILER_C_MINOR_VERSION "${COMPILER_C_MINOR_VERSION}")
153         if(COMPILER_C_MAJOR_VERSION)
154            # set(__GNUC__ ${COMPILER_C_MAJOR_VERSION})
155         endif(COMPILER_C_MAJOR_VERSION)
156         if(COMPILER_C_MINOR_VERSION)
157            # set(__GNUC_MINOR__ ${COMPILER_C_MINOR_VERSION})
158         endif(COMPILER_C_MINOR_VERSION)
159         set(MSVC 0)
160             set(BORLAND 0)
161     endif(CMAKE_COMPILER_IS_GNUCC)
162     
163     if(ARCH_32_BITS)    ### Arch 32bits
164         set(_WIN32 1)
165     else(ARCH_32_BITS)  ### Arch 64bits
166         set(_WIN64 1)
167     endif(ARCH_32_BITS)
168     
169     set(_XBT_WIN32 1)
170     
171     message(STATUS "C_COMPILER                  ${CMAKE_C_COMPILER} ${COMPILER_C_VERSION}")
172     message(STATUS "CXX_COMPILER                        ${CMAKE_CXX_COMPILER} ${COMPILER_CXX_VERSION}")
173     message(STATUS "CMAKE_RC_COMPILER           ${CMAKE_RC_COMPILER}")     
174     message(STATUS "INCLUDE                     ${CMAKE_INCLUDE_WIN}")
175     message(STATUS "LIB                         ${CMAKE_LIB_WIN}")
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 tests
221 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/AddTests.cmake)
222 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/CTestConfig.cmake)
223
224 ### Setup the distrib
225 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/Distrib.cmake)
226
227 ### Pipol compilation
228 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/Pipol.cmake)
229
230 if(NOT WIN32)
231 ### Build the doc
232 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/GenerateDoc.cmake)
233 endif(NOT WIN32)
234 ### Print ARGS
235 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/PrintArgs.cmake)
236
237 INCLUDE(Dart)