Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
cosmetics
[simgrid.git] / CMakeLists.txt
index a8ac91d..29e9a43 100644 (file)
@@ -11,18 +11,50 @@ set(libsmpi_version "${release_version}")
 ### Find programs and paths
 FIND_PROGRAM(GCOV_PATH gcov)
 FIND_PROGRAM(VALGRIND_PATH valgrind)
+include(FindPerl)
+if(NOT PERL_EXECUTABLE)
+       message(FATAL_ERROR "-- SimGrid cannot be compiled without Perl installed -- sorry. Bailling out.")
+endif(NOT PERL_EXECUTABLE)
 
-### SET THE PROJECT_DIRECTORY
-SET(PROJECT_DIRECTORY "${CMAKE_HOME_DIRECTORY}")
+
+### SET THE LIBRARY EXTENSION
+if(APPLE)
+       set(LIB_EXE "dylib")
+else(APPLE)
+       set(LIB_EXE "so")
+endif(APPLE)
 
 ### Set some variables for Cmake
-SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
-set(INCLUDES "-I${PROJECT_DIRECTORY} -I${PROJECT_DIRECTORY}/include -I${PROJECT_DIRECTORY}/src/include -I${PROJECT_DIRECTORY}/src -I${CMAKE_CURRENT_BINARY_DIR}/src/")
+SET(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib)
+
+if("${CMAKE_BINARY_DIR}" STREQUAL "${CMAKE_HOME_DIRECTORY}")
+       set(INCLUDES
+       ${CMAKE_HOME_DIRECTORY}
+       ${CMAKE_HOME_DIRECTORY}/include
+       ${CMAKE_HOME_DIRECTORY}/src
+       ${CMAKE_HOME_DIRECTORY}/src/include
+       )
+else("${CMAKE_BINARY_DIR}" STREQUAL "${CMAKE_HOME_DIRECTORY}")
+       set(INCLUDES
+       ${CMAKE_HOME_DIRECTORY}
+       ${CMAKE_HOME_DIRECTORY}/include
+       ${CMAKE_HOME_DIRECTORY}/src
+       ${CMAKE_HOME_DIRECTORY}/src/include
+       ${CMAKE_BINARY_DIR}
+       ${CMAKE_BINARY_DIR}/include
+       ${CMAKE_BINARY_DIR}/src
+       )
+endif("${CMAKE_BINARY_DIR}" STREQUAL "${CMAKE_HOME_DIRECTORY}")
+
+set(INCLUDES ${INCLUDES} ${CMAKE_HOME_DIRECTORY} ${CMAKE_HOME_DIRECTORY}/include ${CMAKE_HOME_DIRECTORY}/src/include ${CMAKE_HOME_DIRECTORY}/src ${CMAKE_CURRENT_BINARY_DIR}/src)
+if(WIN32)
+    set(INCLUDES ${INCLUDES} ${CMAKE_HOME_DIRECTORY}/include/xbt ${CMAKE_HOME_DIRECTORY}/src/xbt) #for win32_ucontext.[ch]
+endif(WIN32)
 set(CMAKE_SOURCE_DIR ${PROJECT_SOURCE_DIRECTORY})
 
-if(EXISTS /usr/include/)
-       set(INCLUDES "${INCLUDES} -I/usr/include/")
-endif(EXISTS /usr/include/)
+if(NOT CMAKE_CROSSCOMPILING AND EXISTS /usr/include/)
+       set(INCLUDES ${INCLUDES} /usr/include/)
+endif(NOT CMAKE_CROSSCOMPILING AND EXISTS /usr/include/)
 
 ### Check 32bits or 64bits
 INCLUDE (CheckTypeSize)
@@ -34,32 +66,34 @@ ELSE(SIZEOF_LONG EQUAL 4)
 ENDIF(SIZEOF_LONG EQUAL 4)
 
 if(WIN32)
+
        set(INCLUDES_MORE $ENV{INCLUDE})
        string(REPLACE "\\" "/" INCLUDES_MORE "${INCLUDES_MORE}")
        foreach(include_dir ${INCLUDES_MORE})
