Optional find dependency in installed cmake config. (#7099)

* Find dependency only when xgboost is built as static library.
* Resolve msvc warning.
* Add test for linking shared library.
This commit is contained in:
Jiaming Yuan
2021-07-11 17:20:55 +08:00
committed by GitHub
parent 1d91f71119
commit 345796825f
15 changed files with 222 additions and 171 deletions

View File

@@ -1,5 +1,14 @@
cmake_minimum_required(VERSION 3.13)
project(api-demo LANGUAGES C CXX VERSION 0.0.1)
project(api-demo LANGUAGES C VERSION 0.0.1)
find_package(xgboost REQUIRED)
# xgboost is built as static libraries, all cxx dependencies need to be linked into the
# executable.
if (XGBOOST_BUILD_STATIC_LIB)
enable_language(CXX)
# find again for those cxx libraries.
find_package(xgboost REQUIRED)
endif(XGBOOST_BUILD_STATIC_LIB)
add_executable(api-demo c-api-demo.c)
target_link_libraries(api-demo PRIVATE xgboost::xgboost)