Logo AND Algorithmique Numérique Distribuée

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