Skip to content

Commit

Permalink
Merge pull request #4889 from msimberg/fix-init-main
Browse files Browse the repository at this point in the history
Restore old behaviour of not requiring linking to hpx_wrap when HPX_WITH_DYNAMIC_HPX_MAIN=OFF
  • Loading branch information
msimberg authored Aug 14, 2020
2 parents 6d75999 + fdcc28d commit 148ffaa
Show file tree
Hide file tree
Showing 12 changed files with 91 additions and 72 deletions.
1 change: 1 addition & 0 deletions .jenkins/lsu/env-clang-7.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ configure_extra_options+=" -DHPX_WITH_DEPRECATION_WARNINGS=OFF"
configure_extra_options+=" -DHPX_WITH_COMPILER_WARNINGS=ON"
configure_extra_options+=" -DHPX_WITH_COMPILER_WARNINGS_AS_ERRORS=ON"
configure_extra_options+=" -DHPX_WITH_PARCELPORT_MPI=ON"
configure_extra_options+=" -DHPX_WITH_DYNAMIC_HPX_MAIN=OFF"
25 changes: 25 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,31 @@ if(HPX_WITH_UNITY_BUILD AND (CMAKE_VERSION VERSION_LESS "3.16"))
hpx_error("HPX_WITH_UNITY_BUILD=ON but this requires CMake 3.16 or newer.")
endif()

# ##############################################################################
# Dynamic hpx_main
# ##############################################################################

set(HPX_WITH_DYNAMIC_HPX_MAIN_DEFAULT OFF)
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux" OR APPLE)
set(HPX_WITH_DYNAMIC_HPX_MAIN_DEFAULT ON)
endif()

hpx_option(
HPX_WITH_DYNAMIC_HPX_MAIN
BOOL
"Enable dynamic overload of system ``main()`` (Linux and Apple only, default: ON)"
${HPX_WITH_DYNAMIC_HPX_MAIN_DEFAULT}
ADVANCED
)
if(HPX_WITH_DYNAMIC_HPX_MAIN)
if(NOT HPX_WITH_DYNAMIC_HPX_MAIN_DEFAULT)
hpx_error(
"HPX_WITH_DYNAMIC_HPX_MAIN was set to ON, but the option is only available on Linux and Apple (this is \"${CMAKE_SYSTEM_NAME}\")."
)
endif()
hpx_add_config_define(HPX_HAVE_DYNAMIC_HPX_MAIN)
endif()

