Skip to content

Commit

Permalink
Allow mixing debug and release builds
Browse files Browse the repository at this point in the history
  • Loading branch information
msimberg committed Jan 6, 2021
1 parent da5853f commit 3d5207c
Show file tree
Hide file tree
Showing 18 changed files with 105 additions and 194 deletions.
19 changes: 1 addition & 18 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1739,23 +1739,6 @@ hpx_option(
ADVANCED
)

# ##############################################################################
# Add necessary compiler flags. Flags added here include flags to disable/enable
# certain warnings, enabling C++11 mode and disabling asserts. Setting of
# optimization flags is not handled here and is left to the responsibility of
# the user to avoid conflicts in the resulting binaries

hpx_add_target_compile_definition(_DEBUG PUBLIC CONFIGURATIONS Debug)
hpx_add_target_compile_definition(DEBUG PUBLIC CONFIGURATIONS Debug)
hpx_add_target_compile_definition(
HPX_DISABLE_ASSERTS PUBLIC CONFIGURATIONS Release RelWithDebInfo
MinSizeRelease
)
hpx_add_target_compile_definition(
BOOST_DISABLE_ASSERTS PUBLIC CONFIGURATIONS Release RelWithDebInfo
MinSizeRelease
)

# ##############################################################################
# C++ feature tests
# ##############################################################################
Expand Down Expand Up @@ -1860,7 +1843,7 @@ if(WIN32)
# non-referenced functions and data (-Zc:inline)
hpx_add_target_compile_option(-Zc:inline PUBLIC)
hpx_add_target_compile_option(
-Gw PUBLIC CONFIGURATIONS Release RelWithDebInfo MinSizeRelease
-Gw PUBLIC CONFIGURATIONS Release RelWithDebInfo MinSizeRel
)
hpx_add_target_compile_option(-Zo PUBLIC CONFIGURATIONS RelWithDebInfo)
if(HPX_WITH_DATAPAR_VC)
Expand Down
4 changes: 1 addition & 3 deletions cmake/HPX_AddModule.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -300,9 +300,7 @@ function(add_hpx_module libname modulename)
endif()

target_compile_definitions(
hpx_${modulename}
PRIVATE $<$<CONFIG:Debug>:DEBUG> $<$<CONFIG:Debug>:_DEBUG>
HPX_${libname_upper}_EXPORTS
hpx_${modulename} PRIVATE HPX_${libname_upper}_EXPORTS
)

# This is a temporary solution until all of HPX has been modularized as it
Expand Down
6 changes: 6 additions & 0 deletions cmake/HPX_CompilerFlagsTargets.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ target_compile_definitions(
hpx_public_flags INTERFACE $<$<CONFIG:Debug>:HPX_DEBUG>
)

target_compile_definitions(
hpx_private_flags INTERFACE $<$<CONFIG:MinSizeRel>:NDEBUG>
hpx_private_flags INTERFACE $<$<CONFIG:Release>:NDEBUG>
hpx_private_flags INTERFACE $<$<CONFIG:RelWithDebInfo>:NDEBUG>
)

# Remaining flags are set through the macros in cmake/HPX_AddCompileFlag.cmake

include(HPX_ExportTargets)
Expand Down
1 change: 0 additions & 1 deletion cmake/templates/HPXConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ if(NOT HPX_CMAKE_LOGLEVEL)
set(HPX_CMAKE_LOGLEVEL "WARN")
endif()

hpx_check_cmake_build_type()
hpx_check_compiler_compatibility()
hpx_check_boost_compatibility()
hpx_check_allocator_compatibility()
Expand Down
22 changes: 0 additions & 22 deletions cmake/templates/HPXMacros.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -95,25 +95,3 @@ function(hpx_check_allocator_compatibility)
"informational purposes to dependent projects and should not be changed.")
endif()
endfunction()

