Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds HPX_LINKER_FLAGS to HPX applications without editing their source codes #3371

Merged
merged 2 commits into from
Jul 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions cmake/HPX_GeneratePackage.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ if(HPX_WITH_STATIC_LINKING)
set(HPX_CONF_LIBRARIES "general;hpx;${HPX_LIBRARIES}")
set(HPX_PKG_LIBRARIES "\${libdir}/libhpx.a ${HPX_PKG_LIBRARIES}")
set(HPX_PKG_DEBUG_LIBRARIES "\${libdir}/libhpxd.a ${HPX_PKG_DEBUG_LIBRARIES}")
if(HPX_WITH_DYNAMIC_HPX_MAIN AND ("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux"))
set(HPX_PKG_LIBRARIES "\${libdir}/libhpx_wrap.a ${HPX_PKG_LIBRARIES}")
set(HPX_PKG_DEBUG_LIBRARIES "\${libdir}/libhpx_wrapd.a ${HPX_PKG_DEBUG_LIBRARIES}")
endif()
else()
set(HPX_CONF_LIBRARIES "general;hpx;general;hpx_init;${HPX_LIBRARIES}")
if(APPLE)
Expand All @@ -71,6 +75,10 @@ else()
set(HPX_PKG_DEBUG_LIBRARIES_BAZEL "${HPX_CONF_PREFIX}/lib/libhpxd.so ${HPX_CONF_PREFIX}/lib/libhpx_initd.a ${HPX_PKG_DEBUG_LIBRARIES}")
set(HPX_PKG_LIBRARIES "\${libdir}/libhpx.so \${libdir}/libhpx_init.a ${HPX_PKG_LIBRARIES}")
set(HPX_PKG_DEBUG_LIBRARIES "\${libdir}/libhpxd.so \${libdir}/libhpx_initd.a ${HPX_PKG_DEBUG_LIBRARIES}")
if(HPX_WITH_DYNAMIC_HPX_MAIN AND ("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux"))
set(HPX_PKG_LIBRARIES "\${libdir}/libhpx_wrap.a ${HPX_PKG_LIBRARIES}")
set(HPX_PKG_DEBUG_LIBRARIES "\${libdir}/libhpx_wrapd.a ${HPX_PKG_DEBUG_LIBRARIES}")
endif()
endif()
endif()

Expand Down
9 changes: 5 additions & 4 deletions cmake/HPX_SetupTarget.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,11 @@ function(hpx_setup_target target)
endif()

