Skip to content

Commit

Permalink
Build system fixes (#214)
Browse files Browse the repository at this point in the history
- remove absolute rpath when SKBUILD/SPACK_BUILD
- add hatchet/tests/timemory_tests.py to cmake_proces_manifest
- tweaks to {dl,rt,pthread}_LIBRARY
- warn about PYBIND11_INSTALL
- timemory-{c,cxx,fortran} alias libraries in build tree
- fixes to building timemory-{mpip,ncclp,mallocp}-shared when static cxx
  • Loading branch information
jrmadsen committed Jul 9, 2021
1 parent 41f6de0 commit 0ce6be2
Show file tree
Hide file tree
Showing 16 changed files with 169 additions and 78 deletions.
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,10 @@ set(CMAKE_INSTALL_CONFIGDIR ${CMAKE_INSTALL_DATAROOTDIR}/cmake/${PROJECT_NAME})

if(UNIX AND NOT APPLE)
set(CMAKE_INSTALL_RPATH
"\$ORIGIN/../${CMAKE_INSTALL_LIBDIR}:\$ORIGIN/timemory:\$ORIGIN:${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}:${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/timemory")
"\$ORIGIN/../${CMAKE_INSTALL_LIBDIR}:\$ORIGIN/timemory:\$ORIGIN")
if(NOT SKBUILD AND NOT SPACK_BUILD)
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_RPATH}:${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}:${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/timemory")
endif()
endif()

# create the full path version and generic path versions
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.2.1.rc14
3.2.1.rc15
56 changes: 41 additions & 15 deletions cmake/Modules/BuildSettings.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,54 @@ include_guard(DIRECTORY)

include(GNUInstallDirs)
include(Compilers)
include(FindPackageHandleStandardArgs)

target_compile_definitions(timemory-compile-options INTERFACE $<$<CONFIG:DEBUG>:DEBUG>)

if(CMAKE_DL_LIBS)
set(dl_LIBRARY ${CMAKE_DL_LIBS})
target_link_libraries(timemory-compile-options INTERFACE ${CMAKE_DL_LIBS})
else()
find_library(dl_LIBRARY NAMES dl)
#----------------------------------------------------------------------------------------#
# dynamic linking and runtime libraries
#
if(CMAKE_DL_LIBS AND NOT "${CMAKE_DL_LIBS}" STREQUAL "dl")
# if cmake provides dl library, use that
set(dl_LIBRARY ${CMAKE_DL_LIBS} CACHE FILEPATH "dynamic linking system library")
endif()

foreach(_TYPE dl rt dw)
if(NOT ${_TYPE}_LIBRARY)
find_library(${_TYPE}_LIBRARY NAMES ${_TYPE})
endif()
endforeach()

find_package_handle_standard_args(dl-library REQUIRED_VARS dl_LIBRARY)
find_package_handle_standard_args(rt-library REQUIRED_VARS rt_LIBRARY)
# find_package_handle_standard_args(dw-library REQUIRED_VARS dw_LIBRARY)

if(TIMEMORY_BUILD_PORTABLE)
if(dl_LIBRARY)
target_link_libraries(timemory-compile-options INTERFACE ${dl_LIBRARY})
set(dl_LIBRARY dl)
else()
set(dl_LIBRARY)
endif()
elseif(dl_LIBRARY)
add_rpath(${dl_LIBRARY})
endif()

if(dl_LIBRARY)
target_link_libraries(timemory-compile-options INTERFACE ${dl_LIBRARY})
endif()

if(TIMEMORY_BUILD_PORTABLE)
if(rt_LIBRARY)
set(rt_LIBRARY rt)
else()
set(rt_LIBRARY)
endif()
elseif(rt_LIBRARY)
add_rpath(${rt_LIBRARY})
endif()

#----------------------------------------------------------------------------------------#

if(WIN32)
set(OS_FLAG "/bigobj")
else()
Expand Down Expand Up @@ -72,15 +107,6 @@ endif()
add_interface_library(timemory-compile-debuginfo
"Attempts to set best flags for more expressive profiling information in debug or optimized binaries")

# if cmake provides dl library, use that
if(CMAKE_DL_LIBS)
set(dl_LIBRARY "${CMAKE_DL_LIBS}" CACHE STRING "dynamic linking libraries")
endif()

find_library(rt_LIBRARY NAMES rt)
find_library(dl_LIBRARY NAMES dl)
find_library(dw_LIBRARY NAMES dw)

add_target_flag_if_avail(timemory-compile-debuginfo
"-g"
"-fno-omit-frame-pointer"
Expand Down
42 changes: 26 additions & 16 deletions cmake/Modules/ConfigCUDA.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -157,28 +157,38 @@ if("CUDA" IN_LIST LANGUAGES)
${CUDA_INCLUDE_DIRS}
${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES})

find_library(CUDA_dl_LIBRARY
NAMES dl)
if(NOT CUDA_dl_LIBRARY)
if(dl_LIBRARY)
set(CUDA_dl_LIBRARY ${dl_LIBRARY})
else()
find_library(CUDA_dl_LIBRARY NAMES dl)
endif()
endif()

target_link_libraries(${PROJECT_CUDA_INTERFACE_PREFIX}-cudart INTERFACE
${CUDA_CUDART_LIBRARY} ${CUDA_rt_LIBRARY})
if(NOT CUDA_rt_LIBRARY)
if(rt_LIBRARY)
set(CUDA_rt_LIBRARY ${rt_LIBRARY})
else()
find_library(CUDA_rt_LIBRARY NAMES rt)
endif()
endif()

target_link_libraries(${PROJECT_CUDA_INTERFACE_PREFIX}-cudart-device INTERFACE
${CUDA_cudadevrt_LIBRARY} ${CUDA_rt_LIBRARY})
if(NOT CUDA_dl_LIBRARY)
set(CUDA_dl_LIBRARY)
endif()

target_link_libraries(${PROJECT_CUDA_INTERFACE_PREFIX}-cudart-static INTERFACE
${CUDA_cudart_static_LIBRARY} ${CUDA_rt_LIBRARY})
if(NOT CUDA_rt_LIBRARY)
set(CUDA_rt_LIBRARY)
endif()

if(CUDA_dl_LIBRARY)
target_link_libraries(${PROJECT_CUDA_INTERFACE_PREFIX}-cudart INTERFACE
${CUDA_dl_LIBRARY})
target_link_libraries(${PROJECT_CUDA_INTERFACE_PREFIX}-cudart INTERFACE
${CUDA_CUDART_LIBRARY} ${CUDA_rt_LIBRARY} ${CUDA_dl_LIBRARY})

target_link_libraries(${PROJECT_CUDA_INTERFACE_PREFIX}-cudart-device INTERFACE
${CUDA_dl_LIBRARY})
target_link_libraries(${PROJECT_CUDA_INTERFACE_PREFIX}-cudart-device INTERFACE
${CUDA_cudadevrt_LIBRARY} ${CUDA_rt_LIBRARY} ${CUDA_dl_LIBRARY})

target_link_libraries(${PROJECT_CUDA_INTERFACE_PREFIX}-cudart-static INTERFACE
${CUDA_dl_LIBRARY})
endif()
target_link_libraries(${PROJECT_CUDA_INTERFACE_PREFIX}-cudart-static INTERFACE
${CUDA_cudart_static_LIBRARY} ${CUDA_rt_LIBRARY} ${CUDA_dl_LIBRARY})

else()
message(FATAL_ERROR
Expand Down
3 changes: 3 additions & 0 deletions cmake/Modules/Options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,9 @@ if(TIMEMORY_BUILD_DOCS)
endif()

set(PYBIND11_INSTALL OFF CACHE BOOL "Install Pybind11")
if(PYBIND11_INSTALL AND (SKBUILD OR SPACK_BUILD))
timemory_message(WARNING "Pybind11 will be installed. This may overwrite an existing pip/conda/spack PyBind11 installation...")
endif()

# clang-tidy
macro(_TIMEMORY_ACTIVATE_CLANG_TIDY)
Expand Down
7 changes: 4 additions & 3 deletions cmake/Modules/Packages.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -526,15 +526,16 @@ if(NOT WIN32)
set(THREADS_PREFER_PTHREAD_FLAG OFF)
endif()

find_library(PTHREADS_LIBRARY pthread)
find_library(pthread_LIBRARY NAMES pthread pthreads)
find_package_handle_standard_args(pthread-library REQUIRED_VARS pthread_LIBRARY)
find_package(Threads ${TIMEMORY_FIND_QUIETLY} ${TIMEMORY_FIND_REQUIREMENT})

if(Threads_FOUND)
target_link_libraries(timemory-threading INTERFACE ${CMAKE_THREAD_LIBS_INIT})
endif()

if(PTHREADS_LIBRARY AND NOT WIN32)
target_link_libraries(timemory-threading INTERFACE ${PTHREADS_LIBRARY})
if(NOT TIMEMORY_BUILD_PORTABLE AND pthread_LIBRARY AND NOT WIN32)
target_link_libraries(timemory-threading INTERFACE ${pthread_LIBRARY})
endif()


Expand Down
7 changes: 7 additions & 0 deletions external/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,19 @@ if(TIMEMORY_USE_PYTHON AND TIMEMORY_BUILD_PYTHON_HATCHET)
add_dependencies(libpytimemory hatchet)
if(CMAKE_INSTALL_PYTHONDIR)
set(HATCHET_PYDIR "${CMAKE_CURRENT_LIST_DIR}/hatchet/hatchet")

file(GLOB_RECURSE hatchet_files
"${HATCHET_PYDIR}/*.py"
"${HATCHET_PYDIR}/*.js")

file(GLOB_RECURSE hatchet_test_files
"${HATCHET_PYDIR}/tests/*")

if("${HATCHET_PYDIR}/tests/timemory_test.py" IN_LIST hatchet_test_files)
list(REMOVE_ITEM hatchet_test_files
"${HATCHET_PYDIR}/tests/timemory_test.py")
endif()

set(HATCHET_CYTHONDIR
"${HATCHET_PYDIR}/cython_modules/libs")

Expand Down
36 changes: 20 additions & 16 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,30 +385,34 @@ def parse_requirements(fname="requirements.txt"):
# --------------------------------------------------------------------------- #
#
def exclude_install_hook(cmake_manifest):
cmake_manifest = list(
filter(lambda name: "pytest.ini" not in name, cmake_manifest)
def _filter_manifest(_manifest, *args):
for itr in args:
_manifest = list(
filter(
lambda name: itr not in name,
cmake_manifest,
)
)
return _manifest

cmake_manifest = _filter_manifest(
cmake_manifest,
"pytest.ini",
os.path.join("hatchet", "tests", "timemory_test.py"),
)
if not get_bool_option(args, "develop"):
cmake_manifest = list(
filter(lambda name: not (name.endswith(".a")), cmake_manifest)
)
if not get_bool_option(args, "install-config"):
cmake_manifest = list(
filter(
lambda name: (os.path.join("share", "cmake") not in name),
cmake_manifest,
)
)
cmake_manifest = list(
filter(
lambda name: (os.path.join("lib", "cmake") not in name),
cmake_manifest,
)
cmake_manifest = _filter_manifest(
cmake_manifest,
os.path.join("share", "cmake"),
os.path.join("lib", "cmake"),
)
if not get_bool_option(args, "install-headers"):
cmake_manifest = list(
filter(lambda name: "include" not in name, cmake_manifest)
)
cmake_manifest = _filter_manifest(cmake_manifest, "include")

return cmake_manifest


Expand Down
18 changes: 18 additions & 0 deletions source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,20 @@ if(TIMEMORY_BUILD_FORTRAN)
endif()
endif()

#----------------------------------------------------------------------------------------#
#
# Language aliases libraries
#
#----------------------------------------------------------------------------------------#

foreach(_LANG c cxx fortran)
if(TARGET timemory-${_LANG}-shared)
add_library(timemory::timemory-${_LANG} ALIAS timemory-${_LANG}-shared)
elseif(TARGET timemory-${_LANG}-static)
add_library(timemory::timemory-${_LANG} ALIAS timemory-${_LANG}-static)
endif()
endforeach()

#----------------------------------------------------------------------------------------#
#
# TOOL executables and libraries
Expand Down Expand Up @@ -392,6 +406,7 @@ if(TARGET timemory-mpip-shared)
list(APPEND TIMEMORY_TOOL_LIBRARIES timemory-mpip-shared)
else()
inform_empty_interface(timemory-mpip-library "MPIP standalone instrumentation library")
set(TIMEMORY_BUILD_MPIP_LIBRARY OFF PARENT_SCOPE)
endif()

if(_OMPT_LIB)
Expand All @@ -400,6 +415,7 @@ if(_OMPT_LIB)
target_link_libraries(timemory-ompt-library INTERFACE timemory-ompt ${_OMPT_LIB})
else()
inform_empty_interface(timemory-ompt-library "OpenMP stand-alone instrumentation library")
set(TIMEMORY_BUILD_OMPT_LIBRARY OFF PARENT_SCOPE)
endif()

if(TARGET timemory-ncclp-shared)
Expand All @@ -409,6 +425,7 @@ if(TARGET timemory-ncclp-shared)
list(APPEND TIMEMORY_TOOL_LIBRARIES timemory-ncclp-shared)
else()
inform_empty_interface(timemory-ncclp-library "NCCLP standalone instrumentation library")
set(TIMEMORY_BUILD_NCCLP_LIBRARY OFF PARENT_SCOPE)
endif()

if(TARGET timemory-mallocp-shared)
Expand All @@ -418,6 +435,7 @@ if(TARGET timemory-mallocp-shared)
list(APPEND TIMEMORY_TOOL_LIBRARIES timemory-mallocp-shared)
else()
inform_empty_interface(timemory-mallocp-library "MALLOCP standalone instrumentation library")
set(TIMEMORY_BUILD_MALLOCP_LIBRARY OFF PARENT_SCOPE)
endif()

if(TARGET timemory-compiler-instrument-base)
Expand Down
12 changes: 10 additions & 2 deletions source/tools/timemory-mallocp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
cmake_minimum_required(VERSION 3.15 FATAL_ERROR)

if(NOT TIMEMORY_USE_GOTCHA OR NOT TARGET timemory::timemory-cxx-shared)
if(NOT TIMEMORY_USE_GOTCHA OR
(BUILD_STATIC_LIBS AND NOT BUILD_SHARED_LIBS AND NOT CMAKE_POSITION_INDEPENDENT_CODE))
return()
endif()

if(NOT TIMEMORY_BUILD_MALLOCP_LIBRARY OR TIMEMORY_SKIP_BUILD OR TIMEMORY_BUILD_EXCLUDE_FROM_ALL)
set(_EXCLUDE EXCLUDE_FROM_ALL)
endif()

if(NOT TARGET timemory::timemory-cxx)
if(TIMEMORY_BUILD_MALLOCP_LIBRARY)
message(WARNING "timemory-mallocp-library cannot be built due to missing timemory::timemory-cxx target")
endif()
return()
endif()

project(timemory-mallocp-tool)

add_library(timemory-mallocp-shared SHARED ${_EXCLUDE} ${PROJECT_SOURCE_DIR}/timemory-mallocp.cpp)
Expand All @@ -16,7 +24,7 @@ add_library(timemory::timemory-mallocp-shared ALIAS timemory-mallocp-shared)
# public link targets
target_link_libraries(timemory-mallocp-shared PUBLIC
timemory::timemory-headers
timemory::timemory-cxx-shared
timemory::timemory-cxx
timemory::timemory-gotcha)

# private link targets
Expand Down
6 changes: 3 additions & 3 deletions source/tools/timemory-mallocp/timemory-mallocp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@

using namespace tim::component;

using malloc_toolset_t = tim::component_tuple<memory_allocations>;
uint64_t global_cnt = 0;
uint64_t global_id = std::numeric_limits<uint64_t>::max();
using malloc_toolset_t = tim::component_tuple<memory_allocations>;
static uint64_t global_cnt = 0;
static uint64_t global_id = std::numeric_limits<uint64_t>::max();
//
//--------------------------------------------------------------------------------------//
//
Expand Down
12 changes: 10 additions & 2 deletions source/tools/timemory-mpip/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
cmake_minimum_required(VERSION 3.15 FATAL_ERROR)

if(NOT TIMEMORY_USE_GOTCHA OR NOT TIMEMORY_USE_MPI OR NOT TARGET timemory::timemory-cxx-shared)
if(NOT TIMEMORY_USE_GOTCHA OR NOT TIMEMORY_USE_MPI OR
(BUILD_STATIC_LIBS AND NOT BUILD_SHARED_LIBS AND NOT CMAKE_POSITION_INDEPENDENT_CODE))
return()
endif()

if(NOT TIMEMORY_BUILD_MPIP_LIBRARY OR TIMEMORY_SKIP_BUILD OR TIMEMORY_BUILD_EXCLUDE_FROM_ALL)
set(_EXCLUDE EXCLUDE_FROM_ALL)
endif()

if(NOT TARGET timemory::timemory-cxx)
if(TIMEMORY_BUILD_MPIP_LIBRARY)
message(WARNING "timemory-mpip-library cannot be built due to missing timemory::timemory-cxx target")
endif()
return()
endif()

project(timemory-mpip-tool)

add_library(timemory-mpip-shared SHARED ${_EXCLUDE} ${PROJECT_SOURCE_DIR}/timemory-mpip.cpp)
Expand All @@ -16,7 +24,7 @@ add_library(timemory::timemory-mpip-shared ALIAS timemory-mpip-shared)
# public link targets
target_link_libraries(timemory-mpip-shared PUBLIC
timemory::timemory-headers
timemory::timemory-cxx-shared
timemory::timemory-cxx
timemory::timemory-mpi
timemory::timemory-gotcha)

Expand Down
10 changes: 5 additions & 5 deletions source/tools/timemory-mpip/timemory-mpip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ TIMEMORY_DEFINE_CONCRETE_TRAIT(is_memory_category, mpi_data_tracker_t, true_type
//
//--------------------------------------------------------------------------------------//
//
using api_t = TIMEMORY_API;
using mpi_toolset_t = tim::component_tuple<user_mpip_bundle, mpi_comm_data>;
using mpip_handle_t = mpip_handle<mpi_toolset_t, api_t>;
uint64_t global_id = 0;
void* libmpi_handle = nullptr;
using api_t = TIMEMORY_API;
using mpi_toolset_t = tim::component_tuple<user_mpip_bundle, mpi_comm_data>;
using mpip_handle_t = mpip_handle<mpi_toolset_t, api_t>;
static uint64_t global_id = 0;
static void* libmpi_handle = nullptr;
//
//--------------------------------------------------------------------------------------//
//
Expand Down

0 comments on commit 0ce6be2

Please sign in to comment.