summaryrefslogtreecommitdiffstats
path: root/Tests/RunCMake/SharedLibraryDefines/common.cmake
blob: 21e4cc860a2b104948ff328f0906331c8522f073 (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
enable_language(${language})

function(sharedLibraryDefs_addTests policy_value)
  block(SCOPE_FOR POLICIES)
    if (NOT "${policy_value}" STREQUAL "WARN")
      # WARN is the default value - no need to set it
      cmake_policy(SET CMP0203 "${policy_value}")
    endif()

    add_executable(${language}-CMP0203_${policy_value} checker.${extension})
    target_compile_definitions(${language}-CMP0203_${policy_value} PRIVATE "FUNCTION=main")

    add_library(${language}-CMP0203_${policy_value}_shared SHARED checker.${extension})
    target_compile_definitions(${language}-CMP0203_${policy_value}_shared PRIVATE "FUNCTION=test")

    add_library(${language}-CMP0203_${policy_value}_static STATIC checker.${extension})
    target_compile_definitions(${language}-CMP0203_${policy_value}_static PRIVATE "FUNCTION=test")
  endblock()
endfunction()

sharedLibraryDefs_addTests(OLD)
sharedLibraryDefs_addTests(WARN)

if (CMAKE_GENERATOR MATCHES "Visual Studio")
  # Visual Studio always defines `_WINDLL`
  target_compile_definitions(${language}-CMP0203_OLD_shared PRIVATE "MUST_HAVE_DEFINE")
  target_compile_definitions(${language}-CMP0203_WARN_shared PRIVATE "MUST_HAVE_DEFINE")
endif()

sharedLibraryDefs_addTests(NEW)

if ("${CMAKE_${language}_COMPILER_ID}" STREQUAL "MSVC" OR "${CMAKE_${language}_SIMULATE_ID}" STREQUAL "MSVC")
  target_compile_definitions(${language}-CMP0203_NEW_shared PRIVATE "MUST_HAVE_DEFINE")
endif()