summaryrefslogtreecommitdiff
path: root/Tests/RunCMake/target_link_libraries-LINK_LANGUAGE/genex.cmake
blob: 22d3df73809c49eb29d6c3765d75cfba6b8adc1b (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

cmake_minimum_required(VERSION 3.16...3.17)

enable_language(C)
enable_language(CXX)

add_library(shared_C SHARED func.c)
add_library(shared_CXX SHARED func.cxx)

add_library(static_cxx STATIC func.cxx)
target_compile_definitions(static_cxx PRIVATE BUILD_STATIC)

add_library(static1_C STATIC empty.c)
target_link_libraries (static1_C INTERFACE $<$<LINK_LANGUAGE:C>:shared_C>)

add_library(static2_C STATIC empty.c)
target_link_libraries (static2_C PRIVATE $<$<LINK_LANGUAGE:C>:shared_C>)


set (binary_dir "${CMAKE_BINARY_DIR}")
get_property (is_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
if (is_multi_config)
  string (APPEND binary_dir "/Release")
endif()
add_library(import STATIC IMPORTED)
set_property(TARGET import PROPERTY IMPORTED_LOCATION "${binary_dir}/${CMAKE_STATIC_LIBRARY_PREFIX}static1_C${CMAKE_STATIC_LIBRARY_SUFFIX}")
target_link_libraries (import INTERFACE $<$<LINK_LANGUAGE:C>:shared_C>)
target_link_libraries (import INTERFACE $<$<LINK_LANGUAGE:CXX>:shared_CXX>)


add_library(interface INTERFACE)
target_link_libraries (interface INTERFACE $<$<LINK_LANGUAGE:C>:shared_C>
                                           $<$<LINK_LANGUAGE:CXX>:shared_CXX>)


add_library(interface2 INTERFACE)
target_link_libraries (interface2 INTERFACE import)


add_library(static3 STATIC empty.c)
target_link_libraries (static3 PRIVATE interface)


add_library(LinkLibraries_lib SHARED lib.c)
target_link_libraries (LinkLibraries_lib PRIVATE $<$<LINK_LANGUAGE:C>:shared_C>)

add_library(LinkLibraries_lib2 SHARED lib.c)
target_link_libraries (LinkLibraries_lib2 PRIVATE $<$<LINK_LANGUAGE:C>:static1_C>)

add_library(LinkLibraries_lib3 SHARED lib.c)
target_link_libraries (LinkLibraries_lib3 PRIVATE $<$<LINK_LANGUAGE:C>:static2_C>)

add_executable(LinkLibraries_exe main.c)
target_link_libraries (LinkLibraries_exe PRIVATE $<$<LINK_LANGUAGE:C>:shared_C>)

add_executable(LinkLibraries_C_import main.c)
target_link_libraries (LinkLibraries_C_import PRIVATE import)
add_executable(LinkLibraries_CXX_import main.cxx)
target_link_libraries (LinkLibraries_CXX_import PRIVATE import)

add_executable(LinkLibraries_C_interface main.c)
target_link_libraries (LinkLibraries_C_interface PRIVATE interface)
add_executable(LinkLibraries_CXX_interface main.cxx)
target_link_libraries (LinkLibraries_CXX_interface PRIVATE interface)

add_executable(LinkLibraries_C_interface2 main.c)
target_link_libraries (LinkLibraries_C_interface2 PRIVATE interface2)
add_executable(LinkLibraries_CXX_interface2 main.cxx)
target_link_libraries (LinkLibraries_CXX_interface2 PRIVATE interface2)

add_executable(LinkLibraries_C_static main.c)
target_link_libraries (LinkLibraries_C_static PRIVATE static3)
add_executable(LinkLibraries_CXX_static main.cxx)
target_link_libraries (LinkLibraries_CXX_static PRIVATE static3)

# $<LINK_LANGUAGE:> change, by default, link language from C to CXX
# but because LINKER_LANGUAGE property is set, keep C as link language
add_executable(LinkLibraries_C_static_CXX main.c)
target_compile_definitions (LinkLibraries_C_static_CXX PRIVATE C_USE_CXX)
target_link_libraries (LinkLibraries_C_static_CXX PRIVATE $<$<LINK_LANGUAGE:C>:static_cxx>)
set_property(TARGET LinkLibraries_C_static_CXX PROPERTY LINKER_LANGUAGE C)