Skip to content

Commit

Permalink
Using target_link_libraries for cmake versions >= 3.12
Browse files Browse the repository at this point in the history
  • Loading branch information
hkaiser committed Oct 30, 2019
1 parent 78a0f8b commit cbeb3cd
Show file tree
Hide file tree
Showing 13 changed files with 135 additions and 41 deletions.
38 changes: 30 additions & 8 deletions cmake/HPX_SetupAllocator.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
# 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)

include(HPX_AddDefinitions)

if(NOT HPX_WITH_MALLOC)
set(HPX_WITH_MALLOC CACHE STRING
"Use the specified allocator. Supported allocators are tcmalloc, jemalloc, tbbmalloc and system."
Expand All @@ -34,8 +36,12 @@ if(NOT HPX_WITH_MALLOC_DEFAULT)
hpx_error(${allocator_error})
endif()

set_property(TARGET hpx::allocator PROPERTY
INTERFACE_LINK_LIBRARIES ${TCMALLOC_LIBRARIES})
if(${CMAKE_VERSION} VERSION_LESS "3.12.0")
set_property(TARGET hpx::allocator PROPERTY
INTERFACE_LINK_LIBRARIES ${TCMALLOC_LIBRARIES})
else()
target_link_libraries(hpx::allocator INTERFACE ${TCMALLOC_LIBRARIES})
endif()

if(MSVC)
hpx_add_link_flag_if_available(/INCLUDE:__tcmalloc)
Expand All @@ -48,11 +54,16 @@ if(NOT HPX_WITH_MALLOC_DEFAULT)
if(NOT JEMALLOC_LIBRARIES)
hpx_error(${allocator_error})
endif()

set_property(TARGET hpx::allocator PROPERTY
INTERFACE_INCLUDE_DIRECTORIES ${JEMALLOC_INCLUDE_DIR}
${JEMALLOC_ADDITIONAL_INCLUDE_DIR})
set_property(TARGET hpx::allocator PROPERTY
INTERFACE_LINK_LIBRARIES ${JEMALLOC_LIBRARIES})
if(${CMAKE_VERSION} VERSION_LESS "3.12.0")
set_property(TARGET hpx::allocator PROPERTY
INTERFACE_LINK_LIBRARIES ${JEMALLOC_LIBRARIES})
else()
target_link_libraries(hpx::allocator INTERFACE ${JEMALLOC_LIBRARIES})
endif()
endif()

if("${HPX_WITH_MALLOC_UPPER}" STREQUAL "MIMALLOC")
Expand All @@ -78,13 +89,20 @@ if(NOT HPX_WITH_MALLOC_DEFAULT)
if(MSVC)
hpx_add_link_flag_if_available(/INCLUDE:__TBB_malloc_proxy)
endif()
set_property(TARGET hpx::allocator PROPERTY
INTERFACE_LINK_LIBRARIES ${TBBMALLOC_LIBRARY} ${TBBMALLOC_PROXY_LIBRARY})
if(${CMAKE_VERSION} VERSION_LESS "3.12.0")
set_property(TARGET hpx::allocator PROPERTY
INTERFACE_LINK_LIBRARIES ${TBBMALLOC_LIBRARY} ${TBBMALLOC_PROXY_LIBRARY})
else()
target_link_libraries(hpx::allocator INTERFACE
${TBBMALLOC_LIBRARY} ${TBBMALLOC_PROXY_LIBRARY})
endif()
endif()

if("${HPX_WITH_MALLOC_UPPER}" STREQUAL "CUSTOM")
set(_use_custom_allocator TRUE)
endif()
else()
set(HPX_WITH_MALLOC ${HPX_WITH_MALLOC_DEFAULT})
endif()

if("${HPX_WITH_MALLOC_UPPER}" MATCHES "SYSTEM")
Expand All @@ -106,8 +124,12 @@ if((NOT HPX_WITH_APEX) AND HPX_WITH_ITTNOTIFY)
add_library(hpx::amplifier INTERFACE IMPORTED)
set_property(TARGET hpx::amplifier PROPERTY
INTERFACE_INCLUDE_DIRECTORIES ${AMPLIFIER_INCLUDE_DIR})
set_property(TARGET hpx::amplifier PROPERTY
INTERFACE_LINK_LIBRARIES ${AMPLIFIER_LIBRARIES})
if(${CMAKE_VERSION} VERSION_LESS "3.12.0")
set_property(TARGET hpx::amplifier PROPERTY
INTERFACE_LINK_LIBRARIES ${AMPLIFIER_LIBRARIES})
else()
target_link_libraries(hpx::allocator INTERFACE ${AMPLIFIER_LIBRARIES})
endif()

hpx_add_config_define(HPX_HAVE_ITTNOTIFY 1)
hpx_add_config_define(HPX_HAVE_THREAD_DESCRIPTION)
Expand Down
17 changes: 10 additions & 7 deletions cmake/HPX_SetupBoost.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,6 @@ if(Boost_VERSION_STRING VERSION_LESS 1.70)
set(__boost_libraries ${__boost_libraries} system)
endif()

if(HPX_PARCELPORT_VERBS_WITH_LOGGING OR HPX_PARCELPORT_VERBS_WITH_DEV_MODE OR
HPX_PARCELPORT_LIBFABRIC_WITH_LOGGING OR HPX_PARCELPORT_LIBFABRIC_WITH_DEV_MODE)
set(__boost_libraries ${__boost_libraries} log log_setup date_time chrono thread)
endif()

# Set configuration option to use Boost.Context or not. This depends on the
# platform.
set(__use_generic_coroutine_context OFF)
Expand Down Expand Up @@ -113,10 +108,18 @@ if(HPX_PLATFORM_UC STREQUAL "XEONPHI")
endif()

set_property(TARGET hpx::boost APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${Boost_INCLUDE_DIRS})
set_property(TARGET hpx::boost APPEND PROPERTY INTERFACE_LINK_LIBRARIES ${Boost_LIBRARIES})
if(${CMAKE_VERSION} VERSION_LESS "3.12.0")
set_property(TARGET hpx::boost APPEND PROPERTY INTERFACE_LINK_LIBRARIES ${Boost_LIBRARIES})
else()
target_link_libraries(hpx::boost INTERFACE ${Boost_LIBRARIES})
endif()

find_package(Threads QUIET REQUIRED)
set_property(TARGET hpx::boost APPEND PROPERTY INTERFACE_LINK_LIBRARIES Threads::Threads)
if(${CMAKE_VERSION} VERSION_LESS "3.12.0")
set_property(TARGET hpx::boost APPEND PROPERTY INTERFACE_LINK_LIBRARIES Threads::Threads)
else()
target_link_libraries(hpx::boost INTERFACE Threads::Threads)
endif()

# If we compile natively for the MIC, we need some workarounds for certain
# Boost headers
Expand Down
12 changes: 10 additions & 2 deletions cmake/HPX_SetupBoostFilesystem.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,16 @@ if(HPX_FILESYSTEM_WITH_BOOST_FILESYSTEM_COMPATIBILITY)
endif()

add_library(hpx::boost::filesystem INTERFACE IMPORTED)
set_property(TARGET hpx::boost::filesystem PROPERTY INTERFACE_LINK_LIBRARIES
${Boost_FILESYSTEM_LIBRARIES})

set_property(TARGET hpx::boost::filesystem APPEND PROPERTY
INTERFACE_INCLUDE_DIRECTORIES ${Boost_INCLUDE_DIRS})
if(${CMAKE_VERSION} VERSION_LESS "3.12.0")
set_property(TARGET hpx::boost::filesystem PROPERTY INTERFACE_LINK_LIBRARIES
${Boost_FILESYSTEM_LIBRARIES})
else()
target_link_libraries(hpx::boost::filesystem INTERFACE
${Boost_FILESYSTEM_LIBRARIES})
endif()

else()
if(NOT HPX_WITH_CXX17_FILESYSTEM)
Expand Down
11 changes: 10 additions & 1 deletion cmake/HPX_SetupBoostIostreams.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,17 @@ if(HPX_WITH_COMPRESSION_BZIP2 OR HPX_WITH_COMPRESSION_ZLIB)
endif()

add_library(hpx::boost::iostreams INTERFACE IMPORTED)

# Can't directly link to "iostreams" target in set_property, can change is when using target_link_libraries

set_property(TARGET hpx::boost::iostreams APPEND PROPERTY
INTERFACE_LINK_LIBRARIES ${Boost_IOSTREAMS_LIBRARIES})
INTERFACE_INCLUDE_DIRECTORIES ${Boost_INCLUDE_DIRS})
if(${CMAKE_VERSION} VERSION_LESS "3.12.0")
set_property(TARGET hpx::boost::iostreams APPEND PROPERTY
INTERFACE_LINK_LIBRARIES ${Boost_IOSTREAMS_LIBRARIES})
else()
target_link_libraries(hpx::boost::iostreams INTERFACE
${Boost_IOSTREAMS_LIBRARIES})
endif()

