Logo AND Algorithmique Numérique Distribuée

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