if(NOT target_NOLIBS)
set(hpx_libs hpx)
if(HPX_WITH_DYNAMIC_HPX_MAIN AND ("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this happen for executables only?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hkaiser if we limit it to Executables only, then some shared objects that link to it in phylanx will throw a linker error for not defined __real___libc_start_main. Providing this flag to non-executables will not produce unexpected results.

set(hpx_libs hpx_wrap)
set_target_properties(${target} PROPERTIES LINK_FLAGS "-Wl,-wrap=__libc_start_main")
endif()
set(hpx_libs ${hpx_libs} hpx)
if(NOT target_STATIC_LINKING)
set(hpx_libs ${hpx_libs})
if(NOT nohpxinit)
Expand All @@ -203,9 +207,6 @@ function(hpx_setup_target target)
if(DEFINED HPX_LIBRARIES)
set(hpx_libs ${hpx_libs} ${HPX_LIBRARIES})
endif()
if(HPX_WITH_DYNAMIC_HPX_MAIN AND (("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") AND ("${_type}" STREQUAL "EXECUTABLE")))
set_target_properties(${target} PROPERTIES LINK_FLAGS "-Wl,-wrap=__libc_start_main")
endif()
else()
target_compile_options(${target} PUBLIC ${CXX_FLAG})
endif()
Expand Down
5 changes: 5 additions & 0 deletions cmake/templates/HPXConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,8 @@ if(HPX_WITH_CUDA)
set(HPX_CUDA_CLANG_FLAGS @HPX_CUDA_CLANG_FLAGS@)
cuda_include_directories("@HPX_CMAKE_CONF_INCLUDE_DIRS@")
endif()

# Add HPX linker flag to CMAKE_EXE_LINKER_FLAGS
if(HPX_WITH_DYNAMIC_HPX_MAIN AND ("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux"))
set(CMAKE_EXE_LINKER_FLAGS "@CMAKE_EXE_LINKER_FLAGS@ @HPX_LINKER_FLAGS@")
endif()
69 changes: 68 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,16 @@ add_hpx_library_sources(hpx
GLOB_RECURSE GLOBS "${PROJECT_SOURCE_DIR}/src/compat/*.cpp"
APPEND)

# libhpx_wrap sources
if(HPX_WITH_DYNAMIC_HPX_MAIN AND ("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux"))
add_hpx_library_sources (hpx_Wrap
GLOB GLOBS "${PROJECT_SOURCE_DIR}/src/hpx_wrap.cpp")
endif()

# libhpx_init sources
add_hpx_library_sources(hpx_init
GLOB GLOBS "${PROJECT_SOURCE_DIR}/src/hpx_*.cpp"
EXCLUDE "hpx_init[.]cpp")
EXCLUDE "hpx_init[.]cpp|hpx_wrap.cpp")
add_hpx_library_sources(hpx_init
GLOB GLOBS "${PROJECT_SOURCE_DIR}/src/util/lightweight_test.cpp"
APPEND)
Expand Down Expand Up @@ -156,6 +162,14 @@ add_hpx_source_group(
ROOT "${PROJECT_SOURCE_DIR}/hpx"
TARGETS ${hpx_HEADERS})

if(HPX_WITH_DYNAMIC_HPX_MAIN AND ("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux"))
add_hpx_source_group(
NAME hpx_wrap
CLASS "Source Files"
ROOT "${PROECT_SOURCE_DIR}/src"
TARGETS "${PROECT_SOURCE_DIR}/src/hpx_wrap.cpp")
endif()

add_hpx_source_group(
NAME hpx_init
CLASS "Source Files"
Expand Down Expand Up @@ -316,11 +330,64 @@ foreach(_flag ${HPX_TARGET_COMPILE_DEFINITIONS_VAR})
endif()
endforeach()

################################################################################
# libhpx_wrap

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of this should be disabled for anything but Linux

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh yes! forgot that.

if(HPX_WITH_DYNAMIC_HPX_MAIN AND ("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux"))
if(NOT HPX_WITH_STATIC_LINKING)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
if(HPX_WITH_DEFAULT_TARGETS)
if(HPX_WITH_CUDA)
cuda_add_library(hpx_wrap STATIC
"${PROJECT_SOURCE_DIR}/src/hpx_wrap.cpp")
else()
add_library(hpx_wrap STATIC
"${PROJECT_SOURCE_DIR}/src/hpx_wrap.cpp")
endif()
else()
if(HPX_WITH_CUDA)
cuda_add_library(hpx_wrap STATIC EXCLUDE_FROM_ALL
"${PROJECT_SOURCE_DIR}/src/hpx_wrap.cpp")
else()
add_library(hpx_wrap STATIC EXCLUDE_FROM_ALL
"${PROJECT_SOURCE_DIR}/src/hpx_wrap.cpp")
endif()
endif()

set_property(TARGET hpx_wrap APPEND
PROPERTY COMPILE_DEFINITIONS
"HPX_APPLICATION_EXPORTS"
"HPX_ENABLE_ASSERT_HANDLER")

set_property(TARGET hpx_wrap PROPERTY FOLDER "Core")
set(hpx_targets ${hpx_targets} hpx_wrap)
endif()

endif()

get_property(HPX_TARGET_COMPILE_DEFINITIONS_VAR
GLOBAL PROPERTY HPX_TARGET_COMPILE_DEFINITIONS)
foreach(_flag ${HPX_TARGET_COMPILE_DEFINITIONS_VAR})
target_compile_definitions(hpx INTERFACE ${_flag})
target_compile_definitions(hpx PUBLIC ${_flag})
if(HPX_WITH_DYNAMIC_HPX_MAIN AND ("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux"))
target_compile_definitions(hpx_wrap INTERFACE ${_flag})
target_compile_definitions(hpx_wrap PUBLIC ${_flag})
endif()
if(NOT HPX_WITH_STATIC_LINKING)
target_compile_definitions(hpx_init PUBLIC ${_flag})
endif()
endforeach()

get_property(HPX_TARGET_COMPILE_OPTIONS_VAR
GLOBAL PROPERTY HPX_TARGET_COMPILE_OPTIONS)
foreach(_flag ${HPX_TARGET_COMPILE_OPTIONS_VAR})
target_compile_options(hpx INTERFACE ${_flag})
target_compile_options(hpx PUBLIC ${_flag})
if(HPX_WITH_DYNAMIC_HPX_MAIN AND ("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux"))
target_compile_options(hpx_wrap INTERFACE ${_flag})
target_compile_options(hpx_wrap PUBLIC ${_flag})
endif()
if(NOT HPX_WITH_STATIC_LINKING)
target_compile_options(hpx_init PUBLIC ${_flag})
endif()
Expand Down