endif()
11 changes: 10 additions & 1 deletion cmake/HPX_SetupBoostProgramOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ if(HPX_PROGRAM_OPTIONS_WITH_BOOST_PROGRAM_OPTIONS_COMPATIBILITY)
endif()

add_library(hpx::boost::program_options INTERFACE IMPORTED)
set_property(TARGET hpx::boost::program_options PROPERTY INTERFACE_LINK_LIBRARIES ${Boost_PROGRAM_OPTIONS_LIBRARIES})

set_property(TARGET hpx::boost::program_options APPEND PROPERTY
INTERFACE_INCLUDE_DIRECTORIES ${Boost_INCLUDE_DIRS})
if(${CMAKE_VERSION} VERSION_LESS "3.12.0")
set_property(TARGET hpx::boost::program_options PROPERTY INTERFACE_LINK_LIBRARIES
${Boost_PROGRAM_OPTIONS_LIBRARIES})
else()
target_link_libraries(hpx::boost::program_options INTERFACE
${Boost_PROGRAM_OPTIONS_LIBRARIES})
endif()

endif()
11 changes: 9 additions & 2 deletions cmake/HPX_SetupBoostRegex.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,12 @@ else()
endif()

add_library(hpx::boost::regex INTERFACE IMPORTED)
set_property(TARGET hpx::boost::regex PROPERTY INTERFACE_LINK_LIBRARIES
${Boost_REGEX_LIBRARIES})

