Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Use memcpy() instead of possibly broken aliasing through an union.
[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
8 set(CMAKE_C_FLAGS "" CACHE TYPE INTERNAL FORCE)
9 set(CMAKE_CXX_FLAGS "" CACHE TYPE INTERNAL FORCE)
10 set(CMAKE_EXE_LINKER_FLAGS "" CACHE TYPE INTERNAL FORCE)
11 set(CMAKE_C_LINK_FLAGS "" CACHE TYPE INTERNAL FORCE)
12
13 ## Mapping version number -> version name
14 # 3.5.99 -> alpha1 (oops)
15 # 3.5.9{1,2} -> beta{1,2}
16 # 3.5.9{3,4,5} -> rc{1,2,3}
17 # 3.6.{0,1,2} -> release 3.6, 3.6.1, 3.6.2
18 # 3.7.{0,1} -> release 3.7, 3.7.1
19 # 3.8.0 -> release 3.8
20
21 set(SIMGRID_VERSION_MAJOR "3")
22 set(SIMGRID_VERSION_MINOR "8")
23 set(SIMGRID_VERSION_PATCH "0")
24
25 if(${SIMGRID_VERSION_PATCH} EQUAL "0")
26   set(release_version "${SIMGRID_VERSION_MAJOR}.${SIMGRID_VERSION_MINOR}")
27 else(${SIMGRID_VERSION_PATCH} EQUAL "0")
28   set(release_version "${SIMGRID_VERSION_MAJOR}.${SIMGRID_VERSION_MINOR}.${SIMGRID_VERSION_PATCH}")
29 endif(${SIMGRID_VERSION_PATCH} EQUAL "0")
30 set(libsimgrid_version "${release_version}")
31 set(libgras_version "${release_version}")
32 set(libsmpi_version "${release_version}")
33 set(GCC_NEED_VERSION "4.0")
34 set(APPLE_NEED_GCC_VERSION "4.6")
35
36 ### SET THE LIBRARY EXTENSION AND GCC VERSION
37 if(APPLE) #MAC
38   set(LIB_EXE "dylib")
39 else(APPLE)
40   if(WIN32) #WINDOWS
41     set(LIB_EXE "a")
42     set(BIN_EXE ".exe")
43   else(WIN32) #UNIX
44     set(LIB_EXE "so")
45   endif(WIN32)
46 endif(APPLE)
47
48 string(REGEX MATCH "gcc" GCC "${CMAKE_C_COMPILER}")
49 if(GCC)
50   exec_program("${CMAKE_C_COMPILER} --version" OUTPUT_VARIABLE "COMPILER_C_VERSION")
51   exec_program("${CMAKE_CXX_COMPILER} --version" OUTPUT_VARIABLE "COMPILER_CXX_VERSION")
52   string(REGEX MATCH "[0-9].[0-9].[0-9]" COMPILER_C_VERSION "${COMPILER_C_VERSION}")
53   string(REGEX MATCH "[0-9].[0-9].[0-9]" COMPILER_CXX_VERSION "${COMPILER_CXX_VERSION}")
54
55   string(REGEX MATCH "^[0-9].[0-9]" COMPILER_C_VERSION_MAJOR_MINOR "${COMPILER_C_VERSION}")
56   string(REPLACE "${COMPILER_C_VERSION_MAJOR_MINOR}." "" COMPILER_C_VERSION_PATCH "${COMPILER_C_VERSION}")
57
58   if(${GCC_NEED_VERSION} GREATER  COMPILER_C_VERSION_MAJOR_MINOR)
59     message(FATAL_ERROR "Gcc must be to version ${GCC_NEED_VERSION} current version ${COMPILER_C_VERSION_MAJOR_MINOR}")
60   endif(${GCC_NEED_VERSION} GREATER  COMPILER_C_VERSION_MAJOR_MINOR)
61 endif(GCC)
62
63 string(REGEX MATCH "cl.exe" VBC "${CMAKE_C_COMPILER}")
64 if(VBC)
65   message(FATAL_ERROR "VB is not yet supported by Simgrid.")
66 endif(VBC)
67
68 ### Find programs and paths
69 FIND_PROGRAM(GCOV_PATH gcov)
70 include(FindPerl)
71 if(NOT PERL_EXECUTABLE)
72   message(FATAL_ERROR "-- SimGrid cannot be compiled without Perl installed -- sorry. Bailling out.")
73 endif(NOT PERL_EXECUTABLE)
74
75 if(CMAKE_CACHE_MAJOR_VERSION EQUAL "2" AND CMAKE_CACHE_MINOR_VERSION GREATER "7") #need cmake version 2.8
76   get_filename_component(TRUE_CMAKE_HOME_DIRECTORY "${CMAKE_HOME_DIRECTORY}" REALPATH)
77   get_filename_component(TRUE_CMAKE_BINARY_DIR "${CMAKE_BINARY_DIR}" REALPATH)
78   if(${TRUE_CMAKE_HOME_DIRECTORY} STREQUAL ${CMAKE_HOME_DIRECTORY})
79   else(${TRUE_CMAKE_HOME_DIRECTORY} STREQUAL ${CMAKE_HOME_DIRECTORY})
80     message(STATUS "Change link path '${CMAKE_HOME_DIRECTORY}' to true path '${TRUE_CMAKE_HOME_DIRECTORY}'")
81     set(CMAKE_HOME_DIRECTORY "${TRUE_CMAKE_HOME_DIRECTORY}" CACHE TYPE INTERNAL FORCE)
82     set(CMAKE_SOURCE_DIR "${TRUE_CMAKE_HOME_DIRECTORY}" CACHE TYPE INTERNAL FORCE)
83   endif(${TRUE_CMAKE_HOME_DIRECTORY} STREQUAL ${CMAKE_HOME_DIRECTORY})
84
85   if(${TRUE_CMAKE_BINARY_DIR} STREQUAL ${CMAKE_BINARY_DIR})
86   else(${TRUE_CMAKE_BINARY_DIR} STREQUAL ${CMAKE_BINARY_DIR})
87     message(STATUS "Change link path '${CMAKE_BINARY_DIR}' to true path '${TRUE_CMAKE_BINARY_DIR}'")
88     set(CMAKE_BINARY_DIR "${TRUE_CMAKE_BINARY_DIR}" CACHE TYPE INTERNAL FORCE)
89   endif(${TRUE_CMAKE_BINARY_DIR} STREQUAL ${CMAKE_BINARY_DIR})
90 endif(CMAKE_CACHE_MAJOR_VERSION EQUAL "2" AND CMAKE_CACHE_MINOR_VERSION GREATER "7")
91
92 ### Set some variables for Cmake
93 SET(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib)
94
95 if("${CMAKE_BINARY_DIR}" STREQUAL "${CMAKE_HOME_DIRECTORY}")
96   set(INCLUDES
97     ${CMAKE_HOME_DIRECTORY}
98     ${CMAKE_HOME_DIRECTORY}/include
99     ${CMAKE_HOME_DIRECTORY}/src
100     ${CMAKE_HOME_DIRECTORY}/src/include
101     )
102 else("${CMAKE_BINARY_DIR}" STREQUAL "${CMAKE_HOME_DIRECTORY}")
103   set(INCLUDES
104     ${CMAKE_HOME_DIRECTORY}
105     ${CMAKE_HOME_DIRECTORY}/include
106     ${CMAKE_HOME_DIRECTORY}/src
107     ${CMAKE_HOME_DIRECTORY}/src/include
108     ${CMAKE_BINARY_DIR}
109     ${CMAKE_BINARY_DIR}/include
110     ${CMAKE_BINARY_DIR}/src
111     )
112 endif("${CMAKE_BINARY_DIR}" STREQUAL "${CMAKE_HOME_DIRECTORY}")
113
114 set(INCLUDES ${INCLUDES} ${CMAKE_HOME_DIRECTORY} ${CMAKE_HOME_DIRECTORY}/include ${CMAKE_HOME_DIRECTORY}/src/include ${CMAKE_HOME_DIRECTORY}/src ${CMAKE_BINARY_DIR}/src)
115 if(WIN32)
116   set(INCLUDES ${INCLUDES} ${CMAKE_HOME_DIRECTORY}/include/xbt ${CMAKE_HOME_DIRECTORY}/src/xbt) #for win32_ucontext.[ch]
117 endif(WIN32)
118 set(CMAKE_SOURCE_DIR ${PROJECT_SOURCE_DIRECTORY})
119
120 if(NOT CMAKE_CROSSCOMPILING AND EXISTS /usr/include/)
121   set(INCLUDES ${INCLUDES} /usr/include/)
122 endif(NOT CMAKE_CROSSCOMPILING AND EXISTS /usr/include/)
123
124 ### Check 32bits or 64bits
125 INCLUDE (CheckTypeSize)
126 CHECK_TYPE_SIZE("void*" SIZEOF_VOIDSTAR)
127 IF(SIZEOF_VOIDSTAR EQUAL 4)
128   SET(ARCH_32_BITS 1)
129 ELSE(SIZEOF_VOIDSTAR EQUAL 4)
130   SET(ARCH_32_BITS 0)
131 ENDIF(SIZEOF_VOIDSTAR EQUAL 4)
132
133 if(WIN32)
134
135   #Need env INCLUDE
136   set(CMAKE_INCLUDE_WIN "${CMAKE_C_COMPILER}")
137   set(CMAKE_LIB_WIN "${CMAKE_C_COMPILER}")
138   string(REGEX REPLACE "/bin/gcc.*" "/include"  CMAKE_INCLUDE_WIN "${CMAKE_INCLUDE_WIN}")
139   string(REGEX REPLACE "/bin/gcc.*" "/lib"  CMAKE_LIB_WIN "${CMAKE_LIB_WIN}")
140   set(INCLUDES ${INCLUDES} ${CMAKE_INCLUDE_WIN})
141
142   if(CMAKE_COMPILER_IS_GNUCC)
143     set(__GNUC__ 1)
144     exec_program("${CMAKE_C_COMPILER} --version" OUTPUT_VARIABLE "COMPILER_C_VERSION")
145     string(REGEX MATCH "[0-9].[0-9].[0-9]" COMPILER_C_VERSION "${COMPILER_C_VERSION}")
146     string(REGEX MATCH "^[0-9]" COMPILER_C_MAJOR_VERSION "${COMPILER_C_VERSION}")
147     string(REGEX MATCH "^[0-9].[0-9]" COMPILER_C_MINOR_VERSION "${COMPILER_C_VERSION}")
148     string(REGEX REPLACE "^${COMPILER_C_MAJOR_VERSION}." "" COMPILER_C_MINOR_VERSION "${COMPILER_C_MINOR_VERSION}")
149     if(COMPILER_C_MAJOR_VERSION)
150       # set(__GNUC__ ${COMPILER_C_MAJOR_VERSION})
151     endif(COMPILER_C_MAJOR_VERSION)
152     if(COMPILER_C_MINOR_VERSION)
153       # set(__GNUC_MINOR__ ${COMPILER_C_MINOR_VERSION})
154     endif(COMPILER_C_MINOR_VERSION)
155     set(MSVC 0)
156     set(BORLAND 0)
157   else(CMAKE_COMPILER_IS_GNUCC)
158     message(FATAL_ERROR "Please use MinGW to compile SimGrid!")
159   endif(CMAKE_COMPILER_IS_GNUCC)
160
161   if(ARCH_32_BITS)      ### Arch 32bits
162     set(_WIN32 1)
163   else(ARCH_32_BITS)    ### Arch 64bits
164     set(_WIN64 1)
165   endif(ARCH_32_BITS)
166
167   set(NSIS_WIN_VERSION $ENV{PROCESSOR_ARCHITEW6432})
168   if(NSIS_WIN_VERSION MATCHES "")
169     set(NSIS_WIN_VERSION $ENV{PROCESSOR_ARCHITECTURE})
170   endif(NSIS_WIN_VERSION MATCHES "")
171   string(TOLOWER ${NSIS_WIN_VERSION} NSIS_WIN_VERSION)
172
173   set(_XBT_WIN32 1)
174
175   message(STATUS "C_COMPILER                    ${CMAKE_C_COMPILER} ${COMPILER_C_VERSION}")
176   message(STATUS "CXX_COMPILER                  ${CMAKE_CXX_COMPILER} ${COMPILER_CXX_VERSION}")
177   message(STATUS "CMAKE_RC_COMPILER             ${CMAKE_RC_COMPILER}")
178   message(STATUS "INCLUDE                       ${CMAKE_INCLUDE_WIN}")
179   message(STATUS "LIB                           ${CMAKE_LIB_WIN}")
180   message(STATUS "MAKE_PROGRAM                  ${CMAKE_MAKE_PROGRAM}")
181   message(STATUS "CMAKE_BUILD_TOOL              ${CMAKE_BUILD_TOOL}")
182   message(STATUS "LINKER                        ${CMAKE_LINKER}")
183   message(STATUS "CMAKE_GENERATOR               ${CMAKE_GENERATOR}")
184   message(STATUS "BORLAND                       ${BORLAND}")
185   message(STATUS "VISUALC                       ${MSVC}")
186   message(STATUS "GNUC                          ${CMAKE_COMPILER_IS_GNUCC}")
187
188 endif(WIN32)
189
190 include_directories(${INCLUDES})
191
192 ### Determine the assembly flavor that we need today
193 include(CMakeDetermineSystem)
194 set(PROCESSOR_${CMAKE_SYSTEM_PROCESSOR} 1)
195
196 ### Setup Options
197 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/Option.cmake)
198
199 ### Make the *.h files with *.h.in files
200 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/CompleteInFiles.cmake)
201
202 ### Define source packages for Libs
203 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/DefinePackages.cmake)
204
205 ### Build some Maintainer files
206 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/MaintainerMode.cmake)
207 if(NOT WIN32)
208   include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/UnitTesting.cmake)
209 endif(NOT WIN32)
210
211 ### Setup gcc flags
212 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/Flags.cmake)
213
214 ### Make Libs
215 if(NOT WIN32)
216   include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/MakeLib.cmake)
217 else(NOT WIN32)
218   include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/MakeLibWin.cmake)
219 endif(NOT WIN32)
220
221 ### Make Exes
222 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/MakeExe.cmake)
223
224 ### Make tests
225 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/AddTests.cmake)
226 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/CTestConfig.cmake)
227
228 ### Setup the distrib
229 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/Distrib.cmake)
230
231 ### Pipol compilation
232 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/Pipol.cmake)
233
234 ### Build the doc
235 if(NOT WIN32)
236   include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/GenerateDoc.cmake)
237 else(NOT WIN32)
238   include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/GenerateDocWin.cmake)
239 endif(NOT WIN32)
240
241 ### Print ARGS
242 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/PrintArgs.cmake)
243
244 INCLUDE(Dart)