Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
e4aa9ec6cc827d69e9c10a168b98422cbf264743
[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 # 3.5.93 -> rc1
15 # 3.5.94 -> rc2
16 set(SIMGRID_VERSION_MAJOR "3")
17 set(SIMGRID_VERSION_MINOR "5")
18 set(SIMGRID_VERSION_PATCH "94")
19 set(release_version "${SIMGRID_VERSION_MAJOR}.${SIMGRID_VERSION_MINOR}")
20 set(libsimgrid_version "${release_version}")
21 set(libgras_version "${release_version}")
22 set(libsmpi_version "${release_version}")
23 set(GCC_NEED_VERSION "4.0")
24
25 ### SET THE LIBRARY EXTENSION AND GCC VERSION
26 if(APPLE) #MAC
27         set(LIB_EXE "dylib")
28 else(APPLE)
29     if(WIN32) #WINDOWS
30         set(LIB_EXE "a")
31     else(WIN32) #UNIX
32             set(LIB_EXE "so")
33     endif(WIN32)
34 endif(APPLE)
35
36 string(REGEX MATCH "gcc" GCC "${CMAKE_C_COMPILER}")
37 if(GCC)
38         exec_program("${CMAKE_C_COMPILER} --version" OUTPUT_VARIABLE "COMPILER_C_VERSION")
39         exec_program("${CMAKE_CXX_COMPILER} --version" OUTPUT_VARIABLE "COMPILER_CXX_VERSION")
40         string(REGEX MATCH "[0-9].[0-9].[0-9]" COMPILER_C_VERSION "${COMPILER_C_VERSION}")
41         string(REGEX MATCH "[0-9].[0-9].[0-9]" COMPILER_CXX_VERSION "${COMPILER_CXX_VERSION}")
42         
43         string(REGEX MATCH "^[0-9].[0-9]" COMPILER_C_VERSION_MAJOR_MINOR "${COMPILER_C_VERSION}")
44         string(REPLACE "${COMPILER_C_VERSION_MAJOR_MINOR}." "" COMPILER_C_VERSION_PATCH "${COMPILER_C_VERSION}")
45         
46         if(${GCC_NEED_VERSION} GREATER  COMPILER_C_VERSION_MAJOR_MINOR)
47             message(FATAL_ERROR "Gcc must be to version ${GCC_NEED_VERSION} current version ${COMPILER_C_VERSION_MAJOR_MINOR}")
48         endif(${GCC_NEED_VERSION} GREATER  COMPILER_C_VERSION_MAJOR_MINOR)
49 endif(GCC)
50
51 string(REGEX MATCH "cl.exe" VBC "${CMAKE_C_COMPILER}")
52 if(VBC)
53     message(FATAL_ERROR "VB is not yet supported by Simgrid.")
54 endif(VBC)
55
56 ### Find programs and paths
57 FIND_PROGRAM(GCOV_PATH gcov)
58 include(FindPerl)
59 if(NOT PERL_EXECUTABLE)
60         message(FATAL_ERROR "-- SimGrid cannot be compiled without Perl installed -- sorry. Bailling out.")
61 endif(NOT PERL_EXECUTABLE)
62
63 if(CMAKE_CACHE_MAJOR_VERSION EQUAL "2" AND CMAKE_CACHE_MINOR_VERSION GREATER "7") #need cmake version 2.8
64         get_filename_component(TRUE_CMAKE_HOME_DIRECTORY "${CMAKE_HOME_DIRECTORY}" REALPATH)
65         get_filename_component(TRUE_CMAKE_BINARY_DIR "${CMAKE_BINARY_DIR}" REALPATH)
66         if(${TRUE_CMAKE_HOME_DIRECTORY} STREQUAL ${CMAKE_HOME_DIRECTORY})
67         else(${TRUE_CMAKE_HOME_DIRECTORY} STREQUAL ${CMAKE_HOME_DIRECTORY})
68                 message(STATUS "Change link path '${CMAKE_HOME_DIRECTORY}' to true path '${TRUE_CMAKE_HOME_DIRECTORY}'")
69                 set(CMAKE_HOME_DIRECTORY "${TRUE_CMAKE_HOME_DIRECTORY}" CACHE TYPE INTERNAL FORCE)
70                 set(CMAKE_SOURCE_DIR "${TRUE_CMAKE_HOME_DIRECTORY}" CACHE TYPE INTERNAL FORCE)
71         endif(${TRUE_CMAKE_HOME_DIRECTORY} STREQUAL ${CMAKE_HOME_DIRECTORY})
72         
73         if(${TRUE_CMAKE_BINARY_DIR} STREQUAL ${CMAKE_BINARY_DIR})
74         else(${TRUE_CMAKE_BINARY_DIR} STREQUAL ${CMAKE_BINARY_DIR})
75                 message(STATUS "Change link path '${CMAKE_BINARY_DIR}' to true path '${TRUE_CMAKE_BINARY_DIR}'")
76                 set(CMAKE_BINARY_DIR "${TRUE_CMAKE_BINARY_DIR}" CACHE TYPE INTERNAL FORCE)
77         endif(${TRUE_CMAKE_BINARY_DIR} STREQUAL ${CMAKE_BINARY_DIR})    
78 endif(CMAKE_CACHE_MAJOR_VERSION EQUAL "2" AND CMAKE_CACHE_MINOR_VERSION GREATER "7")
79
80 ### Set some variables for Cmake
81 SET(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib)
82
83 if("${CMAKE_BINARY_DIR}" STREQUAL "${CMAKE_HOME_DIRECTORY}")
84         set(INCLUDES
85         ${CMAKE_HOME_DIRECTORY}
86         ${CMAKE_HOME_DIRECTORY}/include
87         ${CMAKE_HOME_DIRECTORY}/src
88         ${CMAKE_HOME_DIRECTORY}/src/include
89         )
90 else("${CMAKE_BINARY_DIR}" STREQUAL "${CMAKE_HOME_DIRECTORY}")
91         set(INCLUDES
92         ${CMAKE_HOME_DIRECTORY}
93         ${CMAKE_HOME_DIRECTORY}/include
94         ${CMAKE_HOME_DIRECTORY}/src
95         ${CMAKE_HOME_DIRECTORY}/src/include
96         ${CMAKE_BINARY_DIR}
97         ${CMAKE_BINARY_DIR}/include
98         ${CMAKE_BINARY_DIR}/src
99         )
100 endif("${CMAKE_BINARY_DIR}" STREQUAL "${CMAKE_HOME_DIRECTORY}")
101
102 set(INCLUDES ${INCLUDES} ${CMAKE_HOME_DIRECTORY} ${CMAKE_HOME_DIRECTORY}/include ${CMAKE_HOME_DIRECTORY}/src/include ${CMAKE_HOME_DIRECTORY}/src ${CMAKE_BINARY_DIR}/src)
103 if(WIN32)
104     set(INCLUDES ${INCLUDES} ${CMAKE_HOME_DIRECTORY}/include/xbt ${CMAKE_HOME_DIRECTORY}/src/xbt) #for win32_ucontext.[ch]
105 endif(WIN32)
106 set(CMAKE_SOURCE_DIR ${PROJECT_SOURCE_DIRECTORY})
107
108 if(NOT CMAKE_CROSSCOMPILING AND EXISTS /usr/include/)
109         set(INCLUDES ${INCLUDES} /usr/include/)
110 endif(NOT CMAKE_CROSSCOMPILING AND EXISTS /usr/include/)
111
112 ### Check 32bits or 64bits
113 INCLUDE (CheckTypeSize)
114 CHECK_TYPE_SIZE("long" SIZEOF_LONG)
115 IF(SIZEOF_LONG EQUAL 4)
116   SET(ARCH_32_BITS 1)
117 ELSE(SIZEOF_LONG EQUAL 4)
118   SET(ARCH_32_BITS 0)
119 ENDIF(SIZEOF_LONG EQUAL 4)
120
121 if(WIN32)
122
123     #Need env INCLUDE 
124     set(CMAKE_INCLUDE_WIN "${CMAKE_C_COMPILER}")
125     set(CMAKE_LIB_WIN "${CMAKE_C_COMPILER}")
126     string(REGEX REPLACE "/bin/gcc.*" "/include"  CMAKE_INCLUDE_WIN "${CMAKE_INCLUDE_WIN}")
127     string(REGEX REPLACE "/bin/gcc.*" "/lib"  CMAKE_LIB_WIN "${CMAKE_LIB_WIN}")
128     set(INCLUDES ${INCLUDES} ${CMAKE_INCLUDE_WIN})
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                  ${CMAKE_C_COMPILER} ${COMPILER_C_VERSION}")
173     message(STATUS "CXX_COMPILER                        ${CMAKE_CXX_COMPILER} ${COMPILER_CXX_VERSION}")
174     message(STATUS "CMAKE_RC_COMPILER           ${CMAKE_RC_COMPILER}")     
175     message(STATUS "INCLUDE                     ${CMAKE_INCLUDE_WIN}")
176     message(STATUS "LIB                         ${CMAKE_LIB_WIN}")
177     message(STATUS "MAKE_PROGRAM                        ${CMAKE_MAKE_PROGRAM}")
178     message(STATUS "CMAKE_BUILD_TOOL            ${CMAKE_BUILD_TOOL}")
179     message(STATUS "LINKER                      ${CMAKE_LINKER}")
180     message(STATUS "CMAKE_GENERATOR             ${CMAKE_GENERATOR}")
181     message(STATUS "BORLAND                     ${BORLAND}")
182     message(STATUS "VISUALC                     ${MSVC}")
183     message(STATUS "GNUC                                ${CMAKE_COMPILER_IS_GNUCC}")
184    
185 endif(WIN32)
186
187 include_directories(${INCLUDES})
188
189 ### Determine the assembly flavor that we need today
190 include(CMakeDetermineSystem)
191 set(PROCESSOR_${CMAKE_SYSTEM_PROCESSOR} 1)
192
193 ### Setup Options
194 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/Option.cmake)
195
196 ### Make the *.h files with *.h.in files
197 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/CompleteInFiles.cmake)
198
199 ### Define source packages for Libs 
200 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/DefinePackages.cmake)
201
202 ### Build some Maintainer files
203 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/MaintainerMode.cmake)
204 if(NOT WIN32)
205 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/UnitTesting.cmake)
206 endif(NOT WIN32)
207
208 ### Setup gcc flags
209 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/Flags.cmake)
210
211 ### Make Libs
212 if(NOT WIN32)
213 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/MakeLib.cmake)
214 else(NOT WIN32)
215 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/MakeLibWin.cmake)
216 endif(NOT WIN32)
217
218 ### Make Exes
219 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/MakeExe.cmake)
220
221 ### Make tests
222 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/AddTests.cmake)
223 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/CTestConfig.cmake)
224
225 ### Setup the distrib
226 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/Distrib.cmake)
227
228 ### Pipol compilation
229 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/Pipol.cmake)
230
231 if(NOT WIN32)
232 ### Build the doc
233 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/GenerateDoc.cmake)
234 endif(NOT WIN32)
235 ### Print ARGS
236 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/PrintArgs.cmake)
237
238 INCLUDE(Dart)