set_property(TARGET hpx::boost::regex APPEND PROPERTY
INTERFACE_INCLUDE_DIRECTORIES ${Boost_INCLUDE_DIRS})
if(${CMAKE_VERSION} VERSION_LESS "3.12.0")
set_property(TARGET hpx::boost::regex PROPERTY INTERFACE_LINK_LIBRARIES
${Boost_REGEX_LIBRARIES})
else()
target_link_libraries(hpx::boost::regex INTERFACE ${Boost_REGEX_LIBRARIES})
endif()
9 changes: 7 additions & 2 deletions cmake/HPX_SetupGooglePerfTools.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ if(HPX_WITH_GOOGLE_PERFTOOLS)
add_library(hpx::gperftools INTERFACE IMPORTED)
set_property(TARGET hpx::gperftools PROPERTY
INTERFACE_INCLUDE_DIRECTORIES ${GOOGLE_PERFTOOLS_INCLUDE_DIR})
set_property(TARGET hpx::gperftools PROPERTY
INTERFACE_LINK_LIBRARIES ${GOOGLE_PERFTOOLS_LIBRARIES})
if(${CMAKE_VERSION} VERSION_LESS "3.12.0")
set_property(TARGET hpx::gperftools PROPERTY
INTERFACE_LINK_LIBRARIES ${GOOGLE_PERFTOOLS_LIBRARIES})
else()
target_link_libraries(hpx::gperftools INTERFACE ${GOOGLE_PERFTOOLS_LIBRARIES})
endif()

