2016-11-03 08:06:33 -04:00
|
|
|
#
|
|
|
|
# Core setup
|
|
|
|
#
|
|
|
|
set(CMAKE_CXX_STANDARD 14)
|
|
|
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
|
|
set(CMAKE_CXX_EXTENSIONS OFF)
|
|
|
|
|
|
|
|
# Export compile commands used for custom targets
|
|
|
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
|
|
|
|
|
|
|
# Set default build type if not specified
|
|
|
|
if(NOT CMAKE_BUILD_TYPE)
|
|
|
|
message_colored(STATUS "No build type specified; using Release" 33)
|
|
|
|
set(CMAKE_BUILD_TYPE "Release")
|
|
|
|
endif()
|
|
|
|
|
2016-11-20 17:04:31 -05:00
|
|
|
# Compiler flags
|
2016-11-03 08:06:33 -04:00
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wextra")
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
|
2016-11-20 17:04:31 -05:00
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic")
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic-errors")
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ffunction-sections -fdata-sections")
|
2016-11-03 08:06:33 -04:00
|
|
|
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG")
|
|
|
|
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0")
|
|
|
|
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g2")
|
|
|
|
|
2016-11-20 17:04:31 -05:00
|
|
|
# Linker flags
|
|
|
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections")
|
|
|
|
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} -s")
|
2016-11-03 08:06:33 -04:00
|
|
|
|
2016-11-20 17:04:31 -05:00
|
|
|
# Check compiler
|
|
|
|
if(${CMAKE_CXX_COMPILER_ID} STREQUAL Clang)
|
2016-11-03 08:06:33 -04:00
|
|
|
message_colored(STATUS "Using supported compiler ${CMAKE_CXX_COMPILER_ID}" 32)
|
2016-11-20 17:04:31 -05:00
|
|
|
elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL GNU)
|
2016-11-03 08:06:33 -04:00
|
|
|
message_colored(STATUS "Using supported compiler ${CMAKE_CXX_COMPILER_ID}" 32)
|
|
|
|
else()
|
|
|
|
message_colored(WARNING "Using unsupported compiler ${CMAKE_CXX_COMPILER_ID} !" 31)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# Set compiler and linker flags for preferred C++ library
|
|
|
|
if(CXXLIB_CLANG)
|
|
|
|
message_colored(STATUS "Linking against libc++" 32)
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
|
|
|
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lc++ -lc++abi")
|
|
|
|
elseif(CXXLIB_GCC)
|
|
|
|
message_colored(STATUS "Linking against libstdc++" 32)
|
|
|
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lstdc++")
|
|
|
|
else()
|
|
|
|
message_colored(STATUS "No preferred c++lib specified... linking against system default" 33)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(ENABLE_CCACHE)
|
|
|
|
require_binary(ccache)
|
|
|
|
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ${BINPATH_ccache})
|
|
|
|
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ${BINPATH_ccache})
|
|
|
|
endif()
|
2016-11-30 12:22:10 -05:00
|
|
|
|
|
|
|
# Install paths
|
|
|
|
if(NOT DEFINED CMAKE_INSTALL_BINDIR)
|
|
|
|
set(CMAKE_INSTALL_BINDIR bin)
|
|
|
|
endif()
|
|
|
|
if(NOT DEFINED CMAKE_INSTALL_SBINDIR)
|
|
|
|
set(CMAKE_INSTALL_SBINDIR sbin)
|
|
|
|
endif()
|
|
|
|
if(NOT DEFINED CMAKE_INSTALL_LIBDIR)
|
|
|
|
set(CMAKE_INSTALL_LIBDIR lib)
|
|
|
|
endif()
|
|
|
|
if(NOT DEFINED CMAKE_INSTALL_INCLUDEDIR)
|
|
|
|
set(CMAKE_INSTALL_INCLUDEDIR include)
|
|
|
|
endif()
|