Skip to content

Commit fb747b7

Browse files
committed
Resolve xtl in user cmake
1 parent f925249 commit fb747b7

2 files changed

Lines changed: 43 additions & 11 deletions

File tree

CMakeLists.txt

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ cmake_minimum_required(VERSION 3.13)
1313

1414
project(xsimd)
1515

16+
OPTION(ENABLE_XTL_COMPLEX "enables support for xcomplex defined in xtl" OFF)
17+
OPTION(BUILD_TESTS "xsimd test suite" OFF)
18+
1619
# Versioning
1720
# ==========
1821

@@ -37,14 +40,18 @@ target_include_directories(xsimd INTERFACE
3740
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
3841
$<INSTALL_INTERFACE:include>)
3942

40-
OPTION(ENABLE_XTL_COMPLEX "enables support for xcomplex defined in xtl" OFF)
41-
OPTION(BUILD_TESTS "xsimd test suite" OFF)
42-
4343
target_compile_features(xsimd INTERFACE cxx_std_14)
44+
45+
# Only add xtl build option to the build tree, that is if xsimd being locally
46+
# developed or is vendored.
47+
# Otherwise (if an install is performed), this will the handled in the user
48+
# cmake script (xsimdConfig.cmake).
4449
if(ENABLE_XTL_COMPLEX)
4550
find_package(xtl 0.8.0 REQUIRED)
46-
target_compile_definitions(xsimd INTERFACE XSIMD_ENABLE_XTL_COMPLEX=1)
47-
target_link_libraries(xsimd INTERFACE xtl)
51+
target_link_libraries(xsimd INTERFACE $<BUILD_INTERFACE:xtl>)
52+
target_compile_definitions(xsimd INTERFACE
53+
$<BUILD_INTERFACE:XSIMD_ENABLE_XTL_COMPLEX=1>
54+
)
4855
endif()
4956

5057
if(BUILD_TESTS)

xsimdConfig.cmake.in

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,37 @@
1818
@PACKAGE_INIT@
1919

2020
if(NOT TARGET @PROJECT_NAME@)
21-
set(@PROJECT_NAME@_ENABLE_XTL_COMPLEX @ENABLE_XTL_COMPLEX@)
22-
if(@PROJECT_NAME@_ENABLE_XTL_COMPLEX)
23-
include(CMakeFindDependencyMacro)
24-
find_dependency(xtl REQUIRED)
21+
include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake")
22+
get_target_property(
23+
@PROJECT_NAME@_INCLUDE_DIRS
24+
@PROJECT_NAME@ INTERFACE_INCLUDE_DIRECTORIES
25+
)
26+
27+
# xsimd <= 14 behaviour.
28+
# Packagers that configured xsimd for their users with ENABLE_XTL_COMPLEX
29+
# have it automatically enabled.
30+
# Can be removed in xsimd 15. Keeping it with a version check so we do not
31+
# miss the opportunity to remove it in the next major release.
32+
# Compared to legacy version, users can now override the check
33+
# with XSIMD_ENABLE_XTL_COMPLEX.
34+
if(
35+
@ENABLE_XTL_COMPLEX@
36+
AND @XSIMD_VERSION_MAJOR@ LESS_EQUAL 14
37+
AND NOT DEFINED XSIMD_ENABLE_XTL_COMPLEX
38+
)
39+
# The next check will handle adding it to the target
40+
set(XSIMD_ENABLE_XTL_COMPLEX @ENABLE_XTL_COMPLEX@)
2541
endif()
2642

27-
include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake")
28-
get_target_property(@PROJECT_NAME@_INCLUDE_DIRS @PROJECT_NAME@ INTERFACE_INCLUDE_DIRECTORIES)
43+
# Final users of xsimd in a package manager control whether or not to
44+
# enable xtl with this variable.
45+
if(XSIMD_ENABLE_XTL_COMPLEX)
46+
include(CMakeFindDependencyMacro)
47+
find_dependency(xtl 0.8.0 REQUIRED)
48+
target_link_libraries(@PROJECT_NAME@ INTERFACE xtl)
49+
target_compile_definitions(
50+
@PROJECT_NAME@
51+
INTERFACE XSIMD_ENABLE_XTL_COMPLEX=1
52+
)
53+
endif()
2954
endif()

0 commit comments

Comments
 (0)