Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
292f43d9f0fe3fa69ba1f8646467a69aaa8d6792
[simgrid.git] / CMakeLists.txt
1 cmake_minimum_required(VERSION 2.6)
2 project(simgrid CXX C)
3 set(CMAKE_C_FLAGS "" CACHE TYPE INTERNAL FORCE)
4 set(CMAKE_CXX_FLAGS "" CACHE TYPE INTERNAL FORCE)
5 set(CMAKE_EXE_LINKER_FLAGS "" CACHE TYPE INTERNAL FORCE)
6 set(release_version "3.5")
7 set(libsimgrid_version "${release_version}")
8 set(libgras_version "${release_version}")
9 set(libsmpi_version "${release_version}")
10
11 ### Find programs and paths
12 FIND_PROGRAM(GCOV_PATH gcov)
13 FIND_PROGRAM(VALGRIND_PATH valgrind)
14
15 ### SET THE PROJECT_DIRECTORY
16 SET(PROJECT_DIRECTORY "${CMAKE_HOME_DIRECTORY}")
17
18 ### SET THE LIBRARY EXTENSION
19 if(APPLE)
20         set(LIB_EXE "dylib")
21 else(APPLE)
22         set(LIB_EXE "so")
23 endif(APPLE)
24
25 ### Set some variables for Cmake
26 SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
27 set(INCLUDES ${PROJECT_BINARY_DIR} ${PROJECT_BINARY_DIR}/include ${PROJECT_BINARY_DIR}/src/include ${PROJECT_BINARY_DIR}/src)
28 set(INCLUDES ${INCLUDES} ${PROJECT_DIRECTORY} ${PROJECT_DIRECTORY}/include ${PROJECT_DIRECTORY}/src/include ${PROJECT_DIRECTORY}/src ${CMAKE_CURRENT_BINARY_DIR}/src)
29 if(WIN32)
30     set(INCLUDES ${INCLUDES} ${PROJECT_DIRECTORY}/include/xbt ${PROJECT_DIRECTORY}/src/xbt) #for win32_ucontext.[ch]
31 endif(WIN32)
32 set(CMAKE_SOURCE_DIR ${PROJECT_SOURCE_DIRECTORY})
33
34 if(NOT CMAKE_CROSSCOMPILING AND EXISTS /usr/include/)
35         set(INCLUDES ${INCLUDES} /usr/include/)
36 endif(NOT CMAKE_CROSSCOMPILING AND EXISTS /usr/include/)
37
38 ### Check 32bits or 64bits
39 INCLUDE (CheckTypeSize)
40 CHECK_TYPE_SIZE("long" SIZEOF_LONG)
41 IF(SIZEOF_LONG EQUAL 4)
42   SET(ARCH_32_BITS 1)
43 ELSE(SIZEOF_LONG EQUAL 4)
44   SET(ARCH_32_BITS 0)
45 ENDIF(SIZEOF_LONG EQUAL 4)
46
47 if(WIN32)
48
49         set(INCLUDES_MORE $ENV{INCLUDE})
50         string(REPLACE "\\" "/" INCLUDES_MORE "${INCLUDES_MORE}")
51         foreach(include_dir ${INCLUDES_MORE})
52             if(IS_DIRECTORY ${include_dir})
53                 string(REGEX MATCH ".*[ ].*" testoki "${include_dir}")
54                 if(testoki)
55                         string(REPLACE " " "\\ " include_dir "${include_dir}")
56                     set(INCLUDES ${INCLUDES} \"${include_dir}\")
57                 else(testoki)
58                     set(INCLUDES ${INCLUDES} ${include_dir})
59                 endif(testoki)
60             else(IS_DIRECTORY ${include_dir})
61                 message(FATAL_ERROR "${include_dir} not find")
62             endif(IS_DIRECTORY ${include_dir})
63         endforeach(include_dir ${INCLUDES_MORE})
64
65     if(BORLAND)                 ### BORLAND COMPILER
66             set(__BORLANDC__ 1)
67             set(CMAKE_COMPILER_IS_GNUCC 0)
68             set(MSVC 0)
69             set(_XBT_BORLANDC_COMPILER 1)
70     endif(BORLAND)
71     
72     if(MSVC)    ### MicroSoftVisualC COMPILER
73             set(__VISUALC__ 1)
74             set(BORLAND 0)
75             set(CMAKE_COMPILER_IS_GNUCC 0)
76             set(_XBT_VISUALC_COMPILER 1)
77             set(_MSC_VER 1)
78         set(__STRICT_ANSI__ 1)
79         set(_M_IX86 1)
80     endif(MSVC)
81     
82     if(CMAKE_COMPILER_IS_GNUCC)
83         set(__GNUC__ 1)
84         exec_program("${CMAKE_C_COMPILER} --version" OUTPUT_VARIABLE "COMPILER_C_VERSION")
85         string(REGEX MATCH "[0-9].[0-9].[0-9]" COMPILER_C_VERSION "${COMPILER_C_VERSION}")
86         string(REGEX MATCH "^[0-9]" COMPILER_C_MAJOR_VERSION "${COMPILER_C_VERSION}")
87         string(REGEX MATCH "^[0-9].[0-9]" COMPILER_C_MINOR_VERSION "${COMPILER_C_VERSION}")
88         string(REGEX REPLACE "^${COMPILER_C_MAJOR_VERSION}." "" COMPILER_C_MINOR_VERSION "${COMPILER_C_MINOR_VERSION}")
89         if(COMPILER_C_MAJOR_VERSION)
90            # set(__GNUC__ ${COMPILER_C_MAJOR_VERSION})
91         endif(COMPILER_C_MAJOR_VERSION)
92         if(COMPILER_C_MINOR_VERSION)
93            # set(__GNUC_MINOR__ ${COMPILER_C_MINOR_VERSION})
94         endif(COMPILER_C_MINOR_VERSION)
95         set(MSVC 0)
96             set(BORLAND 0)
97     endif(CMAKE_COMPILER_IS_GNUCC)
98     
99     if(ARCH_32_BITS)    ### Arch 32bits
100         set(_WIN32 1)
101     else(ARCH_32_BITS)  ### Arch 64bits
102         set(_WIN64 1)
103     endif(ARCH_32_BITS)
104     
105     set(_XBT_WIN32 1)
106     
107     message("Be sure all those variables are correctely set.")
108     message("   -- C_COMPILER                   $ENV{CC}")
109     message("   -- CXX_COMPILER                 $ENV{CXX}")    
110     message("   -- INCLUDE                      $ENV{INCLUDE}")
111     message("   -- LIB                          $ENV{LIB}")
112     message("   -- MAKE_PROGRAM                 ${CMAKE_MAKE_PROGRAM}")
113     message("   -- CMAKE_BUILD_TOOL             ${CMAKE_BUILD_TOOL}")
114     message("   -- LINKER                       ${CMAKE_LINKER}")
115     message("   -- CMAKE_GENERATOR              ${CMAKE_GENERATOR}")
116     message("   -- INCLUDES                     ${INCLUDES}")
117     message("   -- BORLAND                      ${BORLAND}")
118     message("   -- VISUALC                      ${MSVC}")
119     message("   -- GNUC                         ${CMAKE_COMPILER_IS_GNUCC}\n\n")
120     
121 endif(WIN32)
122
123 include_directories(${INCLUDES})
124
125 ### Setup Options
126 include(${PROJECT_DIRECTORY}/buildtools/Cmake/Option.cmake)
127
128 ### Make the *.h files with *.h.in files
129 include(${PROJECT_DIRECTORY}/buildtools/Cmake/CompleteInFiles.cmake)
130
131 ### Define source packages for Libs 
132 include(${PROJECT_DIRECTORY}/buildtools/Cmake/DefinePackages.cmake)
133
134 ### Build some Maintainer files
135 include(${PROJECT_DIRECTORY}/buildtools/Cmake/MaintainerMode.cmake)
136
137 ### Setup gcc flags
138 include(${PROJECT_DIRECTORY}/buildtools/Cmake/Flags.cmake)
139
140 ### Make Libs and Exes
141 if(WIN32)
142     include(${PROJECT_DIRECTORY}/buildtools/Cmake/MakeExeLibWin.cmake)
143 else(WIN32)
144     include(${PROJECT_DIRECTORY}/buildtools/Cmake/MakeExeLib.cmake)
145 endif(WIN32)
146
147 ### Build the doc
148 if(enable_doc)
149         ADD_CUSTOM_COMMAND(
150           OUTPUT ${PROJECT_DIRECTORY}/doc/html
151           DEPENDS       ${PROJECT_DIRECTORY}/doc/FAQ.doc 
152                                 ${PROJECT_DIRECTORY}/buildtools/Cmake/GenerateDoc.cmake 
153                                 ${PROJECT_DIRECTORY}/buildtools/Cmake/doc/CMakeLists.txt
154           COMMAND ${CMAKE_MAKE_PROGRAM} html
155           COMMENT "Generating the simgrid documentation..."
156         )
157         ADD_CUSTOM_TARGET(simgrid_documentation ALL
158                           DEPENDS ${PROJECT_DIRECTORY}/doc/html)
159 endif(enable_doc)
160
161 ### Make Simgrid.jar and Java examples
162 if(HAVE_JAVA)
163         include(${PROJECT_DIRECTORY}/buildtools/Cmake/MakeJava.cmake)
164 endif(HAVE_JAVA)
165
166 ### Make tests
167 if(NOT WIN32)
168 include(${PROJECT_DIRECTORY}/buildtools/Cmake/AddTests.cmake)
169 else(NOT WIN32)
170 include(${PROJECT_DIRECTORY}/buildtools/Cmake/AddTestsWin.cmake)
171 endif(NOT WIN32)
172
173 include(${PROJECT_DIRECTORY}/buildtools/Cmake/CTestConfig.cmake)
174
175 ### Setup the distrib
176 include(${PROJECT_DIRECTORY}/buildtools/Cmake/Distrib.cmake)
177
178 ### Pipol compilation
179 include(${PROJECT_DIRECTORY}/buildtools/Cmake/Pipol.cmake)
180
181 ### Print ARGS
182 include(${PROJECT_DIRECTORY}/buildtools/Cmake/PrintArgs.cmake)
183
184 INCLUDE(Dart)