# Check we are using the same build type as HPX
function(hpx_check_cmake_build_type)
get_property(_GENERATOR_IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
if (NOT _GENERATOR_IS_MULTI_CONFIG AND
NOT "${HPX_BUILD_TYPE}" STREQUAL "${CMAKE_BUILD_TYPE}" AND
("${HPX_BUILD_TYPE}" STREQUAL "Debug" OR "${CMAKE_BUILD_TYPE}" STREQUAL "Debug"))
if(HPX_IGNORE_CMAKE_BUILD_TYPE_COMPATIBILITY)
hpx_warn("CMAKE_BUILD_TYPE does not match ${HPX_BUILD_TYPE}: "
"this project uses '${CMAKE_BUILD_TYPE}', HPX uses '${HPX_BUILD_TYPE}'. "
"HPX is not ABI compatible between release and debug modes and it is "
"recommended that you use the same build type for HPX and your project.")
else()
hpx_error("CMAKE_BUILD_TYPE does not match ${HPX_BUILD_TYPE}: "
"this project uses '${CMAKE_BUILD_TYPE}', HPX uses '${HPX_BUILD_TYPE}'. "
"Please add -DCMAKE_BUILD_TYPE=${HPX_BUILD_TYPE} to your cmake command "
"or add -DHPX_IGNORE_CMAKE_BUILD_TYPE_COMPATIBILITY=ON to ignore this "
"check (not recommended; HPX is not ABI compatible between release and "
"debug modes).")
endif()
endif()
endfunction()
4 changes: 0 additions & 4 deletions examples/hello_world_component/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ if(EXISTS "${HPX_DIR}")

add_executable(hello_world_client hello_world_client.cpp)
target_include_directories(hello_world_client PRIVATE ${test_SOURCE_DIR})
target_include_directories(hello_world_client PRIVATE HPX_DEBUG)

if("${SETUP_TYPE}" STREQUAL "TARGETS")
target_link_libraries(
Expand All @@ -36,9 +35,6 @@ if(EXISTS "${HPX_DIR}")
target_include_directories(
hello_world_client_only_hpx_init PRIVATE ${test_SOURCE_DIR}
)
target_include_directories(
hello_world_client_only_hpx_init PRIVATE HPX_DEBUG
)

target_link_libraries(
hello_world_client_only_hpx_init PRIVATE hello_world_component
Expand Down
9 changes: 0 additions & 9 deletions hpx/runtime/components/server/component_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,6 @@ namespace hpx { namespace components
HPX_EXPORT naming::id_type get_unmanaged_id(
naming::gid_type const& gid) const;

#if defined(HPX_DISABLE_ASSERTS) || defined(BOOST_DISABLE_ASSERTS) || defined(NDEBUG)
static constexpr void mark_as_migrated()
{
}
static constexpr void on_migrated()
{
}
#else
static void mark_as_migrated()
{
// If this assertion is triggered then this component instance is
Expand All @@ -100,7 +92,6 @@ namespace hpx { namespace components
// migration.
HPX_ASSERT(false);
}
#endif

protected:
// Create a new GID (if called for the first time), assign this
Expand Down
33 changes: 0 additions & 33 deletions hpx/runtime/components/server/fixed_component_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,6 @@ class fixed_component_base : public traits::detail::fixed_component_tag
}
}

#if defined(HPX_DISABLE_ASSERTS) || defined(BOOST_DISABLE_ASSERTS) || defined(NDEBUG)
static constexpr void mark_as_migrated()
{
}
static constexpr void on_migrated()
{
}
#else
void mark_as_migrated()
{
// If this assertion is triggered then this component instance is being
Expand All @@ -178,7 +170,6 @@ class fixed_component_base : public traits::detail::fixed_component_tag
// migration.
HPX_ASSERT(false);
}
#endif

private:
mutable naming::gid_type gid_;
Expand All @@ -191,15 +182,6 @@ namespace detail
///////////////////////////////////////////////////////////////////////
struct fixed_heap
{
#if defined(HPX_DISABLE_ASSERTS) || defined(BOOST_DISABLE_ASSERTS) || defined(NDEBUG)
static constexpr void* alloc(std::size_t /*count*/)
{
return nullptr;
}
static constexpr void free(void* /*p*/, std::size_t /*count*/)
{
}
#else
static void* alloc(std::size_t /*count*/)
{
HPX_ASSERT(false); // this shouldn't ever be called
Expand All @@ -209,7 +191,6 @@ namespace detail
{
HPX_ASSERT(false); // this shouldn't ever be called
}
#endif
};
}

Expand All @@ -223,17 +204,6 @@ class fixed_component : public Component
typedef component_type derived_type;
typedef detail::fixed_heap heap_type;

#if defined(HPX_DISABLE_ASSERTS) || defined(BOOST_DISABLE_ASSERTS) || defined(NDEBUG)
static constexpr Component* create(std::size_t /* count */)
{
return nullptr;
}

static constexpr void destroy(
Component* /* p */, std::size_t /* count */ = 1)
{
}
#else
/// \brief The function \a create is used for allocation and
/// initialization of instances of the derived components.
static Component* create(std::size_t /* count */)
Expand All @@ -248,9 +218,6 @@ class fixed_component : public Component
{
HPX_ASSERT(false); // this shouldn't ever be called
}
#endif
};

}}


9 changes: 0 additions & 9 deletions hpx/runtime/components/server/managed_component_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,6 @@ namespace hpx { namespace components
/// destructed
static constexpr void finalize() {}

#if defined(HPX_DISABLE_ASSERTS) || defined(BOOST_DISABLE_ASSERTS) || defined(NDEBUG)
static constexpr void mark_as_migrated()
{
}
static constexpr void on_migrated()
{
}
#else
static void mark_as_migrated()
{
// If this assertion is triggered then this component instance is
Expand All @@ -194,7 +186,6 @@ namespace hpx { namespace components
// migration.
HPX_ASSERT(false);
}
#endif
};
}