endif()
6 changes: 5 additions & 1 deletion cmake/HPX_SetupHwloc.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,8 @@ add_library(hpx::hwloc INTERFACE IMPORTED)
# System has been removed when passing at set_property for cmake < 3.11
# instead of target_include_directories
set_property(TARGET hpx::hwloc PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${HWLOC_INCLUDE_DIR})
set_property(TARGET hpx::hwloc PROPERTY INTERFACE_LINK_LIBRARIES ${HWLOC_LIBRARIES})
if(${CMAKE_VERSION} VERSION_LESS "3.12.0")
set_property(TARGET hpx::hwloc PROPERTY INTERFACE_LINK_LIBRARIES ${HWLOC_LIBRARIES})
else()
target_link_libraries(hpx::hwloc INTERFACE ${HWLOC_LIBRARIES})
endif()
8 changes: 6 additions & 2 deletions cmake/HPX_SetupLibfabric.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@ if (HPX_WITH_PARCELPORT_LIBFABRIC)
add_library(hpx::libfabric INTERFACE IMPORTED)
set_property(TARGET hpx::libfabric PROPERTY
INTERFACE_INCLUDE_DIRECTORIES ${LIBFABRIC_INCLUDE_DIR})
set_property(TARGET hpx::libfabric PROPERTY
INTERFACE_LINK_LIBRARIES ${LIBFABRIC_LIBRARY})

if(${CMAKE_VERSION} VERSION_LESS "3.12.0")
set_property(TARGET hpx::libfabric PROPERTY INTERFACE_LINK_LIBRARIES ${LIBFABRIC_LIBRARY})
else()
target_link_libraries(hpx::libfabric INTERFACE ${LIBFABRIC_LIBRARY})
endif()


# Setup PMI imported target
Expand Down
26 changes: 19 additions & 7 deletions cmake/HPX_SetupMPI.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,29 @@ if(HPX_WITH_NETWORKING AND HPX_WITH_PARCELPORT_MPI)
INTERFACE_INCLUDE_DIRECTORIES ${MPI_INCLUDE_PATH} ${MPI_CXX_INCLUDE_DIRS})
# MPI_LIBRARY and EXTRA is deprecated but still linked for older MPI versions
if (MPI_CXX_LIBRARIES)
set_property(TARGET hpx::mpi APPEND PROPERTY
INTERFACE_LINK_LIBRARIES ${MPI_CXX_LIBRARIES})
if(${CMAKE_VERSION} VERSION_LESS "3.12.0")
set_property(TARGET hpx::mpi APPEND PROPERTY
INTERFACE_LINK_LIBRARIES ${MPI_CXX_LIBRARIES})
else()
target_link_libraries(hpx::mpi INTERFACE ${MPI_CXX_LIBRARIES})
endif()
endif()
# Insure compatibility with older versions
# Ensure compatibility with older versions
if (MPI_LIBRARY)
set_property(TARGET hpx::mpi APPEND PROPERTY
INTERFACE_LINK_LIBRARIES ${MPI_LIBRARY})
if(${CMAKE_VERSION} VERSION_LESS "3.12.0")
set_property(TARGET hpx::mpi APPEND PROPERTY
INTERFACE_LINK_LIBRARIES ${MPI_LIBRARY})
else()
target_link_libraries(hpx::mpi INTERFACE ${MPI_LIBRARY})
endif()
endif()
if (MPI_EXTRA_LIBRARY)
set_property(TARGET hpx::mpi APPEND PROPERTY
INTERFACE_LINK_LIBRARIES ${MPI_EXTRA_LIBRARY})
if(${CMAKE_VERSION} VERSION_LESS "3.12.0")
set_property(TARGET hpx::mpi APPEND PROPERTY
INTERFACE_LINK_LIBRARIES ${MPI_EXTRA_LIBRARY})
else()
target_link_libraries(hpx::mpi INTERFACE ${MPI_EXTRA_LIBRARY})
endif()
endif()
set_property(TARGET hpx::mpi PROPERTY INTERFACE_COMPILE_OPTIONS ${MPI_CXX_COMPILE_FLAGS})
set_property(TARGET hpx::mpi PROPERTY INTERFACE_COMPILE_DEFINITIONS ${MPI_CXX_COMPILE_DEFINITIONS})
Expand Down
7 changes: 5 additions & 2 deletions cmake/HPX_SetupPapi.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ if(HPX_WITH_PAPI)
add_library(hpx::papi INTERFACE IMPORTED)
set_property(TARGET hpx::papi PROPERTY
INTERFACE_INCLUDE_DIRECTORIES ${PAPI_INCLUDE_DIR})
set_property(TARGET hpx::papi PROPERTY
INTERFACE_LINK_LIBRARIES ${PAPI_LIBRARY})
if(${CMAKE_VERSION} VERSION_LESS "3.12.0")
set_property(TARGET hpx::papi PROPERTY INTERFACE_LINK_LIBRARIES ${PAPI_LIBRARY})
else()
target_link_libraries(hpx::papi INTERFACE ${PAPI_LIBRARY})
endif()
endif()
10 changes: 8 additions & 2 deletions cmake/HPX_SetupVc.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ add_library(hpx::vc INTERFACE IMPORTED)
set_property(TARGET hpx::vc PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${Vc_INCLUDE_DIR})

