Skip to content

Commit

Permalink
Always build and export the cudf::cudftestutil target (#7574)
Browse files Browse the repository at this point in the history
We should always build the static `cudftestutil` target regardless of whether `BUILD_TESTS=ON` was passed.

Needed by #7484 and rapidsai/cuspatial#365.

Authors:
  - Paul Taylor (@trxcllnt)

Approvers:
  - Keith Kraus (@kkraus14)

URL: #7574
  • Loading branch information
trxcllnt authored Mar 17, 2021
1 parent 57a7a8f commit 5f12732
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 74 deletions.
66 changes: 37 additions & 29 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ include(cmake/Modules/ConfigureCUDA.cmake)

# find zlib
find_package(ZLIB REQUIRED)
# find Threads (needed by cudftestutil)
find_package(Threads REQUIRED)
# add third party dependencies using CPM
include(cmake/thirdparty/CUDF_GetCPM.cmake)
# find boost
Expand All @@ -133,6 +135,8 @@ include(cmake/thirdparty/CUDF_GetArrow.cmake)
include(cmake/thirdparty/CUDF_GetDLPack.cmake)
# find libcu++
include(cmake/thirdparty/CUDF_GetLibcudacxx.cmake)
# find or install GoogleTest
include(cmake/thirdparty/CUDF_GetGTest.cmake)
# Stringify libcudf and libcudacxx headers used in JIT operations
include(cmake/Modules/StringifyJITHeaders.cmake)

Expand Down Expand Up @@ -417,7 +421,8 @@ target_include_directories(cudf
"$<BUILD_INTERFACE:${CUDF_SOURCE_DIR}/include>"
"$<BUILD_INTERFACE:${CUDF_GENERATED_INCLUDE_DIR}/include>"
PRIVATE "$<BUILD_INTERFACE:${CUDF_SOURCE_DIR}/src>"
INTERFACE "$<INSTALL_INTERFACE:include>")
INTERFACE "$<INSTALL_INTERFACE:include>"
"$<INSTALL_INTERFACE:include/libcudf/libcudaxx>")

# Add Conda library paths if specified
if(CONDA_LINK_DIRS)
Expand Down Expand Up @@ -480,34 +485,37 @@ add_library(cudf::cudf ALIAS cudf)
# - tests and benchmarks --------------------------------------------------------------------------
###################################################################################################

if (CUDF_BUILD_TESTS OR CUDF_BUILD_BENCHMARKS)
# Find or install GoogleTest
CPMFindPackage(NAME GTest
VERSION 1.10.0
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG release-1.10.0
GIT_SHALLOW TRUE
OPTIONS "INSTALL_GTEST OFF"
# googletest >= 1.10.0 provides a cmake config file -- use it if it exists
FIND_PACKAGE_ARGUMENTS "CONFIG")
# Add GTest aliases if they don't already exist.
# Assumes if GTest::gtest doesn't exist, the others don't either.
# TODO: Is this always a valid assumption?
if(NOT TARGET GTest::gtest)
add_library(GTest::gtest ALIAS gtest)
add_library(GTest::gmock ALIAS gmock)
add_library(GTest::gtest_main ALIAS gtest_main)
add_library(GTest::gmock_main ALIAS gmock_main)
endif()
if(GTest_ADDED)
install(TARGETS gmock
gtest
gmock_main
gtest_main
DESTINATION lib
EXPORT cudf-targets)
endif()
endif()
###################################################################################################
# - build cudftestutil ----------------------------------------------------------------------------

add_library(cudftestutil STATIC
tests/utilities/base_fixture.cpp
tests/utilities/column_utilities.cu
tests/utilities/table_utilities.cu
tests/strings/utilities.cu)

target_compile_options(cudftestutil
PUBLIC "$<$<COMPILE_LANGUAGE:CXX>:${CUDF_CXX_FLAGS}>"
"$<$<COMPILE_LANGUAGE:CUDA>:${CUDF_CUDA_FLAGS}>"
)

target_compile_features(cudftestutil PUBLIC cxx_std_14 cuda_std_14)

target_link_libraries(cudftestutil
PUBLIC GTest::gmock
GTest::gtest
Threads::Threads
cudf)

target_include_directories(cudftestutil
PUBLIC "$<BUILD_INTERFACE:${CUDF_SOURCE_DIR}>"
"$<BUILD_INTERFACE:${CUDF_SOURCE_DIR}/src>")

install(TARGETS cudftestutil
DESTINATION lib
EXPORT cudf-targets)

add_library(cudf::cudftestutil ALIAS cudftestutil)

###################################################################################################
# - add tests -------------------------------------------------------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions cpp/cmake/cudf-build-config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ include(@CUDF_SOURCE_DIR@/cmake/thirdparty/CUDF_GetThrust.cmake)
# find rmm
set(CUDF_MIN_VERSION_rmm "${CUDF_VERSION_MAJOR}.${CUDF_VERSION_MINOR}")
include(@CUDF_SOURCE_DIR@/cmake/thirdparty/CUDF_GetRMM.cmake)
# find gtest
include(@CUDF_SOURCE_DIR@/cmake/thirdparty/CUDF_GetGTest.cmake)

# find arrow
if(NOT EXISTS "${CMAKE_CURRENT_LIST_DIR}/cudf-arrow-targets.cmake")
Expand Down
7 changes: 1 addition & 6 deletions cpp/cmake/cudf-config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,8 @@ find_dependency(Arrow @CUDF_VERSION_Arrow@)
find_dependency(ArrowCUDA @CUDF_VERSION_Arrow@)
find_dependency(Boost @CUDF_MIN_VERSION_Boost@)

