Commit aaa0be85 authored by Millian Poquet's avatar Millian Poquet
Browse files

CMakeLists update

Options have been added to:
  - enable warnings
  - treat warnings as errors
  - enable compile-time optimizations
  - disable run-time assertions

gcc/clang versions are checked to ensure they support c++11.
The C++11 flag is set manually to limit CMake version need.
The CMake version needed is now 2.8.11 (target_compile_definitions).
parent 80674359
cmake_minimum_required(VERSION 2.8)
#cmake_minimum_required(VERSION 3.0.2)
cmake_minimum_required(VERSION 2.8.11)
project("Batsim")
# C++ standard
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# 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)
# Dependencies
################
# Dependencies #
################
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
## SimGrid dependency
......@@ -22,31 +25,82 @@ include_directories(${Boost_INCLUDE_DIR})
find_package(rapidjson REQUIRED)
include_directories(${RAPIDJSON_INCLUDE_DIRS})
# Finding source files
################
# Source files #
################
file(GLOB batsim_SRC
"src/*.hpp"
"src/*.cpp")
# Executables
add_executable(batsim ${batsim_SRC})
#add_executable(batexec batexec.c job.c utils.c export.c)
# Libraries to link
target_link_libraries(batsim ${SIMGRID_LIBRARIES} ${Boost_SYSTEM_LIBRARY_DEBUG} ${Boost_FILESYSTEM_LIBRARY_DEBUG})
#target_link_libraries(batexec simgrid jansson m)
target_link_libraries(batsim ${SIMGRID_LIBRARIES} ${Boost_SYSTEM_LIBRARY_DEBUG}
${Boost_FILESYSTEM_LIBRARY_DEBUG})
################
# Installation #
################
install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/batsim
DESTINATION bin)
# Installation
INSTALL(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/batsim
#${CMAKE_CURRENT_BINARY_DIR}/batexec
DESTINATION bin)
##################
# Compiler flags #
##################
# Extra compiler flags
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set_property(TARGET batsim APPEND_STRING PROPERTY COMPILE_FLAGS "-Wall -Wextra")
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
set_property(TARGET batsim APPEND_STRING PROPERTY COMPILE_FLAGS "-Wall -Wextra")
# 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")
else()
message("Compiler is unknown, warnings will NOT be added to it")
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)
endif()
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment