summaryrefslogtreecommitdiffstats
path: root/Tests/RunCMake/target_link_libraries-ALIAS/AliasTargets.cmake
blob: 65c708c631d4f77051e6ba733ade51e1c2efdd14 (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
enable_language(C)

add_library (func SHARED func.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-local SHARED IMPORTED)
set_property(TARGET import-local PROPERTY IMPORTED_LOCATION "${binary_dir}/${CMAKE_STATIC_LIBRARY_PREFIX}func${CMAKE_SHARED_LIBRARY_SUFFIX}")
set_property(TARGET import-local PROPERTY IMPORTED_IMPLIB "${binary_dir}/${CMAKE_STATIC_LIBRARY_PREFIX}func${CMAKE_IMPORT_LIBRARY_SUFFIX}")
add_library(alias::local ALIAS import-local)

if(NOT DEFINED CMAKE_IMPORT_LIBRARY_SUFFIX)
  add_library(import-local-stub SHARED IMPORTED)
  set_property(TARGET import-local-stub PROPERTY IMPORTED_IMPLIB "${binary_dir}/${CMAKE_STATIC_LIBRARY_PREFIX}func${CMAKE_SHARED_LIBRARY_SUFFIX}")
  add_library(alias::local-stub ALIAS import-local-stub)
endif()

add_library (lib-local SHARED lib.c)
target_link_libraries (lib-local PRIVATE alias::local $<TARGET_NAME_IF_EXISTS:alias::local-stub>)

add_executable (main-local main.c)
target_link_libraries (main-local PRIVATE alias::local)


add_library(import-global SHARED IMPORTED GLOBAL)
set_property(TARGET import-global PROPERTY IMPORTED_LOCATION "${binary_dir}/${CMAKE_STATIC_LIBRARY_PREFIX}func${CMAKE_SHARED_LIBRARY_SUFFIX}")
set_property(TARGET import-global PROPERTY IMPORTED_IMPLIB "${binary_dir}/${CMAKE_STATIC_LIBRARY_PREFIX}func${CMAKE_IMPORT_LIBRARY_SUFFIX}")
add_library(alias::global ALIAS import-global)

add_library (lib-global SHARED lib.c)
target_link_libraries (lib-global PRIVATE alias::global)

add_executable (main-global main.c)
target_link_libraries (main-global PRIVATE alias::global)


add_subdirectory(sub_dir)