if(NOT HPX_WITH_DATAPAR_VC_NO_LIBRARY)
set_property(TARGET hpx::vc PROPERTY INTERFACE_LINK_LIBRARIES ${Vc_LIBRARIES})
if(${CMAKE_VERSION} VERSION_LESS "3.12.0")
set_property(TARGET hpx::vc PROPERTY INTERFACE_LINK_LIBRARIES ${Vc_LIBRARIES})
else()
target_link_libraries(hpx::vc INTERFACE ${Vc_LIBRARIES})
endif()
endif()

foreach(_flag ${Vc_DEFINITIONS})
Expand All @@ -72,11 +76,13 @@ foreach(_flag ${Vc_DEFINITIONS})
set_property(TARGET hpx::vc APPEND PROPERTY INTERFACE_COMPILE_DEFINITIONS ${_flag})
endforeach()

include(HPX_AddDefinitions)

# do not include Vc build flags for MSVC builds as this breaks building the
# core HPX libraries itself
if(NOT MSVC)
set_property(TARGET hpx::vc PROPERTY INTERFACE_COMPILE_OPTIONS ${Vc_COMPILE_FLAGS} ${Vc_ARCHITECTURE_FLAGS})
else()
else()
hpx_add_config_cond_define(_SILENCE_ALL_CXX17_DEPRECATION_WARNINGS)
endif()

Expand Down
10 changes: 6 additions & 4 deletions cmake/templates/HPXMacros.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,15 @@ function(hpx_setup_allocator)
if(HPX_DISABLE_CUSTOM_ALLOCATOR)
return()
endif()
if(DEFINED HPX_WITH_MALLOC)
if(HPX_WITH_MALLOC)
string(TOUPPER "${HPX_WITH_MALLOC}" HPX_MALLOC_UPPER)
string(TOUPPER "${HPX_WITH_MALLOC_DEFAULT}" HPX_MALLOC_DEFAULT_UPPER)
if(NOT HPX_MALLOC_UPPER STREQUAL HPX_MALLOC_DEFAULT_UPPER)
hpx_error("The specified allocators do not match. This Project is configured with ${HPX_WITH_MALLOC} and HPX was configured with ${HPX_WITH_MALLOC_DEFAULT}.")
if(NOT (HPX_MALLOC_UPPER STREQUAL HPX_MALLOC_DEFAULT_UPPER))
hpx_error("The specified allocators do not match. This Project is configured with '${HPX_WITH_MALLOC}' and HPX was configured with '${HPX_WITH_MALLOC_DEFAULT}'.")
endif()
endif()
set(HPX_WITH_MALLOC ${HPX_WITH_MALLOC_DEFAULT} CACHE STRING "Define which allocator should be linked in. Options are: system, tcmalloc, jemalloc, tbbmalloc, and custom (default is: tcmalloc)")
set(HPX_WITH_MALLOC ${HPX_WITH_MALLOC_DEFAULT} CACHE STRING
"Define which allocator should be linked in. Options are: system, tcmalloc, jemalloc, tbbmalloc, and custom (default is: tcmalloc)"
STRINGS "system;tcmalloc;jemalloc;mimalloc;tbbmalloc;custom")
include(HPX_SetupAllocator)
endfunction()

0 comments on commit cbeb3cd

Please sign in to comment.