CMakeLists.txt 3.88 KB
Newer Older
1
2
# Let's use at least v3.1 for sanity's sake.
cmake_minimum_required(VERSION 3.1)
Olivier Richard's avatar
Olivier Richard committed
3

4
5
project("Batsim")

6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# Enable C++11
# Let's check that the used compiler handles c++11 correctly
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
    if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.8.1")
        message(FATAL_ERROR "Insufficient gcc version: 4.8.1 is needed to support C++11")
    elseif(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "5")
        message(WARNING "Old gcc version found: Using version 5 or greater is recommended")
    endif()
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
    if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "3.3")
        message(FATAL_ERROR "Insufficient clang version: 3.3 is needed to support C++11")
    elseif(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "3.4")
        message(WARNING "Old clang version found: Using version 3.4 or greater is recommended")
    endif()
else()
    message(WARNING "Unknown compiler. Make sure it fully supports C++11.")
endif()

# Let's enable C++11
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

Millian Poquet's avatar
Millian Poquet committed
28
29
30
31
# Options
option(enable_warnings "Enable compilation warnings" ON)
option(treat_warnings_as_errors "Treat compilation warnings as compilation errors" OFF)
option(ignore_assertions "Ignore assertions, which could make the simulation unstable, but could improve its performance" OFF)
Olivier Richard's avatar
Olivier Richard committed
32

33
34
35
36
37
38
39
40
41
42
# Build type
# Set a default build type if none was specified
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
  message(STATUS "Setting build type to 'Debug' as none was specified.")
  set(CMAKE_BUILD_TYPE Debug CACHE STRING "Choose the type of build." FORCE)
  # Set the possible values of build type for cmake-gui
  set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release"
    "MinSizeRel" "RelWithDebInfo")
endif()

Millian Poquet's avatar
Millian Poquet committed
43
44
45
################
# Dependencies #
################
46
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
47

48
49
50
## SimGrid dependency
find_package(SimGrid REQUIRED)
include_directories(${SIMGRID_INCLUDE_DIR})
Millian Poquet's avatar
Millian Poquet committed
51

52
## Boost dependency
53
find_package(Boost 1.48 REQUIRED COMPONENTS system filesystem)
54
55
56
57
58
59
include_directories(${Boost_INCLUDE_DIR})

## Rapidjson dependency
find_package(rapidjson REQUIRED)
include_directories(${RAPIDJSON_INCLUDE_DIRS})

60
61
62
63
64
65
66
67
68
69
70
## Redox dependency
find_package(redox REQUIRED)
include_directories(${REDOX_INCLUDE_DIR})

## Redox sub dependencies
find_package(hiredis REQUIRED)
include_directories(${HIREDIS_INCLUDE_DIRS})

find_package(libev REQUIRED)
include_directories(${LIBEV_INCLUDE_DIRS})

Millian Poquet's avatar
Millian Poquet committed
71
72
73
################
# Source files #
################
74
75
76
file(GLOB batsim_SRC
    "src/*.hpp"
    "src/*.cpp")
77
78

# Executables
79
add_executable(batsim ${batsim_SRC})
Olivier Richard's avatar
Olivier Richard committed
80

81
# Libraries to link
82
83
84
85
86
87
target_link_libraries(batsim ${SIMGRID_LIBRARIES}
                      ${Boost_SYSTEM_LIBRARY_DEBUG}
                      ${Boost_FILESYSTEM_LIBRARY_DEBUG}
                      ${REDOX_LIBRARY}
                      ${LIBEV_LIBRARY}
                      ${HIREDIS_LIBRARY})
Michael Mercier's avatar
Michael Mercier committed
88

Millian Poquet's avatar
Millian Poquet committed
89
90
91
92
93
################
# Installation #
################
install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/batsim
        DESTINATION bin)
94

Millian Poquet's avatar
Millian Poquet committed
95
96
# Let's enable warnings if needed
if (enable_warnings)
97
    set(warning_flags " -Wall -Wextra")
Millian Poquet's avatar
Millian Poquet committed
98
99

    if (treat_warnings_as_errors)
100
        set(warning_flags "${warning_flags} -Werror")
Millian Poquet's avatar
Millian Poquet committed
101
102
103
    endif()

    if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
104
        set_property(TARGET batsim APPEND_STRING PROPERTY COMPILE_FLAGS ${warning_flags})
Millian Poquet's avatar
Millian Poquet committed
105
    elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
106
        set_property(TARGET batsim APPEND_STRING PROPERTY COMPILE_FLAGS ${warning_flags})
Millian Poquet's avatar
Millian Poquet committed
107
108
    else()
        message(WARNING "Unknown compiler. Warnings should not be enabled correctly.")
109
        set_property(TARGET batsim APPEND_STRING PROPERTY COMPILE_FLAGS ${warning_flags})
Millian Poquet's avatar
Millian Poquet committed
110
111
112
    endif()
endif()

113
# Let's ignore assertions if needed (might improve performance but can be dangerous)
Millian Poquet's avatar
Millian Poquet committed
114
115
if (ignore_assertions)
    target_compile_definitions(batsim PRIVATE NDEBUG)
116
endif()