Skip to content

Commit

Permalink
build_system: move compiler flags definitions in their own cmake file
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasVautherin committed Feb 10, 2018
1 parent 704de34 commit fa87bac
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 49 deletions.
51 changes: 2 additions & 49 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,49 +8,7 @@ set(CMAKE_CXX_STANDARD 11)

project(dronecore)

if(MSVC)
add_definitions(-DWINDOWS)
set(warnings "-WX -W2")

# We need this so Windows links to e.g. dronecore_telemetry.dll.
# Without this option it will look for dronecore_telemetry.lib and fail.
option(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS "Export all symbols on Windows" ON)
else()
# We are not using exceptions to make it easier to write wrappers.
add_definitions(-fno-exceptions)

set(warnings "-Wall -Wextra -Werror -Wshadow -Wno-strict-aliasing -Wold-style-cast -Wdouble-promotion -Wformat=2")

if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 6)
set(warnings "${warnings} -Wduplicated-cond -Wnull-dereference")
endif()
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 7)
set(warnings "${warnings} -Wduplicated-branches")
endif()

if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 5)
set(warnings "${warnings} -Wno-missing-field-initializers")
endif()

set(warnings "${warnings} -Wuseless-cast -Wlogical-op")
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(warnings "${warnings} -Wno-missing-braces")
endif()
endif()

# We need a define if on APPLE
if(APPLE)
add_definitions("-DAPPLE")
endif()

# Add DEBUG define for Debug target
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG")

set(CMAKE_CXX_FLAGS_COVERAGE "${CMAKE_CXX_FLAGS_COVERAGE} --coverage")
set(CMAKE_EXE_LINKER_FLAGS_COVERAGE "${CMAKE_EXE_LINKER_FLAGS_COVERAGE} --coverage")
set(CMAKE_LINKER_FLAGS_COVERAGE "${CMAKE_LINKER_FLAGS_COVERAGE} --coverage")

include(cmake/compiler_flags.cmake)
include(cmake/zlib.cmake)
include(cmake/curl.cmake)

Expand All @@ -68,19 +26,14 @@ endif()
set(dronecore_install_include_dir "include/dronecore")
set(dronecore_install_lib_dir ${lib_path})

# Build the actual dronecore library.
add_subdirectory(core)

# Add default plugins.
add_subdirectory(plugins)

# Add external plugins.
if (DEFINED EXTERNAL_DIR AND NOT EXTERNAL_DIR STREQUAL "")
add_subdirectory(${EXTERNAL_DIR}/plugins
${CMAKE_CURRENT_BINARY_DIR}/${EXTERNAL_DIR}/plugins)
include_directories(
${EXTERNAL_DIR}
)
include_directories(${EXTERNAL_DIR})
endif()

if (CMAKE_BUILD_DRONECORESERVER)
Expand Down
42 changes: 42 additions & 0 deletions cmake/compiler_flags.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
if(MSVC)
add_definitions(-DWINDOWS)
set(warnings "-WX -W2")

# We need this so Windows links to e.g. dronecore_telemetry.dll.
# Without this option it will look for dronecore_telemetry.lib and fail.
option(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS "Export all symbols on Windows" ON)
else()
# We are not using exceptions to make it easier to write wrappers.
add_definitions(-fno-exceptions)

set(warnings "-Wall -Wextra -Werror -Wshadow -Wno-strict-aliasing -Wold-style-cast -Wdouble-promotion -Wformat=2")

if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 6)
set(warnings "${warnings} -Wduplicated-cond -Wnull-dereference")
endif()
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 7)
set(warnings "${warnings} -Wduplicated-branches")
endif()

if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 5)
set(warnings "${warnings} -Wno-missing-field-initializers")
endif()

set(warnings "${warnings} -Wuseless-cast -Wlogical-op")
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(warnings "${warnings} -Wno-missing-braces")
endif()
endif()

# We need a define if on APPLE
if(APPLE)
add_definitions("-DAPPLE")
endif()

# Add DEBUG define for Debug target
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG")

set(CMAKE_CXX_FLAGS_COVERAGE "${CMAKE_CXX_FLAGS_COVERAGE} --coverage")
set(CMAKE_EXE_LINKER_FLAGS_COVERAGE "${CMAKE_EXE_LINKER_FLAGS_COVERAGE} --coverage")
set(CMAKE_LINKER_FLAGS_COVERAGE "${CMAKE_LINKER_FLAGS_COVERAGE} --coverage")

0 comments on commit fa87bac

Please sign in to comment.