# ##############################################################################
# Some platforms do not support dynamic linking. Enable this to link all
# libraries statically. This also changes some of the internals of HPX related
Expand Down
2 changes: 1 addition & 1 deletion cmake/HPX_GeneratePackage.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ install(
if(NOT MSVC)
add_library(hpx_pkgconfig_application INTERFACE)
target_link_libraries(
hpx_pkgconfig_application INTERFACE hpx hpx_init hpx_wrap
hpx_pkgconfig_application INTERFACE hpx hpx_wrap hpx_init
)
target_compile_definitions(
hpx_pkgconfig_application INTERFACE HPX_APPLICATION_EXPORTS
Expand Down
25 changes: 22 additions & 3 deletions examples/hello_world_component/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,31 @@ if(EXISTS "${HPX_DIR}")

if("${SETUP_TYPE}" STREQUAL "TARGETS")
target_link_libraries(
hello_world_component PUBLIC HPX::hpx HPX::wrap_main
HPX::iostreams_component
hello_world_component PUBLIC HPX::hpx HPX::iostreams_component
)
target_link_libraries(hello_world_component PRIVATE HPX::component)

target_link_libraries(hello_world_client PRIVATE hello_world_component)
target_link_libraries(
hello_world_client PRIVATE hello_world_component HPX::wrap_main
)

# We still support not linking to HPX::wrap_main when
# HPX_WITH_DYNAMIC_HPX_MAIN=OFF for legacy use. This can only be done using
# an installed HPX. It is strongly recommended to always link to
# HPX::wrap_main when implicitly using main as the runtime entry point.
if(USING_INSTALL_DIR AND NOT HPX_WITH_DYNAMIC_HPX_MAIN)
add_executable(hello_world_client_only_hpx_init hello_world_client.cpp)
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
)
endif()
elseif("${SETUP_TYPE}" STREQUAL "MACROS")
hpx_setup_target(
hello_world_component
Expand Down
21 changes: 21 additions & 0 deletions init/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ set(hpx_init_HEADERS
""
CACHE INTERNAL "Headers for libhpx_init." FORCE
)
list(APPEND hpx_init_HEADERS hpx/hpx_main_impl.hpp)
set(hpx_init_SOURCES
""
CACHE INTERNAL "Sources for libhpx_init." FORCE
Expand All @@ -22,9 +23,19 @@ list(
hpx_main_variables_map.cpp
hpx_user_main.cpp
hpx_user_main_argc_argv.cpp
main.cpp
)

# make source groups
set(hpx_init_HEADER_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/include)
list(TRANSFORM hpx_init_HEADERS PREPEND ${hpx_init_HEADER_ROOT}/)
add_hpx_source_group(
NAME hpx_init
CLASS "Header Files"
ROOT "${hpx_init_HEADER_ROOT}"
TARGETS ${hpx_init_HEADERS}
)

set(hpx_init_SOURCE_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/src)
list(TRANSFORM hpx_init_SOURCES PREPEND ${hpx_init_SOURCE_ROOT}/)
add_hpx_source_group(
Expand All @@ -39,6 +50,10 @@ set_target_properties(hpx_init PROPERTIES POSITION_INDEPENDENT_CODE ON)
target_link_libraries(hpx_init PRIVATE hpx_core)
target_link_libraries(hpx_init PRIVATE hpx_private_flags)
target_compile_definitions(hpx_init PRIVATE HPX_APPLICATION_EXPORTS)
target_include_directories(
hpx_init PUBLIC $<BUILD_INTERFACE:${hpx_init_HEADER_ROOT}>
$<INSTALL_INTERFACE:include>
)

set_property(TARGET hpx_init PROPERTY FOLDER "Core")

Expand Down Expand Up @@ -73,6 +88,12 @@ install(
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT runtime
)

install(
DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
COMPONENT runtime
)

# install PDB if needed
if(MSVC)
foreach(cfg DEBUG;RELWITHDEBINFO)
Expand Down
File renamed without changes.
3 changes: 1 addition & 2 deletions wrap/src/main.cpp → init/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

#include <hpx/config.hpp>
#include <hpx/wrap/config/defines.hpp>

// We support different implementation depending upon the Operating
// System in use.
Expand All @@ -15,7 +14,7 @@

// when statically linking the default definition of main happens on demand only
#if !defined(HPX_HAVE_STATIC_LINKING)
#include <hpx/wrap_main_impl.hpp>
#include <hpx/hpx_main_impl.hpp>
#endif

#endif
4 changes: 2 additions & 2 deletions libs/init_runtime/src/hpx_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ namespace hpx { namespace detail {
}} // namespace hpx::detail

///////////////////////////////////////////////////////////////////////////////
#if (HPX_HAVE_DYNAMIC_HPX_MAIN != 0) && \
#if defined(HPX_HAVE_DYNAMIC_HPX_MAIN) && \
(defined(__linux) || defined(__linux__) || defined(linux) || \
defined(__APPLE__))
namespace hpx_start {
Expand Down Expand Up @@ -765,7 +765,7 @@ namespace hpx {
// make sure the runtime system is not active yet
if (get_runtime_ptr() != nullptr)
{
#if (HPX_HAVE_DYNAMIC_HPX_MAIN != 0) && \
#if defined(HPX_HAVE_DYNAMIC_HPX_MAIN) && \
(defined(__linux) || defined(__linux__) || defined(linux) || \
defined(__APPLE__))
// make sure the runtime system is not initialized
Expand Down
23 changes: 13 additions & 10 deletions tests/unit/build/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ if(NOT HPX_WITH_DISTRIBUTED_RUNTIME)
endif()

# Try building an external cmake based project ...
function(create_cmake_test name hpx_dir setup_type test_dir)
function(create_cmake_test name using_install_dir hpx_dir setup_type test_dir)
set(build_dir "${CMAKE_CURRENT_BINARY_DIR}/${name}")
add_custom_target(
${name}.make_build_dir
COMMAND "${CMAKE_COMMAND}" -E make_directory "${build_dir}"
VERBATIM
)
set(ADDITIONAL_CMAKE_OPTIONS -DUSING_INSTALL_DIR=${using_install_dir})
set(ADDITIONAL_CMAKE_OPTIONS -DSETUP_TYPE=${setup_type})
if(CMAKE_TOOLCHAIN_FILE)
set(ADDITIONAL_CMAKE_OPTIONS ${ADDITIONAL_CMAKE_OPTIONS}
Expand Down Expand Up @@ -117,39 +118,39 @@ function(create_pkgconfig_test name hpx_dir)
endfunction()

create_cmake_test(
cmake_build_dir_targets_test
cmake_build_dir_targets_test FALSE
"${PROJECT_BINARY_DIR}/lib/cmake/${HPX_PACKAGE_NAME}" TARGETS
"examples/hello_world_component"
)

create_cmake_test(
cmake_build_dir_macros_test
cmake_build_dir_macros_test FALSE
"${PROJECT_BINARY_DIR}/lib/cmake/${HPX_PACKAGE_NAME}" MACROS
"examples/hello_world_component"
)

create_cmake_test(
cmake_install_dir_targets_test
cmake_install_dir_targets_test TRUE
"${CMAKE_INSTALL_FULL_LIBDIR}/cmake/${HPX_PACKAGE_NAME}" TARGETS
"examples/hello_world_component"
)

create_cmake_test(
cmake_install_dir_macros_test
cmake_install_dir_macros_test TRUE
"${CMAKE_INSTALL_FULL_LIBDIR}/cmake/${HPX_PACKAGE_NAME}" MACROS
"examples/hello_world_component"
)

if(HPX_WITH_DYNAMIC_HPX_MAIN)
# Google test emulation
create_cmake_test(
cmake_build_dir_gtest_emulation_test
cmake_build_dir_gtest_emulation_test FALSE
"${PROJECT_BINARY_DIR}/lib/cmake/${HPX_PACKAGE_NAME}" TARGETS
"examples/gtest_emulation"
)

create_cmake_test(
cmake_install_dir_gtest_emulation_test
cmake_install_dir_gtest_emulation_test TRUE
"${CMAKE_INSTALL_FULL_LIBDIR}/cmake/${HPX_PACKAGE_NAME}" TARGETS
"examples/gtest_emulation"
)
Expand All @@ -170,10 +171,12 @@ if(NOT MSVC)
endif()

set(build_systems cmake)
set(cmake_tests
build_dir_targets install_dir_targets build_dir_macros install_dir_macros
build_dir_gtest_emulation install_dir_gtest_emulation
set(cmake_tests build_dir_targets install_dir_targets build_dir_macros
install_dir_macros
)
if(HPX_WITH_DYNAMIC_HPX_MAIN)
list(APPEND cmake_tests build_dir_gtest_emulation install_dir_gtest_emulation)
endif()
if(NOT CMAKE_TOOLCHAIN_FILE
AND PKGCONFIG_FOUND
AND NOT MSVC
Expand Down
55 changes: 4 additions & 51 deletions wrap/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,50 +6,17 @@
# Distributed under the Boost Software License, Version 1.0. (See accompanying
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

set(HPX_WITH_DYNAMIC_HPX_MAIN_DEFAULT OFF)
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux" OR APPLE)
set(HPX_WITH_DYNAMIC_HPX_MAIN_DEFAULT ON)
endif()

hpx_option(
HPX_WITH_DYNAMIC_HPX_MAIN
BOOL
"Enable dynamic overload of system ``main()`` (Linux and Apple only, default: ON)"
${HPX_WITH_DYNAMIC_HPX_MAIN_DEFAULT}
ADVANCED
)
if(HPX_WITH_DYNAMIC_HPX_MAIN)
if(NOT HPX_WITH_DYNAMIC_HPX_MAIN_DEFAULT)
hpx_error(
"HPX_WITH_DYNAMIC_HPX_MAIN was set to ON, but the option is only available on Linux and Apple (this is \"${CMAKE_SYSTEM_NAME}\")."
)
endif()
hpx_add_config_define_namespace(
DEFINE HPX_HAVE_DYNAMIC_HPX_MAIN NAMESPACE wrap
)
endif()

set(config_header
"${CMAKE_CURRENT_BINARY_DIR}/include/hpx/wrap/config/defines.hpp"
)
write_config_defines_file(NAMESPACE wrap FILENAME ${config_header})

set(hpx_wrap_HEADERS
""
CACHE INTERNAL "Headers for libhpx_wrap." FORCE
)
list(APPEND hpx_wrap_HEADERS hpx/hpx_main.hpp hpx/wrap_main.hpp
hpx/wrap_main_impl.hpp
)
list(APPEND hpx_wrap_HEADERS hpx/hpx_main.hpp hpx/wrap_main.hpp)

set(hpx_wrap_SOURCES
""
CACHE INTERNAL "Sources for libhpx_wrap." FORCE
)
list(APPEND hpx_wrap_SOURCES main.cpp)
if(HPX_WITH_DYNAMIC_HPX_MAIN)
list(APPEND hpx_wrap_SOURCES hpx_wrap.cpp)
endif()
list(APPEND hpx_wrap_SOURCES hpx_wrap.cpp)

# make source groups
set(hpx_wrap_SOURCE_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/src)
Expand All @@ -69,12 +36,6 @@ add_hpx_source_group(
ROOT "${hpx_wrap_HEADER_ROOT}"
TARGETS ${hpx_wrap_HEADERS}
)
add_hpx_source_group(
NAME hpx_wrap
CLASS "Generated Files"
ROOT "${CMAKE_CURRENT_BINARY_DIR}/include/hpx"
TARGETS ${config_header}
)

add_library(
hpx_wrap STATIC ${hpx_wrap_SOURCES} ${hpx_wrap_HEADERS} ${config_header}
Expand All @@ -85,10 +46,8 @@ target_link_libraries(hpx_wrap PRIVATE hpx_init)
target_link_libraries(hpx_wrap PRIVATE hpx_private_flags)
target_compile_definitions(hpx_wrap PRIVATE HPX_APPLICATION_EXPORTS)
target_include_directories(
hpx_wrap
PUBLIC $<BUILD_INTERFACE:${hpx_wrap_HEADER_ROOT}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
$<INSTALL_INTERFACE:include>
hpx_wrap PUBLIC $<BUILD_INTERFACE:${hpx_wrap_HEADER_ROOT}>
$<INSTALL_INTERFACE:include>
)

set_property(TARGET hpx_wrap PROPERTY FOLDER "Core")
Expand Down Expand Up @@ -129,12 +88,6 @@ install(
COMPONENT runtime
)

install(
DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/hpx
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
COMPONENT runtime
)

hpx_export_internal_targets(hpx_wrap)

add_hpx_pseudo_dependencies(core hpx_wrap)
3 changes: 1 addition & 2 deletions wrap/include/hpx/wrap_main.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#pragma once

#include <hpx/config.hpp>
#include <hpx/wrap/config/defines.hpp>
#include <hpx/hpx_init.hpp>

// We support different implementation depending upon the Operating
Expand Down Expand Up @@ -41,7 +40,7 @@ namespace hpx_start
#else

#if defined(HPX_HAVE_STATIC_LINKING)
#include <hpx/wrap_main_impl.hpp>
#include <hpx/hpx_main_impl.hpp>
#endif

// We support redefining the plain C-main provided by the user to be executed
Expand Down
1 change: 0 additions & 1 deletion wrap/src/hpx_wrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

#include <hpx/config.hpp>
#include <hpx/wrap/config/defines.hpp>

// The following implementation has been divided for Linux and Mac OSX
#if defined(HPX_HAVE_DYNAMIC_HPX_MAIN) && \
Expand Down

0 comments on commit 148ffaa

Please sign in to comment.