Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
abdes committed Nov 28, 2022
2 parents 47cc579 + 432cdaf commit a4085fb
Show file tree
Hide file tree
Showing 8 changed files with 194 additions and 64 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

### [4.6.1](http://github.com/abdes/asap/compare/v4.6.0...v4.6.1) (2022-09-20)
## [4.6.1](http://github.com/abdes/asap/compare/v4.6.0...v4.6.1) (2022-09-20)

### Bug Fixes

Expand Down
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ endif()
# project hierarchy
include(LogHelpers)

# Setup our override file, in which we may cleanup cmake's default compiler
# options, based on what we are doing.
set(CMAKE_USER_MAKE_RULES_OVERRIDE "ResetInitialCompilerOptions")

# ------------------------------------------------------------------------------
# Project description and (meta) information
# ------------------------------------------------------------------------------
Expand Down
73 changes: 49 additions & 24 deletions cmake/AsapTargets.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,32 @@ endfunction()
# Target creation helpers
# ------------------------------------------------------------------------------

macro(_add_common_compiler_options target warnings)
# Set some common compiler options, and forward the 'WARNING' option if it was
# provided
if(warnings)
asap_set_compile_options(${target} WARNING)
else()
asap_set_compile_options(${target})
endif()
endmacro()

function(asap_add_library target)
swift_add_library("${target}" ${ARGN})
set(argOption EXCEPTIONS RTTI WARNING)
set(argSingle CONTRACTS)
set(argMulti)

cmake_parse_arguments(x "${argOption}" "${argSingle}" "${argMulti}" ${ARGN})

if(x_WARNING)
set(warning_flag "WARNING")
else()
set(warning_flag)
endif()

# Contrarily to swift default, we enable exceptions and RTTI for all targets
swift_add_library("${target}" EXCEPTIONS RTTI ${warning_flag}
${x_UNPARSED_ARGUMENTS})

# We can refer to this target either with its standalone target name or with a
# project scoped name (<project>::<module>) which we will alias to the target
Expand All @@ -120,9 +144,9 @@ function(asap_add_library target)
get_target_property(type ${target} TYPE)
if(NOT ${type} STREQUAL "INTERFACE_LIBRARY")
# Set some common private compiler defines
asap_set_compile_definitions(${target})
# Set some common compiler options
asap_set_compile_options(${target})
asap_set_compile_definitions(${target} CONTRACTS ${x_CONTRACTS})
# Set common compiler options
asap_set_compile_options(${target} ${warning_flag})
# Generate export headers for the library
asap_generate_export_headers(${target} ${META_MODULE_NAME})

Expand All @@ -138,33 +162,34 @@ function(asap_add_library target)
endfunction()

function(asap_add_executable target)
swift_add_executable("${target}" ${ARGN})
set(argOption EXCEPTIONS RTTI WARNING)
set(argSingle CONTRACTS)
set(argMulti)

cmake_parse_arguments(x "${argOption}" "${argSingle}" "${argMulti}" ${ARGN})

if(x_WARNING)
set(warning_flag "WARNING")
else()
set(warning_flag)
endif()

# Contrarily to swift default, we enable exceptions and RTTI for all targets
swift_add_executable("${target}" EXCEPTIONS RTTI ${warning_flag}
${x_UNPARSED_ARGUMENTS})
# Set some common private compiler defines
asap_set_compile_definitions(${target})
# Set some common compiler options
asap_set_compile_options(${target})
asap_set_compile_definitions(${target} CONTRACTS ${x_CONTRACTS})
# Set common compiler options
asap_set_compile_options(${target} ${warning_flag})
set_target_properties(${target} PROPERTIES FOLDER "Executables")
endfunction()

function(asap_add_tool target)
swift_add_tool("${target}" ${ARGN})
# Set some common private compiler defines
asap_set_compile_definitions(${target})
# Set some common compiler options
asap_set_compile_options(${target})
asap_add_executable(${target} ${ARGN})
set_target_properties(${target} PROPERTIES FOLDER "Tools")
endfunction()

