CMakeLists.txt 3.73 KB
Newer Older
Millian Poquet's avatar
Millian Poquet committed
1
cmake_minimum_required(VERSION 2.8.11)
Olivier Richard's avatar
Olivier Richard committed
2

3
4
project("Batsim")

Millian Poquet's avatar
Millian Poquet committed
5
6
7
8
9
# Options
option(enable_warnings "Enable compilation warnings" ON)
option(treat_warnings_as_errors "Treat compilation warnings as compilation errors" OFF)
option(enable_optimizations "Enable compilation-level optimizations" 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
10

Millian Poquet's avatar
Millian Poquet committed
11
12
13
################
# Dependencies #
################
14
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
15

16
17
18
## SimGrid dependency
find_package(SimGrid REQUIRED)
include_directories(${SIMGRID_INCLUDE_DIR})
Millian Poquet's avatar
Millian Poquet committed
19

20
21
22
23
24
25
26
27
## Boost dependency
find_package(Boost REQUIRED COMPONENTS system filesystem)
include_directories(${Boost_INCLUDE_DIR})

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

Millian Poquet's avatar
Millian Poquet committed
28
29
30
################
# Source files #
################
31
32
33
file(GLOB batsim_SRC
    "src/*.hpp"
    "src/*.cpp")
34
35

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

38
# Libraries to link
Millian Poquet's avatar
Millian Poquet committed
39
40
target_link_libraries(batsim ${SIMGRID_LIBRARIES} ${Boost_SYSTEM_LIBRARY_DEBUG}
                      ${Boost_FILESYSTEM_LIBRARY_DEBUG})
Michael Mercier's avatar
Michael Mercier committed
41

Millian Poquet's avatar
Millian Poquet committed
42
43
44
45
46
################
# Installation #
################
install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/batsim
        DESTINATION bin)
47

Millian Poquet's avatar
Millian Poquet committed
48
49
50
##################
# Compiler flags #
##################
51

Millian Poquet's avatar
Millian Poquet committed
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# Let's check that compiler versions are ok with c++11
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()
    set_property(TARGET batsim APPEND_STRING PROPERTY COMPILE_FLAGS "-std=c++11")
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()
    set_property(TARGET batsim APPEND_STRING PROPERTY COMPILE_FLAGS "-std=c++11")
67
else()
Millian Poquet's avatar
Millian Poquet committed
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
    message(WARNING "Unknown compiler. C++11 should not be enabled correctly.")
    set_property(TARGET batsim APPEND_STRING PROPERTY COMPILE_FLAGS "-std=c++11")
endif()

# Let's enable warnings if needed
if (enable_warnings)
    set(my_flags " -Wall -Wextra")

    if (treat_warnings_as_errors)
        set(my_flags "${my_flags} -Werror")
    endif()

    if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
        set_property(TARGET batsim APPEND_STRING PROPERTY COMPILE_FLAGS ${my_flags})
    elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
        set_property(TARGET batsim APPEND_STRING PROPERTY COMPILE_FLAGS ${my_flags})
    else()
        message(WARNING "Unknown compiler. Warnings should not be enabled correctly.")
        set_property(TARGET batsim APPEND_STRING PROPERTY COMPILE_FLAGS ${my_flags})
    endif()
endif()

# Let's enable optimization if needed
if (enable_optimizations)
    set(optim_flags " -O2")

    if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
        set_property(TARGET batsim APPEND_STRING PROPERTY COMPILE_FLAGS ${optim_flags})
    elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
        set_property(TARGET batsim APPEND_STRING PROPERTY COMPILE_FLAGS ${optim_flags})
    else()
        message(WARNING "Unknown compiler. Warnings should not be enabled correctly.")
        set_property(TARGET batsim APPEND_STRING PROPERTY COMPILE_FLAGS ${optim_flags})
    endif()
endif()

if (ignore_assertions)
    target_compile_definitions(batsim PRIVATE NDEBUG)
106
endif()