summaryrefslogtreecommitdiffstats
path: root/Tests/ExportImport/Import/Interface/CMakeLists.txt
blob: c8c840198389e61f0eb1584ca4a5be85202c2ca0 (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

# Import targets from the exported build tree.
include(${Import_BINARY_DIR}/../Export/ExportInterfaceBuildTree.cmake)

add_library(define_iface INTERFACE)
set_property(TARGET define_iface PROPERTY
  INTERFACE_COMPILE_DEFINITIONS DEFINE_IFACE_DEFINE)

add_executable(headeronlytest_bld headeronlytest.cpp)
target_link_libraries(headeronlytest_bld bld_headeronly)

set_property(TARGET bld_sharediface APPEND PROPERTY INTERFACE_LINK_LIBRARIES define_iface)

add_executable(interfacetest_bld interfacetest.cpp)
target_link_libraries(interfacetest_bld bld_sharediface)

include(CheckCXXSourceCompiles)

macro(do_try_compile prefix)

  set(CMAKE_REQUIRED_LIBRARIES ${prefix}headeronly)
  check_cxx_source_compiles(
    "
  #include \"headeronly.h\"

  #ifndef HEADERONLY_DEFINE
  #error Expected HEADERONLY_DEFINE
  #endif

  int main(int,char**)
  {
    HeaderOnly ho;
    return ho.foo();
  }
  " ${prefix}IFACE_TRY_COMPILE)

  if(NOT ${prefix}IFACE_TRY_COMPILE)
    message(SEND_ERROR "${prefix} try_compile with IMPORTED INTERFACE target failed!\n\n${OUTPUT}")
  endif()
endmacro()

do_try_compile(bld_)