Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Need one more byte for the terminating \0.
[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()
6 project(SimGrid C)
7 if (enable_gtnets OR enable_ns3)
8   enable_language(CXX)
9 endif()
10 if (NOT DEFINED enable_smpi OR enable_smpi) # smpi is enabled by default
11   # Call enable_language(Fortran) in order to load the build rules for
12   # this language, needed by teshsuite/smpi/mpich-test/.  Use
13   # CMAKE_FORCE_Fortran_COMPILER to bypass checks for a working
14   # compiler (smpiff don't exist at configure time).
15   include(CMakeForceCompiler)
16   if(NOT COMMAND CMAKE_FORCE_Fortran_COMPILER)
17     MACRO(CMAKE_FORCE_Fortran_COMPILER compiler id)
18       SET(CMAKE_Fortran_COMPILER "${compiler}")
19       SET(CMAKE_Fortran_COMPILER_ID_RUN TRUE)
20       SET(CMAKE_Fortran_COMPILER_ID ${id})
21       SET(CMAKE_Fortran_COMPILER_WORKS TRUE)
22       SET(CMAKE_Fortran_COMPILER_FORCED TRUE)
23
24       # Set old compiler id variables.
25       IF("${CMAKE_Fortran_COMPILER_ID}" MATCHES "GNU")
26         SET(CMAKE_COMPILER_IS_GNUG77 1)
27       ENDIF("${CMAKE_Fortran_COMPILER_ID}" MATCHES "GNU")
28     ENDMACRO(CMAKE_FORCE_Fortran_COMPILER)
29   endif()
30   CMAKE_FORCE_Fortran_COMPILER(smpiff smpiff)
31   enable_language(Fortran OPTIONAL)
32 endif()
33
34 set(CMAKE_C_FLAGS "" CACHE TYPE INTERNAL FORCE)
35 set(CMAKE_CXX_FLAGS "" CACHE TYPE INTERNAL FORCE)
36 set(CMAKE_EXE_LINKER_FLAGS "" CACHE TYPE INTERNAL FORCE)
37 set(CMAKE_C_LINK_FLAGS "" CACHE TYPE INTERNAL FORCE)
38 set(CMAKE_Fortran_FLAGS "" CACHE TYPE INTERNAL FORCE)
39 set(CMAKE_Fortran_LINK_FLAGS "" CACHE TYPE INTERNAL FORCE)
40 ## Mapping version number -> version name
41 # 3.5.99 -> alpha1 (oops)
42 # 3.5.9{1,2} -> beta{1,2}
43 # 3.5.9{3,4,5} -> rc{1,2,3}
44 # 3.6.{0,1,2} -> release 3.6, 3.6.1, 3.6.2
45 # 3.7.{0,1} -> release 3.7, 3.7.1
46 # 3.8.{0,1} -> release 3.8, 3.8.1
47 # 3.9.0 -> release 3.9
48 # 3.10.0 -> release 3.10
49
50 set(SIMGRID_VERSION_MAJOR "3")
51 set(SIMGRID_VERSION_MINOR "10")
52 set(SIMGRID_VERSION_PATCH "0")
53
54 if(${SIMGRID_VERSION_PATCH} EQUAL "0")
55   set(release_version "${SIMGRID_VERSION_MAJOR}.${SIMGRID_VERSION_MINOR}")
56 else()
57   set(release_version "${SIMGRID_VERSION_MAJOR}.${SIMGRID_VERSION_MINOR}.${SIMGRID_VERSION_PATCH}")
58 endif()
59 set(libsimgrid_version "${release_version}")
60 set(libsmpi_version "${release_version}")
61 set(libSG_java_version "${release_version}")
62 set(GCC_NEED_VERSION "4.0")
63 set(APPLE_NEED_GCC_VERSION "4.6")
64
65 ### SET THE LIBRARY EXTENSION AND GCC VERSION
66 if(APPLE) #MAC
67   set(LIB_EXE "dylib")
68 else()
69   if(WIN32) #WINDOWS
70     set(LIB_EXE "a")
71     set(BIN_EXE ".exe")
72   else() #UNIX
73     set(LIB_EXE "so")
74   endif()
75 endif()
76
77 if(${CMAKE_C_COMPILER_ID} STREQUAL "GNU")
78   exec_program("${CMAKE_C_COMPILER} --version" OUTPUT_VARIABLE "COMPILER_C_VERSION")
79   exec_program("${CMAKE_CXX_COMPILER} --version" OUTPUT_VARIABLE "COMPILER_CXX_VERSION")
80   string(REGEX MATCH "[0-9].[0-9].[0-9]" COMPILER_C_VERSION "${COMPILER_C_VERSION}")
81   string(REGEX MATCH "[0-9].[0-9].[0-9]" COMPILER_CXX_VERSION "${COMPILER_CXX_VERSION}")
82
83   string(REGEX MATCH "^[0-9].[0-9]" COMPILER_C_VERSION_MAJOR_MINOR "${COMPILER_C_VERSION}")
84   string(REPLACE "${COMPILER_C_VERSION_MAJOR_MINOR}." "" COMPILER_C_VERSION_PATCH "${COMPILER_C_VERSION}")
85
86   if(${GCC_NEED_VERSION} GREATER  COMPILER_C_VERSION_MAJOR_MINOR)
87     message(FATAL_ERROR "Gcc must be to version ${GCC_NEED_VERSION} current version ${COMPILER_C_VERSION_MAJOR_MINOR}")
88   endif()
89 endif()
90
91 string(REGEX MATCH "cl.exe" VBC "${CMAKE_C_COMPILER}")
92 if(VBC)
93   message(FATAL_ERROR "VB is not yet supported by Simgrid.")
94 endif()
95
96 ### Find programs and paths
97 FIND_PROGRAM(GCOV_PATH gcov)
98 include(FindPerl)
99 if(NOT PERL_EXECUTABLE)
100   message(FATAL_ERROR "-- SimGrid cannot be compiled without Perl installed -- sorry. Bailling out.")
101 endif()
102
103 ### Set some variables for Cmake
104 SET(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib)
105
106 set(INCLUDES
107   ${CMAKE_HOME_DIRECTORY}
108   ${CMAKE_HOME_DIRECTORY}/include
109   ${CMAKE_HOME_DIRECTORY}/src
110   ${CMAKE_HOME_DIRECTORY}/src/include
111   ${CMAKE_BINARY_DIR}
112   ${CMAKE_BINARY_DIR}/include
113   ${CMAKE_BINARY_DIR}/src
114   )
115
116 if(WIN32)
117   set(INCLUDES ${INCLUDES} ${CMAKE_HOME_DIRECTORY}/include/xbt ${CMAKE_HOME_DIRECTORY}/src/xbt) #for win32_ucontext.[ch]
118 endif()
119 set(CMAKE_SOURCE_DIR ${PROJECT_SOURCE_DIRECTORY})
120
121 if(NOT CMAKE_CROSSCOMPILING AND EXISTS /usr/include/)
122   set(INCLUDES ${INCLUDES} /usr/include/)
123 endif()
124
125 ### Check 32bits or 64bits
126 INCLUDE (CheckTypeSize)
127 CHECK_TYPE_SIZE("void*" SIZEOF_VOIDSTAR)
128 IF(SIZEOF_VOIDSTAR EQUAL 4)
129   SET(ARCH_32_BITS 1)
130 ELSE()
131   SET(ARCH_32_BITS 0)
132 ENDIF()
133
134 if(WIN32)
135
136   #Need env INCLUDE
137   set(CMAKE_INCLUDE_WIN "${CMAKE_C_COMPILER}")
138   set(CMAKE_LIB_WIN "${CMAKE_C_COMPILER}")
139   string(REGEX REPLACE "/bin/gcc.*" "/include"  CMAKE_INCLUDE_WIN "${CMAKE_INCLUDE_WIN}")
140   string(REGEX REPLACE "/bin/gcc.*" "/lib"  CMAKE_LIB_WIN "${CMAKE_LIB_WIN}")
141   set(INCLUDES ${INCLUDES} ${CMAKE_INCLUDE_WIN})
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()
153     if(COMPILER_C_MINOR_VERSION)
154       # set(__GNUC_MINOR__ ${COMPILER_C_MINOR_VERSION})
155     endif()
156     set(MSVC 0)
157     set(BORLAND 0)
158   else()
159     message(FATAL_ERROR "Please use MinGW to compile SimGrid!")
160   endif()
161
162   if(ARCH_32_BITS)      ### Arch 32bits
163     set(_WIN32 1)
164   else()        ### Arch 64bits
165     set(_WIN64 1)
166   endif()
167
168   set(NSIS_WIN_VERSION $ENV{PROCESSOR_ARCHITEW6432})
169   if(NSIS_WIN_VERSION MATCHES "")
170     set(NSIS_WIN_VERSION $ENV{PROCESSOR_ARCHITECTURE})
171   endif()
172   string(TOLOWER ${NSIS_WIN_VERSION} NSIS_WIN_VERSION)
173
174   set(_XBT_WIN32 1)
175
176   message(STATUS "C_COMPILER                    ${CMAKE_C_COMPILER} ${COMPILER_C_VERSION}")
177   message(STATUS "CXX_COMPILER                  ${CMAKE_CXX_COMPILER} ${COMPILER_CXX_VERSION}")
178   message(STATUS "CMAKE_RC_COMPILER             ${CMAKE_RC_COMPILER}")
179   message(STATUS "INCLUDE                       ${CMAKE_INCLUDE_WIN}")
180   message(STATUS "LIB                           ${CMAKE_LIB_WIN}")
181   message(STATUS "MAKE_PROGRAM                  ${CMAKE_MAKE_PROGRAM}")
182   message(STATUS "CMAKE_BUILD_TOOL              ${CMAKE_BUILD_TOOL}")
183   message(STATUS "LINKER                        ${CMAKE_LINKER}")
184   message(STATUS "CMAKE_GENERATOR               ${CMAKE_GENERATOR}")
185   message(STATUS "BORLAND                       ${BORLAND}")
186   message(STATUS "VISUALC                       ${MSVC}")
187   message(STATUS "GNUC                          ${CMAKE_COMPILER_IS_GNUCC}")
188
189 endif()
190
191 include_directories(${INCLUDES})
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()
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()
215   include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/MakeLibWin.cmake)
216 endif()
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 ### Build the doc
232 if(NOT WIN32)
233   include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/GenerateDoc.cmake)
234 else()
235   include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/GenerateDocWin.cmake)
236 endif()
237
238 ### Print ARGS
239 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/PrintArgs.cmake)
240
241 INCLUDE(Dart)