-               set(INCLUDES "${INCLUDES} -I\"${include_dir}\"")
+           if(IS_DIRECTORY ${include_dir})
+               string(REGEX MATCH ".*[ ].*" testoki "${include_dir}")
+               if(testoki)
+                       string(REPLACE " " "\\ " include_dir "${include_dir}")
+                   set(INCLUDES ${INCLUDES} \"${include_dir}\")
+               else(testoki)
+                   set(INCLUDES ${INCLUDES} ${include_dir})
+               endif(testoki)
+           else(IS_DIRECTORY ${include_dir})
+               message(FATAL_ERROR "${include_dir} not find")
+           endif(IS_DIRECTORY ${include_dir})
        endforeach(include_dir ${INCLUDES_MORE})
-       message("Be sure all those variables are correctely set.")
-    message("  -- C_COMPILER                   $ENV{CC}")
-    message("  -- CXX_COMPILER                 $ENV{CXX}")    
-    message("  -- RC_COMPILER                  $ENV{RC}")
-    message("  -- INCLUDE                      $ENV{INCLUDE}")
-    message("  -- LIB                          $ENV{LIB}")
-    message("  -- MAKE_PROGRAM                 ${CMAKE_MAKE_PROGRAM}")
-    message("  -- CMAKE_BUILD_TOOL             ${CMAKE_BUILD_TOOL}")
-    message("  -- LINKER                       ${CMAKE_LINKER}")
-    message("  -- CMAKE_GENERATOR              ${CMAKE_GENERATOR}")
-    message("  -- INCLUDES                     ${INCLUDES}")
-    message("  -- BORLAND                          ${BORLAND}")
-    message("  -- VISUALC                          ${MSVC}")
-    message("  -- GNUC                         ${CMAKE_COMPILER_IS_GNUCC}\n\n")
+
     if(BORLAND)                        ### BORLAND COMPILER
            set(__BORLANDC__ 1)
+           set(CMAKE_COMPILER_IS_GNUCC 0)
+           set(MSVC 0)
            set(_XBT_BORLANDC_COMPILER 1)
     endif(BORLAND)
     
     if(MSVC)   ### MicroSoftVisualC COMPILER
            set(__VISUALC__ 1)
+           set(BORLAND 0)
+           set(CMAKE_COMPILER_IS_GNUCC 0)
            set(_XBT_VISUALC_COMPILER 1)
            set(_MSC_VER 1)
         set(__STRICT_ANSI__ 1)
@@ -68,6 +102,19 @@ if(WIN32)
     
     if(CMAKE_COMPILER_IS_GNUCC)
         set(__GNUC__ 1)
+        exec_program("${CMAKE_C_COMPILER} --version" OUTPUT_VARIABLE "COMPILER_C_VERSION")
+        string(REGEX MATCH "[0-9].[0-9].[0-9]" COMPILER_C_VERSION "${COMPILER_C_VERSION}")
+        string(REGEX MATCH "^[0-9]" COMPILER_C_MAJOR_VERSION "${COMPILER_C_VERSION}")
+        string(REGEX MATCH "^[0-9].[0-9]" COMPILER_C_MINOR_VERSION "${COMPILER_C_VERSION}")
+        string(REGEX REPLACE "^${COMPILER_C_MAJOR_VERSION}." "" COMPILER_C_MINOR_VERSION "${COMPILER_C_MINOR_VERSION}")
+        if(COMPILER_C_MAJOR_VERSION)
+           # set(__GNUC__ ${COMPILER_C_MAJOR_VERSION})
+        endif(COMPILER_C_MAJOR_VERSION)
+        if(COMPILER_C_MINOR_VERSION)
+           # set(__GNUC_MINOR__ ${COMPILER_C_MINOR_VERSION})
+        endif(COMPILER_C_MINOR_VERSION)
+        set(MSVC 0)
+           set(BORLAND 0)
     endif(CMAKE_COMPILER_IS_GNUCC)
     
     if(ARCH_32_BITS)   ### Arch 32bits
@@ -77,62 +124,77 @@ if(WIN32)
     endif(ARCH_32_BITS)
     
     set(_XBT_WIN32 1)
+    
+    message("Be sure all those variables are correctely set.")
+    message("  -- C_COMPILER                   $ENV{CC}")
+    message("  -- CXX_COMPILER                 $ENV{CXX}")    
+    message("  -- INCLUDE                      $ENV{INCLUDE}")
+    message("  -- LIB                          $ENV{LIB}")
+    message("  -- MAKE_PROGRAM                 ${CMAKE_MAKE_PROGRAM}")
+    message("  -- CMAKE_BUILD_TOOL             ${CMAKE_BUILD_TOOL}")
+    message("  -- LINKER                       ${CMAKE_LINKER}")
+    message("  -- CMAKE_GENERATOR              ${CMAKE_GENERATOR}")
+    message("  -- INCLUDES                     ${INCLUDES}")
+    message("  -- BORLAND                      ${BORLAND}")
+    message("  -- VISUALC                      ${MSVC}")
+    message("  -- GNUC                         ${CMAKE_COMPILER_IS_GNUCC}\n\n")
+    
 endif(WIN32)
 
-add_definitions (${INCLUDES})
+include_directories(${INCLUDES})
+
+
+### Determine the assembly flavor that we need today
+include(CMakeDetermineSystem)
+set(PROCESSOR_${CMAKE_SYSTEM_PROCESSOR} 1)
 
 ### Setup Options
-include(${PROJECT_DIRECTORY}/buildtools/Cmake/Option.cmake)
+include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/Option.cmake)
 
 ### Make the *.h files with *.h.in files