function(asap_add_tool_library target)
swift_add_tool_library("${target}" ${ARGN})
# Set some common private compiler defines
asap_set_compile_definitions(${target})
# Set some common compiler options
asap_set_compile_options(${target})
set_target_properties(
${target}
PROPERTIES FOLDER "Tool Libraries"
VERSION ${META_MODULE_VERSION}
SOVERSION ${META_MODULE_VERSION_MAJOR}
DEBUG_POSTFIX "d")
asap_add_library(${target} ${ARGN})
set_target_properties(${target} PROPERTIES FOLDER "Tool Libraries")
endfunction()
106 changes: 77 additions & 29 deletions cmake/CompileDefinitions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,64 +7,112 @@
include_guard(GLOBAL)

# ------------------------------------------------------------------------------
# Set a common set of compile definitions
# Set a common set of compile definitions.
#
# Compile definitions can be removed from the default set by passing REMOVE
# followed by a list of symbols, eg:
#
# asap_set_compile_definitions(sample-target REMOVE _CRT_SECURE_NO_WARNINGS)
#
# will prevent `_CRT_SECURE_NO_WARNINGS` from being passed to the compiler as a
# defined symbol for sample-target only.
#
# Similarly extra definitions can be added by passing ADD followed by a list of
# symbols (or definitions in the form of symbol=value), eg:
#
# asap_set_compile_definitions(sample-target ADD SUPER HERO=2)
#
# will pass SUPER and HERO=2 to the compiler as definitions for sample-target
# only.
#
# When linking against the contract checking and enforcement library
# `asap-contract` (https://github.com/asap-projects/asap-contract), it is
# possible to control the contract checking mode by passing a value for the
# `CONTRACTS` option to this function as follows:
#
# * CONTRACTS OFF : set contract checking mode to OFF
# * CONTRACTS AUDIT : set contract checking mode to AUDIT
# * CONTRACTS DEFAULT : set contract checking mode to DEFAULT
#
# * CONTRACTS AUTO : set contract checking mode using as a first priority the
# value passed in the cmake option `OPTION_CONTRACT_MODE`. If none is present,
# automatically set the mode based on the build configuration. For Debug ->
# AUDIT, For Release and RelMinSize -> OFF, and for RelWithDebInfo -> DEFAULT.
#
# * CONTRACTS TESTING : indicates that contracts are being testing and the
# target needs to have full control on the contract checking mode. Nothing
# will be done here.
#
# The default setting is AUTO.
# ------------------------------------------------------------------------------

function(asap_set_compile_definitions target)
set(argOption "NO_CONTRACT")
set(argSingle "")
set(argOption "")
set(argSingle "CONTRACTS")
set(argMulti "ADD" "REMOVE")

unset(x_WARNING)
unset(x_CONTRACTS)
unset(x_ADD)
unset(x_REMOVE)

cmake_parse_arguments(x "${argOption}" "${argSingle}" "${argMulti}" ${ARGN})
if(NOT DEFINED x_CONTRACTS OR x_CONTRACTS STREQUAL "")
set(x_CONTRACTS "AUTO")
endif()

set(all_flags)
set(all_definitions)

# Provide a way to distinguish between debug and release builds via
# preprocessor define
list(APPEND all_flags "$<$<CONFIG:Debug>:ASAP_IS_DEBUG_BUILD>")
list(APPEND all_definitions "$<$<CONFIG:Debug>:ASAP_IS_DEBUG_BUILD>")

