Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add missing functions with windows
[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 FIND_PROGRAM(VALGRIND_PATH valgrind)
55 include(FindPerl)
56 if(NOT PERL_EXECUTABLE)
57         message(FATAL_ERROR "-- SimGrid cannot be compiled without Perl installed -- sorry. Bailling out.")
58 endif(NOT PERL_EXECUTABLE)
59
60 if(CMAKE_CACHE_MAJOR_VERSION EQUAL "2" AND CMAKE_CACHE_MINOR_VERSION GREATER "7") #need cmake version 2.8
61         get_filename_component(TRUE_CMAKE_HOME_DIRECTORY "${CMAKE_HOME_DIRECTORY}" REALPATH)
62         get_filename_component(TRUE_CMAKE_BINARY_DIR "${CMAKE_BINARY_DIR}" REALPATH)
63         if(${TRUE_CMAKE_HOME_DIRECTORY} STREQUAL ${CMAKE_HOME_DIRECTORY})
64         else(${TRUE_CMAKE_HOME_DIRECTORY} STREQUAL ${CMAKE_HOME_DIRECTORY})
65                 message(STATUS "Change link path '${CMAKE_HOME_DIRECTORY}' to true path '${TRUE_CMAKE_HOME_DIRECTORY}'")
66                 set(CMAKE_HOME_DIRECTORY "${TRUE_CMAKE_HOME_DIRECTORY}" CACHE TYPE INTERNAL FORCE)
67                 set(CMAKE_SOURCE_DIR "${TRUE_CMAKE_HOME_DIRECTORY}" CACHE TYPE INTERNAL FORCE)
68         endif(${TRUE_CMAKE_HOME_DIRECTORY} STREQUAL ${CMAKE_HOME_DIRECTORY})
69         
70         if(${TRUE_CMAKE_BINARY_DIR} STREQUAL ${CMAKE_BINARY_DIR})
71         else(${TRUE_CMAKE_BINARY_DIR} STREQUAL ${CMAKE_BINARY_DIR})
72                 message(STATUS "Change link path '${CMAKE_BINARY_DIR}' to true path '${TRUE_CMAKE_BINARY_DIR}'")
73                 set(CMAKE_BINARY_DIR "${TRUE_CMAKE_BINARY_DIR}" CACHE TYPE INTERNAL FORCE)
74         endif(${TRUE_CMAKE_BINARY_DIR} STREQUAL ${CMAKE_BINARY_DIR})    
75 endif(CMAKE_CACHE_MAJOR_VERSION EQUAL "2" AND CMAKE_CACHE_MINOR_VERSION GREATER "7")
76
77 ### Set some variables for Cmake
78 SET(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib)
79
80 if("${CMAKE_BINARY_DIR}" STREQUAL "${CMAKE_HOME_DIRECTORY}")
81         set(INCLUDES
82         ${CMAKE_HOME_DIRECTORY}
83         ${CMAKE_HOME_DIRECTORY}/include
84         ${CMAKE_HOME_DIRECTORY}/src
85         ${CMAKE_HOME_DIRECTORY}/src/include
86         )
87 else("${CMAKE_BINARY_DIR}" STREQUAL "${CMAKE_HOME_DIRECTORY}")
88         set(INCLUDES
89         ${CMAKE_HOME_DIRECTORY}
90         ${CMAKE_HOME_DIRECTORY}/include
91         ${CMAKE_HOME_DIRECTORY}/src
92         ${CMAKE_HOME_DIRECTORY}/src/include
93         ${CMAKE_BINARY_DIR}
94         ${CMAKE_BINARY_DIR}/include
95         ${CMAKE_BINARY_DIR}/src
96         )
97 endif("${CMAKE_BINARY_DIR}" STREQUAL "${CMAKE_HOME_DIRECTORY}")
98
99 set(INCLUDES ${INCLUDES} ${CMAKE_HOME_DIRECTORY} ${CMAKE_HOME_DIRECTORY}/include ${CMAKE_HOME_DIRECTORY}/src/include ${CMAKE_HOME_DIRECTORY}/src ${CMAKE_BINARY_DIR}/src)
100 if(WIN32)
101     set(INCLUDES ${INCLUDES} ${CMAKE_HOME_DIRECTORY}/include/xbt ${CMAKE_HOME_DIRECTORY}/src/xbt) #for win32_ucontext.[ch]
102 endif(WIN32)
103 set(CMAKE_SOURCE_DIR ${PROJECT_SOURCE_DIRECTORY})
104
105 if(NOT CMAKE_CROSSCOMPILING AND EXISTS /usr/include/)
106         set(INCLUDES ${INCLUDES} /usr/include/)
107 endif(NOT CMAKE_CROSSCOMPILING AND EXISTS /usr/include/)
108
109 ### Check 32bits or 64bits
110 INCLUDE (CheckTypeSize)
111 CHECK_TYPE_SIZE("long" SIZEOF_LONG)
112 IF(SIZEOF_LONG EQUAL 4)
113   SET(ARCH_32_BITS 1)
114 ELSE(SIZEOF_LONG EQUAL 4)
115   SET(ARCH_32_BITS 0)
116 ENDIF(SIZEOF_LONG EQUAL 4)
117
118 if(WIN32)
119
120     #Need env INCLUDE 
121     set(CMAKE_INCLUDE_WIN "${CMAKE_C_COMPILER}")
122     set(CMAKE_LIB_WIN "${CMAKE_C_COMPILER}")
123     string(REGEX REPLACE "/bin/gcc.*" "/include"  CMAKE_INCLUDE_WIN "${CMAKE_INCLUDE_WIN}")
124     string(REGEX REPLACE "/bin/gcc.*" "/lib"  CMAKE_LIB_WIN "${CMAKE_LIB_WIN}")
125     set(INCLUDES ${INCLUDES} ${CMAKE_INCLUDE_WIN})
126     
127     if(BORLAND)                 ### BORLAND COMPILER
128             set(__BORLANDC__ 1)
129             set(CMAKE_COMPILER_IS_GNUCC 0)
130             set(MSVC 0)
131             set(_XBT_BORLANDC_COMPILER 1)
132     endif(BORLAND)
133     
134     if(MSVC)    ### MicroSoftVisualC COMPILER
135             set(__VISUALC__ 1)
136             set(BORLAND 0)
137             set(CMAKE_COMPILER_IS_GNUCC 0)
138             set(_XBT_VISUALC_COMPILER 1)
139             set(_MSC_VER 1)
140         set(__STRICT_ANSI__ 1)
141         set(_M_IX86 1)
142     endif(MSVC)
143     
144     if(CMAKE_COMPILER_IS_GNUCC)
145         set(__GNUC__ 1)
146         exec_program("${CMAKE_C_COMPILER} --version" OUTPUT_VARIABLE "COMPILER_C_VERSION")
147         string(REGEX MATCH "[0-9].[0-9].[0-9]" COMPILER_C_VERSION "${COMPILER_C_VERSION}")
148         string(REGEX MATCH "^[0-9]" COMPILER_C_MAJOR_VERSION "${COMPILER_C_VERSION}")
149         string(REGEX MATCH "^[0-9].[0-9]" COMPILER_C_MINOR_VERSION "${COMPILER_C_VERSION}")
150         string(REGEX REPLACE "^${COMPILER_C_MAJOR_VERSION}." "" COMPILER_C_MINOR_VERSION "${COMPILER_C_MINOR_VERSION}")
151         if(COMPILER_C_MAJOR_VERSION)
152            # set(__GNUC__ ${COMPILER_C_MAJOR_VERSION})
153         endif(COMPILER_C_MAJOR_VERSION)
154         if(COMPILER_C_MINOR_VERSION)
155            # set(__GNUC_MINOR__ ${COMPILER_C_MINOR_VERSION})
156         endif(COMPILER_C_MINOR_VERSION)
157         set(MSVC 0)
158             set(BORLAND 0)
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(_XBT_WIN32 1)
168     
169     message(STATUS "C_COMPILER                  ${CMAKE_C_COMPILER} ${COMPILER_C_VERSION}")
170     message(STATUS "CXX_COMPILER                        ${CMAKE_CXX_COMPILER} ${COMPILER_CXX_VERSION}")
171     message(STATUS "CMAKE_RC_COMPILER           ${CMAKE_RC_COMPILER}")     
172     message(STATUS "INCLUDE                     ${CMAKE_INCLUDE_WIN}")
173     message(STATUS "LIB                         ${CMAKE_LIB_WIN}")
174     message(STATUS "MAKE_PROGRAM                        ${CMAKE_MAKE_PROGRAM}")
175     message(STATUS "CMAKE_BUILD_TOOL            ${CMAKE_BUILD_TOOL}")
176     message(STATUS "LINKER                      ${CMAKE_LINKER}")
177     message(STATUS "CMAKE_GENERATOR             ${CMAKE_GENERATOR}")
178     message(STATUS "BORLAND                     ${BORLAND}")
179     message(STATUS "VISUALC                     ${MSVC}")
180     message(STATUS "GNUC                                ${CMAKE_COMPILER_IS_GNUCC}")
181    
182 endif(WIN32)
183
184 include_directories(${INCLUDES})
185
186 ### Determine the assembly flavor that we need today
187 include(CMakeDetermineSystem)
188 set(PROCESSOR_${CMAKE_SYSTEM_PROCESSOR} 1)
189
190 ### Setup Options
191 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/Option.cmake)
192
193 ### Make the *.h files with *.h.in files
194 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/CompleteInFiles.cmake)
195
196 ### Define source packages for Libs 
197 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/DefinePackages.cmake)
198
199 ### Build some Maintainer files
200 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/MaintainerMode.cmake)
201 if(NOT WIN32)
202 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/UnitTesting.cmake)
203 endif(NOT WIN32)
204
205 ### Setup gcc flags
206 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/Flags.cmake)
207
208 ### Make Libs
209 if(NOT WIN32)
210 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/MakeLib.cmake)
211 else(NOT WIN32)
212 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/MakeLibWin.cmake)
213 endif(NOT WIN32)
214
215 ### Make Exes
216 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/MakeExe.cmake)
217
218 ### Make Simgrid.jar and Java examples
219 if(HAVE_JAVA)
220         include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/MakeJava.cmake)
221 endif(HAVE_JAVA)
222
223 ### Make tests
224 if(NOT WIN32)
225 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/AddTests.cmake)
226 else(NOT WIN32)
227
228 endif(NOT WIN32)
229
230 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/CTestConfig.cmake)
231
232 ### Setup the distrib
233 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/Distrib.cmake)
234
235 ### Pipol compilation
236 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/Pipol.cmake)
237
238 if(NOT WIN32)
239 ### Build the doc
240 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/GenerateDoc.cmake)
241 endif(NOT WIN32)
242 ### Print ARGS
243 include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/PrintArgs.cmake)
244
245 INCLUDE(Dart)