find_dependency(jitify)
find_dependency(rmm @CUDF_MIN_VERSION_rmm@)
find_dependency(Thrust @CUDF_MIN_VERSION_Thrust@)
find_dependency(dlpack @CUDF_MIN_VERSION_dlpack@)
find_dependency(libcudacxx @CUDF_MIN_VERSION_libcudacxx@)

thrust_create_target(cudf::Thrust FROM_OPTIONS)
find_dependency(gtest @CUDF_MIN_VERSION_gtest@)

list(POP_FRONT CMAKE_MODULE_PATH)

Expand Down
11 changes: 11 additions & 0 deletions cpp/cmake/thirdparty/CUDF_GetCPM.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,14 @@ if(NOT (EXISTS ${CPM_DOWNLOAD_LOCATION}))
endif()

include(${CPM_DOWNLOAD_LOCATION})

# If a target is installed, found by the `find_package` step of CPMFindPackage,
# and marked as IMPORTED, make it globally accessible to consumers of our libs.
function(fix_cmake_global_defaults target)
if(TARGET ${target})
get_target_property(_is_imported ${target} IMPORTED)
if(_is_imported)
set_target_properties(${target} PROPERTIES IMPORTED_GLOBAL TRUE)
endif()
endif()
endfunction()
53 changes: 53 additions & 0 deletions cpp/cmake/thirdparty/CUDF_GetGTest.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#=============================================================================
# Copyright (c) 2021, NVIDIA CORPORATION.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#=============================================================================

function(find_and_configure_gtest VERSION)
# Find or install GoogleTest
CPMFindPackage(NAME GTest
VERSION ${VERSION}
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG release-${VERSION}
GIT_SHALLOW TRUE
OPTIONS "INSTALL_GTEST OFF"
# googletest >= 1.10.0 provides a cmake config file -- use it if it exists
FIND_PACKAGE_ARGUMENTS "CONFIG")
# Add GTest aliases if they don't already exist.
# Assumes if GTest::gtest doesn't exist, the others don't either.
# TODO: Is this always a valid assumption?
if(NOT TARGET GTest::gtest)
add_library(GTest::gtest ALIAS gtest)
add_library(GTest::gmock ALIAS gmock)
add_library(GTest::gtest_main ALIAS gtest_main)
add_library(GTest::gmock_main ALIAS gmock_main)
endif()
# Make sure consumers of cudf can also see GTest::* targets
fix_cmake_global_defaults(GTest::gtest)
fix_cmake_global_defaults(GTest::gmock)
fix_cmake_global_defaults(GTest::gtest_main)
fix_cmake_global_defaults(GTest::gmock_main)
if(GTest_ADDED)
install(TARGETS gmock
gtest
gmock_main
gtest_main
DESTINATION lib
EXPORT cudf-targets)
endif()
endfunction()

set(CUDF_MIN_VERSION_gtest 1.10.0)

find_and_configure_gtest(${CUDF_MIN_VERSION_gtest})
10 changes: 3 additions & 7 deletions cpp/cmake/thirdparty/CUDF_GetRMM.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,9 @@ function(find_and_configure_rmm VERSION)
cudf_restore_if_enabled(BUILD_TESTS)
cudf_restore_if_enabled(BUILD_BENCHMARKS)

#Make sure consumers of cudf can also see rmm::rmm
if(TARGET rmm::rmm)
get_target_property(rmm_is_imported rmm::rmm IMPORTED)
if(rmm_is_imported)
set_target_properties(rmm::rmm PROPERTIES IMPORTED_GLOBAL TRUE)
endif()
endif()
# Make sure consumers of cudf can also see rmm::rmm
fix_cmake_global_defaults(rmm::rmm)

if(NOT rmm_BINARY_DIR IN_LIST CMAKE_PREFIX_PATH)
list(APPEND CMAKE_PREFIX_PATH "${rmm_BINARY_DIR}")
set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} PARENT_SCOPE)
Expand Down
32 changes: 0 additions & 32 deletions cpp/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,38 +14,6 @@
# limitations under the License.
#=============================================================================

###################################################################################################
# - common test utils -----------------------------------------------------------------------------

find_package(Threads REQUIRED)

add_library(cudftestutil STATIC
utilities/base_fixture.cpp
utilities/column_utilities.cu
utilities/table_utilities.cu
strings/utilities.cu)

target_compile_options(cudftestutil
PUBLIC "$<$<COMPILE_LANGUAGE:CXX>:${CUDF_CXX_FLAGS}>"
"$<$<COMPILE_LANGUAGE:CUDA>:${CUDF_CUDA_FLAGS}>"
)

target_compile_features(cudftestutil PUBLIC cxx_std_14 cuda_std_14)

target_link_libraries(cudftestutil
PUBLIC GTest::gmock
GTest::gtest
Threads::Threads
cudf)

target_include_directories(cudftestutil
PUBLIC "$<BUILD_INTERFACE:${CUDF_SOURCE_DIR}>"
"$<BUILD_INTERFACE:${CUDF_SOURCE_DIR}/src>")

install(TARGETS cudftestutil
DESTINATION lib
EXPORT cudf-targets)

###################################################################################################
# - compiler function -----------------------------------------------------------------------------

Expand Down

0 comments on commit 5f12732

Please sign in to comment.