if(MSVC)
list(APPEND all_flags "NOMINMAX" "WIN32_LEAN_AND_MEAN=1"
list(APPEND all_definitions "NOMINMAX" "WIN32_LEAN_AND_MEAN=1"
"_WIN32_WINNT=0x0600")
# Disabling warning for not using "secure-but-not-standard" STL algos
list(APPEND all_flags "_CRT_SECURE_NO_WARNINGS" "_SCL_SECURE_NO_WARNINGS")
list(APPEND all_definitions "_CRT_SECURE_NO_WARNINGS"
"_SCL_SECURE_NO_WARNINGS")
endif()

if(x_REMOVE)
foreach(flag ${x_REMOVE})
list(FIND all_flags ${flag} found)
foreach(definition ${x_REMOVE})
list(FIND all_definitions ${definition} found)
if(found EQUAL -1)
message(
FATAL_ERROR
"Compiler flag '${flag}' specified for removal is not part of the set of common
compiler flags")
"Compiler definition '${definition}' specified for removal is not "
"part of the set of common compiler definitions.")
endif()
endforeach()
list(REMOVE_ITEM all_flags ${x_REMOVE})
list(REMOVE_ITEM all_definitions ${x_REMOVE})
endif()

list(APPEND all_flags ${x_ADD})
target_compile_definitions(${target} PRIVATE ${all_flags})
list(APPEND all_definitions ${x_ADD})

target_compile_definitions(${target} PRIVATE ${all_definitions})

# If linking against asap_contract, set the contract mode based on the build
# type. Use generator expressions only, do not check for CMAKE_BUILD_TYPE
# which is not friendly with multi-config generators.
#
# Do not add this definition if we are testing asap-_contract
if(TARGET asap_contract AND NOT ASAP_CONTRACT_TESTING)
if(NOT DEFINED OPTION_CONTRACT_MODE)
target_compile_definitions(
${target}
PRIVATE $<$<CONFIG:Debug>:ASAP_CONTRACT_AUDIT>
$<$<CONFIG:RelWithDebInfo>:ASAP_CONTRACT_DEFAULT>
$<$<CONFIG:Release,RelMinSize>:ASAP_CONTRACT_OFF>)
# If linking against asap_contract, set the contract checking mode. Use
# generator expressions only, do not check for CMAKE_BUILD_TYPE which is not
# friendly with multi-config generators.
if(NOT x_CONTRACTS STREQUAL "TESTING")
if(x_CONTRACTS MATCHES "OFF|AUDIT|DEFAULT")
target_compile_definitions(${target}
PRIVATE "ASAP_CONTRACT_${x_CONTRACTS}")
elseif(x_CONTRACTS STREQUAL "AUTO")
if(NOT DEFINED OPTION_CONTRACT_MODE)
target_compile_definitions(
${target}
PRIVATE $<$<CONFIG:Debug>:ASAP_CONTRACT_AUDIT>
$<$<CONFIG:RelWithDebInfo>:ASAP_CONTRACT_DEFAULT>
$<$<CONFIG:Release,RelMinSize>:ASAP_CONTRACT_OFF>)
else()
target_compile_definitions(
${target} PRIVATE "ASAP_CONTRACT_${OPTION_CONTRACT_MODE}")
endif()
else()
target_compile_definitions(
${target} PRIVATE "ASAP_CONTRACT_${OPTION_CONTRACT_MODE}")
message(
FATAL_ERROR "Contract mode '${x_CONTRACTS}' is not valid."
"Valid values are: OFF, DEFAULT, AUDIT, AUTO and TESTING.")
endif()
endif()
endfunction()
12 changes: 8 additions & 4 deletions cmake/CompileOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
# RTTI. By default, both are enabled.

function(asap_set_compile_options)
swift_set_compile_options(EXCEPTIONS RTTI ${ARGV})

if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# using Clang
swift_set_compile_options(
Expand Down Expand Up @@ -46,13 +44,19 @@ function(asap_set_compile_options)
endif()
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
# using Visual Studio C++
set(argOption "WARNING" "NO_EXCEPTIONS" "EXCEPTIONS" "NO_RTTI" "RTTI")
set(argOption "WARNING")
set(argSingle "")
set(argMulti "ADD" "REMOVE" "EXTRA_FLAGS")
set(argMulti "")

cmake_parse_arguments(x "${argOption}" "${argSingle}" "${argMulti}" ${ARGN})

set(targets ${x_UNPARSED_ARGUMENTS})

foreach(target ${targets})
target_compile_options(${target} PRIVATE /EHsc /MP /W4)
if(NOT x_WARNING)
target_compile_options(${target} PRIVATE /WX)
endif()
endforeach()
endif()

Expand Down
35 changes: 35 additions & 0 deletions cmake/ResetInitialCompilerOptions.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# ===-----------------------------------------------------------------------===#
# Distributed under the 3-Clause BSD License. See accompanying file LICENSE or
# copy at https://opensource.org/licenses/BSD-3-Clause).
# SPDX-License-Identifier: BSD-3-Clause
# ===-----------------------------------------------------------------------===#

# This module is loaded by `cmake` while enabling support for each language from
# either the project() or enable_language() commands. It is loaded after CMake's
# builtin compiler and platform information modules have been loaded but before
# the information is used. The file may set platform information variables to
# override CMake's defaults.
#
# To load this module, set the variable `CMAKE_USER_MAKE_RULES_OVERRIDE` before
# you declare the project or enable a language:
# ~~~
# set(CMAKE_USER_MAKE_RULES_OVERRIDE "ResetInitialCompilerOptions")
# ~~~

# We use this module to strip compiler options that are not really needed but
# will cause compatibility issues with `ccache`.
if(MSVC AND USE_CCACHE)
# As of ccache 4.6, /Zi option automatically added by cmake is unsupported.
# Given that we are doing ccache only in development environments (USE_CCACHE
# controls if ccache is enabled), we can just strip that option.
macro(strip_unwanted_options_from cmake_flags)
if(${cmake_flags} MATCHES "/Zi")
string(REPLACE "/Zi" "/Z7" ${cmake_flags} ${${cmake_flags}})
endif()
endmacro()
strip_unwanted_options_from(CMAKE_CXX_FLAGS_DEBUG_INIT)
strip_unwanted_options_from(CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT)
strip_unwanted_options_from(CMAKE_C_FLAGS_DEBUG_INIT)
strip_unwanted_options_from(CMAKE_C_FLAGS_RELWITHDEBINFO_INIT)
set(first_time FALSE)
endif()
24 changes: 19 additions & 5 deletions cmake/TestTargets.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,17 @@
include(common/TestTargets)

macro(asap_add_test target)
swift_add_test("${target}" ${ARGN})
set(argOption)
set(argSingle CONTRACTS)
set(argMulti)

cmake_parse_arguments(x "${argOption}" "${argSingle}" "${argMulti}" ${ARGN})

# Contrarily to swift default, we enable exceptions and RTTI for all targets
swift_add_test("${target}" ${warning_flag} ${x_UNPARSED_ARGUMENTS})
# Set some common private compiler defines
asap_set_compile_definitions(${target})
# Set some common compiler options
asap_set_compile_definitions(${target} CONTRACTS ${x_CONTRACTS})
# Set common compiler options
asap_set_compile_options(${target})
if(TARGET gtest AND BUILD_SHARED_LIBS)
target_compile_definitions(${target} PRIVATE GTEST_LINKED_AS_SHARED_LIBRARY)
Expand All @@ -31,9 +38,16 @@ macro(asap_add_test_runner target)
endmacro()

function(asap_add_test_library target)
swift_add_test_library("${target}" ${ARGN})
set(argOption)
set(argSingle CONTRACTS)
set(argMulti)

cmake_parse_arguments(x "${argOption}" "${argSingle}" "${argMulti}" ${ARGN})

# Contrarily to swift default, we enable exceptions and RTTI for all targets
swift_add_test_library("${target}" ${x_UNPARSED_ARGUMENTS})
# Set some common private compiler defines
asap_set_compile_definitions(${target})
asap_set_compile_definitions(${target} CONTRACTS ${x_CONTRACTS})
# Set some common compiler options
asap_set_compile_options(${target})
set_target_properties(
Expand Down
2 changes: 1 addition & 1 deletion doc/conf.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ master_doc = 'index'
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = None
language = 'en'

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
Expand Down

0 comments on commit a4085fb

Please sign in to comment.