Expand Down
15 changes: 2 additions & 13 deletions libs/core/config/include/hpx/config/debug.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,9 @@
#define HPX_BUILD_TYPE
#else

// clang-format off
// Make sure DEBUG macro is defined consistently across platforms
#if defined(_DEBUG) && !defined(DEBUG)
# define DEBUG
#endif

#if defined(DEBUG) && !defined(HPX_DEBUG)
# define HPX_DEBUG
#endif

#if defined(HPX_DEBUG)
# define HPX_BUILD_TYPE debug
#define HPX_BUILD_TYPE debug
#else
# define HPX_BUILD_TYPE release
#define HPX_BUILD_TYPE release
#endif
#endif
// clang-format on
33 changes: 11 additions & 22 deletions libs/core/functional/include/hpx/functional/one_shot.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ namespace hpx { namespace util {
class one_shot_wrapper //-V690
{
public:
#if !defined(HPX_DISABLE_ASSERTS)
// default constructor is needed for serialization
constexpr one_shot_wrapper()
#if defined(HPX_DEBUG)
: _called(false)
#endif
{
}

Expand All @@ -37,42 +38,30 @@ namespace hpx { namespace util {
std::is_constructible<F, F_>::value>::type>
constexpr explicit one_shot_wrapper(F_&& f)
: _f(std::forward<F_>(f))
#if defined(HPX_DEBUG)
, _called(false)
#endif
{
}

constexpr one_shot_wrapper(one_shot_wrapper&& other)
: _f(std::move(other._f))
#if defined(HPX_DEBUG)
, _called(other._called)
#endif
{
#if defined(HPX_DEBUG)
other._called = true;
#endif
}

void check_call()
{
#if defined(HPX_DEBUG)
HPX_ASSERT(!_called);

_called = true;
}
#else
// default constructor is needed for serialization
constexpr one_shot_wrapper() {}

template <typename F_,
typename = typename std::enable_if<
std::is_constructible<F, F_>::value>::type>
constexpr explicit one_shot_wrapper(F_&& f)
: _f(std::forward<F_>(f))
{
}

constexpr one_shot_wrapper(one_shot_wrapper&& other)
: _f(std::move(other._f))
{
}

void check_call() {}
#endif
}

template <typename... Ts>
constexpr HPX_HOST_DEVICE
Expand Down Expand Up @@ -118,7 +107,7 @@ namespace hpx { namespace util {

public: // exposition-only
F _f;
#if !defined(HPX_DISABLE_ASSERTS)
#if defined(HPX_DEBUG)
bool _called;
#endif
};
Expand Down
6 changes: 3 additions & 3 deletions libs/core/preprocessor/include/hpx/preprocessor/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@
#/* HPX_PP_CONFIG_ERRORS */
#
#if !defined(HPX_PP_CONFIG_ERRORS)
#ifdef NDEBUG
#define HPX_PP_CONFIG_ERRORS 0
#else
#ifdef HPX_DEBUG
#define HPX_PP_CONFIG_ERRORS 1
#else
#define HPX_PP_CONFIG_ERRORS 0
#endif
#endif
#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#pragma once

#if !defined(NDEBUG)
#if defined(HPX_DEBUG)
//# define SHARED_PRIORITY_SCHEDULER_DEBUG 1
#endif

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <hpx/config.hpp>
#include <hpx/assert.hpp>
#include <hpx/concepts/has_member_xxx.hpp>
#include <hpx/type_support/unused.hpp>

#include <type_traits>

Expand All @@ -26,24 +27,21 @@ namespace hpx { namespace util { namespace detail {
{
}

#if !defined(HPX_DISABLE_ASSERTS) && !defined(BOOST_DISABLE_ASSERTS) && \
!defined(NDEBUG)

template <typename Lock>
typename std::enable_if<has_owns_lock<Lock>::value>::type assert_owns_lock(
Lock const& l, long)
{
HPX_ASSERT(l.owns_lock());
HPX_UNUSED(l);
}

template <typename Lock>
typename std::enable_if<has_owns_lock<Lock>::value>::type
assert_doesnt_own_lock(Lock const& l, long)
{
HPX_ASSERT(!l.owns_lock());
HPX_UNUSED(l);
}

#endif
}}} // namespace hpx::util::detail

#define HPX_ASSERT_OWNS_LOCK(l) ::hpx::util::detail::assert_owns_lock(l, 0L)
Expand Down
Loading

0 comments on commit 3d5207c

Please sign in to comment.