summaryrefslogtreecommitdiffstats
path: root/Tests/RunCMake/CXXModules/examples/export-usage-build/CMakeLists.txt
blob: a58e2872133f58c2eab91af4b4110fb47cb2772f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
cmake_minimum_required(VERSION 3.24...3.28)
project(cxx_modules_export_usage CXX)

include("${CMAKE_SOURCE_DIR}/../cxx-modules-rules.cmake")

add_library(export_usage STATIC)
target_sources(export_usage
  PRIVATE
    forward.cxx
  PRIVATE
    FILE_SET modules_private TYPE CXX_MODULES
      BASE_DIRS
        "${CMAKE_CURRENT_SOURCE_DIR}"
      FILES
        private.cxx
  PUBLIC
    FILE_SET modules TYPE CXX_MODULES
      BASE_DIRS
        "${CMAKE_CURRENT_SOURCE_DIR}"
      FILES
        importable.cxx)
target_compile_features(export_usage PUBLIC cxx_std_20)

list(APPEND CMAKE_CXX_KNOWN_FEATURES
  exported
  buildiface
  installiface
  buildlocaliface)

target_include_directories(export_usage
  PRIVATE
    "/usr/exported"
    "$<BUILD_INTERFACE:/usr/buildiface>"
    "$<INSTALL_INTERFACE:/usr/installiface>"
    "$<BUILD_LOCAL_INTERFACE:/usr/buildlocaliface>")
target_compile_definitions(export_usage
  PRIVATE
    "exported"
    "$<BUILD_INTERFACE:buildiface>"
    "$<INSTALL_INTERFACE:installiface>"
    "$<BUILD_LOCAL_INTERFACE:buildlocaliface>")
target_compile_features(export_usage
  PRIVATE
    "cxx_std_11"
    "$<BUILD_INTERFACE:cxx_std_14>"
    "$<INSTALL_INTERFACE:cxx_std_17>"
    "$<BUILD_LOCAL_INTERFACE:cxx_std_20>")

if (MSVC)
  set(variable_flag "-constexpr:depth")
else ()
  set(variable_flag "-fconstexpr-depth=")
endif ()

target_compile_options(export_usage
  PRIVATE
    "${variable_flag}100"
    "$<BUILD_INTERFACE:${variable_flag}200>"
    "$<INSTALL_INTERFACE:${variable_flag}300>"
    "$<BUILD_LOCAL_INTERFACE:${variable_flag}400>")

add_library(export_used INTERFACE)
add_library(export_build INTERFACE)
add_library(export_install INTERFACE)
add_library(export_never INTERFACE)

target_link_libraries(export_usage
  PRIVATE
    "export_used"
    "$<BUILD_INTERFACE:export_build>"
    "$<INSTALL_INTERFACE:export_install>"
    "$<BUILD_LOCAL_INTERFACE:export_never>")

install(TARGETS export_usage
  EXPORT CXXModules
  FILE_SET modules DESTINATION "lib/cxx/miu")
export(EXPORT CXXModules
  NAMESPACE CXXModules::
  FILE "${CMAKE_CURRENT_BINARY_DIR}/export_usage-targets.cmake")
install(TARGETS export_used export_build export_install
  EXPORT CXXModulesDeps)
export(EXPORT CXXModulesDeps
  NAMESPACE CXXModules::
  FILE "${CMAKE_CURRENT_BINARY_DIR}/export_usage-dep-targets.cmake")
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/export_usage-config.cmake"
  "include(\"\${CMAKE_CURRENT_LIST_DIR}/export_usage-dep-targets.cmake\")
include(\"\${CMAKE_CURRENT_LIST_DIR}/export_usage-targets.cmake\")
set(\${CMAKE_FIND_PACKAGE_NAME}_FOUND 1)
")

set(generator
  -G "${CMAKE_GENERATOR}")
if (CMAKE_GENERATOR_TOOLSET)
  list(APPEND generator
    -T "${CMAKE_GENERATOR_TOOLSET}")
endif ()
if (CMAKE_GENERATOR_PLATFORM)
  list(APPEND generator
    -A "${CMAKE_GENERATOR_PLATFORM}")
endif ()

add_test(NAME export_usage_build
  COMMAND
    "${CMAKE_COMMAND}"
    "-Dexpected_dir=${CMAKE_CURRENT_SOURCE_DIR}"
    "-Dexport_interfaces_flag=${variable_flag}"
    "-Dexport_usage_DIR=${CMAKE_CURRENT_BINARY_DIR}"
    ${generator}
    -S "${CMAKE_CURRENT_SOURCE_DIR}/test"
    -B "${CMAKE_CURRENT_BINARY_DIR}/test")