-include(${PROJECT_DIRECTORY}/buildtools/Cmake/CompleteInFiles.cmake)
+include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/CompleteInFiles.cmake)
 
 ### Define source packages for Libs 
-include(${PROJECT_DIRECTORY}/buildtools/Cmake/DefinePackages.cmake)
+include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/DefinePackages.cmake)
 
 ### Build some Maintainer files
-include(${PROJECT_DIRECTORY}/buildtools/Cmake/MaintainerMode.cmake)
+include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/MaintainerMode.cmake)
+include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/UnitTesting.cmake)
 
 ### Setup gcc flags
-include(${PROJECT_DIRECTORY}/buildtools/Cmake/Flags.cmake)
+include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/Flags.cmake)
 
 ### Make Libs and Exes
 if(WIN32)
-    include(${PROJECT_DIRECTORY}/buildtools/Cmake/MakeExeLibWin.cmake)
+    include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/MakeExeLibWin.cmake)
 else(WIN32)
-    include(${PROJECT_DIRECTORY}/buildtools/Cmake/MakeExeLib.cmake)
+    include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/MakeExeLib.cmake)
 endif(WIN32)
 
-### Build the doc
-if(enable_doc)
-       ADD_CUSTOM_COMMAND(
-         OUTPUT ${PROJECT_DIRECTORY}/doc/html
-         DEPENDS       ${PROJECT_DIRECTORY}/doc/FAQ.doc 
-                               ${PROJECT_DIRECTORY}/buildtools/Cmake/GenerateDoc.cmake 
-                               ${PROJECT_DIRECTORY}/buildtools/Cmake/doc/CMakeLists.txt
-         COMMAND ${CMAKE_MAKE_PROGRAM} html
-         COMMENT "Generating the simgrid documentation..."
-       )
-       ADD_CUSTOM_TARGET(simgrid_documentation ALL
-                         DEPENDS ${PROJECT_DIRECTORY}/doc/html)
-endif(enable_doc)
-
 ### Make Simgrid.jar and Java examples
 if(HAVE_JAVA)
-       include(${PROJECT_DIRECTORY}/buildtools/Cmake/MakeJava.cmake)
+       include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/MakeJava.cmake)
 endif(HAVE_JAVA)
 
 ### Make tests
-include(${PROJECT_DIRECTORY}/buildtools/Cmake/AddTests.cmake)
-include(${PROJECT_DIRECTORY}/buildtools/Cmake/CTestConfig.cmake)
+if(NOT WIN32)
+include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/AddTests.cmake)
+else(NOT WIN32)
+include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/AddTestsWin.cmake)
+endif(NOT WIN32)
+
+include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/CTestConfig.cmake)
 
 ### Setup the distrib
-include(${PROJECT_DIRECTORY}/buildtools/Cmake/Distrib.cmake)
+include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/Distrib.cmake)
 
 ### Pipol compilation
-include(${PROJECT_DIRECTORY}/buildtools/Cmake/Pipol.cmake)
+include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/Pipol.cmake)
+
+### Build the doc
+include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/GenerateDoc.cmake)
 
 ### Print ARGS
-include(${PROJECT_DIRECTORY}/buildtools/Cmake/PrintArgs.cmake)
+include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/PrintArgs.cmake)
 
-INCLUDE(Dart)
\ No newline at end of file
+INCLUDE(Dart)