tools/corrosion/cmake/Corrosion.cmake
author unC0Rr
Wed, 20 Nov 2024 21:37:47 +0100
branchtransitional_engine
changeset 16038 d903f8d2395a
parent 16021 6a3dc15b78b9
permissions -rw-r--r--
- Update corrosion - Implement installation of targets imported with corrosion
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
16038
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
     1
cmake_minimum_required(VERSION 3.22)
16021
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
     2
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
     3
list(APPEND CMAKE_MESSAGE_CONTEXT "Corrosion")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
     4
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
     5
message(DEBUG "Using Corrosion ${Corrosion_VERSION} with CMake ${CMAKE_VERSION} "
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
     6
        "and the `${CMAKE_GENERATOR}` Generator"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
     7
)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
     8
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
     9
get_cmake_property(COR_IS_MULTI_CONFIG GENERATOR_IS_MULTI_CONFIG)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    10
set(COR_IS_MULTI_CONFIG "${COR_IS_MULTI_CONFIG}" CACHE BOOL "Do not change this" FORCE)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    11
mark_as_advanced(FORCE COR_IS_MULTI_CONFIG)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    12
16038
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
    13
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
    14
if(NOT COR_IS_MULTI_CONFIG AND DEFINED CMAKE_CONFIGURATION_TYPES)
16021
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    15
    message(WARNING "The Generator is ${CMAKE_GENERATOR}, which is not a multi-config "
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    16
        "Generator, but CMAKE_CONFIGURATION_TYPES is set. Please don't set "
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    17
        "CMAKE_CONFIGURATION_TYPES unless you are using a multi-config Generator."
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    18
    )
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    19
endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    20
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    21
option(CORROSION_VERBOSE_OUTPUT "Enables verbose output from Corrosion and Cargo" OFF)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    22
16038
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
    23
if(DEFINED CORROSION_RESPECT_OUTPUT_DIRECTORY AND NOT CORROSION_RESPECT_OUTPUT_DIRECTORY)
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
    24
    message(WARNING "The option CORROSION_RESPECT_OUTPUT_DIRECTORY was removed."
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
    25
    " Corrosion now always attempts to respect the output directory.")
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
    26
endif()
16021
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    27
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    28
option(
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    29
    CORROSION_NO_WARN_PARSE_TARGET_TRIPLE_FAILED
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    30
    "Surpresses a warning if the parsing the target triple failed."
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    31
    OFF
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    32
)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    33
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    34
find_package(Rust REQUIRED)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    35
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    36
if(CMAKE_GENERATOR MATCHES "Visual Studio"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    37
        AND (NOT CMAKE_VS_PLATFORM_NAME STREQUAL CMAKE_VS_PLATFORM_NAME_DEFAULT)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    38
        AND Rust_VERSION VERSION_LESS "1.54")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    39
    message(FATAL_ERROR "Due to a cargo issue, cross-compiling with a Visual Studio generator and rust versions"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    40
            " before 1.54 is not supported. Rust build scripts would be linked with the cross-compiler linker, which"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    41
            " causes the build to fail. Please upgrade your Rust version to 1.54 or newer.")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    42
endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    43
16038
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
    44
#    message(STATUS "Using Corrosion as a subdirectory")
16021
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    45
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    46
get_property(
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    47
    RUSTC_EXECUTABLE
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    48
    TARGET Rust::Rustc PROPERTY IMPORTED_LOCATION
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    49
)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    50
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    51
get_property(
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    52
    CARGO_EXECUTABLE
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    53
    TARGET Rust::Cargo PROPERTY IMPORTED_LOCATION
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    54
)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    55
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    56
function(_corrosion_bin_target_suffix target_name out_var_suffix)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    57
    get_target_property(hostbuild "${target_name}" ${_CORR_PROP_HOST_BUILD})
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    58
    if((hostbuild AND CMAKE_HOST_WIN32)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    59
       OR ((NOT hostbuild) AND (Rust_CARGO_TARGET_OS STREQUAL "windows")))
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    60
        set(_suffix ".exe")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    61
    elseif(Rust_CARGO_TARGET_OS STREQUAL "vxworks")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    62
        set(_suffix ".vxe")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    63
    else()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    64
        set(_suffix "")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    65
    endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    66
    set(${out_var_suffix} "${_suffix}" PARENT_SCOPE)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    67
endfunction()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    68
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    69
# Do not call this function directly!
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    70
#
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    71
# This function should be called deferred to evaluate target properties late in the configure stage.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    72
# IMPORTED_LOCATION does not support Generator expressions, so we must evaluate the output
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    73
# directory target property value at configure time. This function must be deferred to the end of
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    74
# the configure stage, so we can be sure that the output directory is not modified afterwards.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    75
function(_corrosion_set_imported_location_deferred target_name base_property output_directory_property filename)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    76
    # The output directory property is expected to be set on the exposed target (without postfix),
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    77
    # but we need to set the imported location on the actual library target with postfix.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    78
    if("${target_name}" MATCHES "^(.+)-(static|shared)$")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    79
        set(output_dir_prop_target_name "${CMAKE_MATCH_1}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    80
    else()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    81
        set(output_dir_prop_target_name "${target_name}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    82
    endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    83
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    84
    # Append .exe suffix for executable by-products if the target is windows or if it's a host
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    85
    # build and the host is Windows.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    86
    get_target_property(target_type ${target_name} TYPE)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    87
    if(${target_type} STREQUAL "EXECUTABLE" AND (NOT "${filename}" MATCHES "\.pdb$"))
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    88
        _corrosion_bin_target_suffix(${target_name} "suffix")
16038
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
    89
        string(APPEND filename "${suffix}")
16021
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    90
    endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    91
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    92
    get_target_property(output_directory "${output_dir_prop_target_name}" "${output_directory_property}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    93
    message(DEBUG "Output directory property (target ${output_dir_prop_target_name}): ${output_directory_property} dir: ${output_directory}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    94
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    95
    foreach(config_type ${CMAKE_CONFIGURATION_TYPES})
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    96
        string(TOUPPER "${config_type}" config_type_upper)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    97
        get_target_property(output_dir_curr_config ${output_dir_prop_target_name}
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    98
            "${output_directory_property}_${config_type_upper}"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    99
        )
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   100
        if(output_dir_curr_config)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   101
            set(curr_out_dir "${output_dir_curr_config}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   102
        elseif(output_directory)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   103
            set(curr_out_dir "${output_directory}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   104
        else()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   105
            set(curr_out_dir "${CMAKE_CURRENT_BINARY_DIR}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   106
        endif()
16038
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   107
        string(REPLACE "\$<CONFIG>" "${config_type}" curr_out_dir "${curr_out_dir}")
16021
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   108
        message(DEBUG "Setting ${base_property}_${config_type_upper} for target ${target_name}"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   109
                " to `${curr_out_dir}/${filename}`.")
16038
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   110
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   111
        string(GENEX_STRIP "${curr_out_dir}" stripped_out_dir)
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   112
        if(NOT ("${stripped_out_dir}" STREQUAL "${curr_out_dir}"))
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   113
            message(FATAL_ERROR "${output_directory_property} for target ${output_dir_prop_target_name} "
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   114
                    "contained an unexpected Generator expression. Output dir: `${curr_out_dir}`"
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   115
                "Note: Corrosion only supports the `\$<CONFIG>` generator expression for output directories.")
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   116
        endif()
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   117
16021
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   118
        # For Multiconfig we want to specify the correct location for each configuration
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   119
        set_property(
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   120
            TARGET ${target_name}
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   121
            PROPERTY "${base_property}_${config_type_upper}"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   122
                "${curr_out_dir}/${filename}"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   123
        )
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   124
        set(base_output_directory "${curr_out_dir}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   125
    endforeach()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   126
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   127
    if(NOT COR_IS_MULTI_CONFIG)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   128
        if(output_directory)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   129
            set(base_output_directory "${output_directory}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   130
        else()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   131
            set(base_output_directory "${CMAKE_CURRENT_BINARY_DIR}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   132
        endif()
16038
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   133
        string(REPLACE "\$<CONFIG>" "${CMAKE_BUILD_TYPE}" base_output_directory "${base_output_directory}")
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   134
        string(GENEX_STRIP "${base_output_directory}" stripped_out_dir)
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   135
        if(NOT ("${stripped_out_dir}" STREQUAL "${base_output_directory}"))
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   136
            message(FATAL_ERROR "${output_dir_prop_target_name} for target ${output_dir_prop_target_name} "
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   137
                    "contained an unexpected Generator expression. Output dir: `${base_output_directory}`"
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   138
                    "Note: Corrosion only supports the `\$<CONFIG>` generator expression for output directories.")
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   139
        endif()
16021
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   140
    endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   141
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   142
    message(DEBUG "Setting ${base_property} for target ${target_name}"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   143
                " to `${base_output_directory}/${filename}`.")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   144
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   145
    # IMPORTED_LOCATION must be set regardless of possible overrides. In the multiconfig case,
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   146
    # the last configuration "wins" (IMPORTED_LOCATION is not documented to have Genex support).
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   147
    set_property(
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   148
            TARGET ${target_name}
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   149
            PROPERTY "${base_property}" "${base_output_directory}/${filename}"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   150
        )
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   151
endfunction()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   152
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   153
# Set the imported location of a Rust target.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   154
#
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   155
# Rust targets are built via custom targets / custom commands. The actual artifacts are exposed
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   156
# to CMake as imported libraries / executables that depend on the cargo_build command. For CMake
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   157
# to find the built artifact we need to set the IMPORTED location to the actual location on disk.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   158
# Corrosion tries to copy the artifacts built by cargo to standard locations. The IMPORTED_LOCATION
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   159
# is set to point to the copy, and not the original from the cargo build directory.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   160
#
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   161
# Parameters:
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   162
# - target_name: Name of the Rust target
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   163
# - base_property: Name of the base property - i.e. `IMPORTED_LOCATION` or `IMPORTED_IMPLIB`.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   164
# - output_directory_property: Target property name that determines the standard location for the
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   165
#    artifact.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   166
# - filename of the artifact.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   167
function(_corrosion_set_imported_location target_name base_property output_directory_property filename)
16038
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   168
        cmake_language(EVAL CODE "
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   169
            cmake_language(DEFER
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   170
                CALL
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   171
                _corrosion_set_imported_location_deferred
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   172
                [[${target_name}]]
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   173
                [[${base_property}]]
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   174
                [[${output_directory_property}]]
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   175
                [[${filename}]]
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   176
            )
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   177
        ")
16021
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   178
endfunction()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   179
16038
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   180
function(_corrosion_copy_byproduct_deferred target_name output_dir_prop_names cargo_build_dir file_names)
16021
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   181
    if(ARGN)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   182
        message(FATAL_ERROR "Unexpected additional arguments")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   183
    endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   184
16038
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   185
    foreach(output_dir_prop_name ${output_dir_prop_names})
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   186
        get_target_property(output_dir ${target_name} "${output_dir_prop_name}")
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   187
        if(output_dir)
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   188
            break()
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   189
        endif()
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   190
    endforeach()
16021
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   191
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   192
    # A Genex expanding to the output directory depending on the configuration.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   193
    set(multiconfig_out_dir_genex "")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   194
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   195
    foreach(config_type ${CMAKE_CONFIGURATION_TYPES})
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   196
        string(TOUPPER "${config_type}" config_type_upper)
16038
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   197
        foreach(output_dir_prop_name ${output_dir_prop_names})
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   198
            get_target_property(output_dir_curr_config ${target_name} "${output_dir_prop_name}_${config_type_upper}")
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   199
            if(output_dir_curr_config)
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   200
                break()
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   201
            endif()
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   202
        endforeach()
16021
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   203
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   204
        if(output_dir_curr_config)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   205
            set(curr_out_dir "${output_dir_curr_config}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   206
        elseif(output_dir)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   207
            # Fallback to `output_dir` if specified
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   208
            # Note: Multi-configuration generators append a per-configuration subdirectory to the
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   209
            # specified directory unless a generator expression is used (from CMake documentation).
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   210
            set(curr_out_dir "${output_dir}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   211
        else()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   212
            # Fallback to the default directory. We do not append the configuration directory here
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   213
            # and instead let CMake do this, since otherwise the resolving of dynamic library
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   214
            # imported paths may fail.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   215
            set(curr_out_dir "${CMAKE_CURRENT_BINARY_DIR}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   216
        endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   217
        set(multiconfig_out_dir_genex "${multiconfig_out_dir_genex}$<$<CONFIG:${config_type}>:${curr_out_dir}>")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   218
    endforeach()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   219
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   220
    if(COR_IS_MULTI_CONFIG)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   221
        set(output_dir "${multiconfig_out_dir_genex}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   222
    else()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   223
        if(NOT output_dir)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   224
            # Fallback to default directory.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   225
            set(output_dir "${CMAKE_CURRENT_BINARY_DIR}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   226
        endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   227
    endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   228
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   229
    # Append .exe suffix for executable by-products if the target is windows or if it's a host
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   230
    # build and the host is Windows.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   231
    get_target_property(target_type "${target_name}" TYPE)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   232
    if (target_type STREQUAL "EXECUTABLE")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   233
        list(LENGTH file_names list_len)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   234
        if(NOT list_len EQUAL "1")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   235
            message(FATAL_ERROR
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   236
                    "Internal error: Exactly one filename should be passed for executable types.")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   237
        endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   238
        _corrosion_bin_target_suffix(${target_name} "suffix")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   239
        if(suffix AND (NOT "${file_names}" MATCHES "\.pdb$"))
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   240
            # For executable targets we know / checked that only one file will be passed.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   241
            string(APPEND file_names "${suffix}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   242
        endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   243
    endif()
16038
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   244
    set(src_file_names "${file_names}")
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   245
    if(Rust_CARGO_TARGET_ENV STREQUAL "gnullvm")
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   246
        # Workaround for cargo not exposing implibs yet.
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   247
        list(TRANSFORM src_file_names PREPEND "deps/" REGEX "\.dll\.a$")
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   248
    endif()
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   249
    list(TRANSFORM src_file_names PREPEND "${cargo_build_dir}/")
16021
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   250
    list(TRANSFORM file_names PREPEND "${output_dir}/" OUTPUT_VARIABLE dst_file_names)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   251
    message(DEBUG "Adding command to copy byproducts `${file_names}` to ${dst_file_names}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   252
    add_custom_command(TARGET _cargo-build_${target_name}
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   253
                        POST_BUILD
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   254
                        # output_dir may contain a Generator expression.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   255
                        COMMAND  ${CMAKE_COMMAND} -E make_directory "${output_dir}"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   256
                        COMMAND
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   257
                        ${CMAKE_COMMAND} -E copy_if_different
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   258
                            # tested to work with both multiple files and paths with spaces
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   259
                            ${src_file_names}
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   260
                            "${output_dir}"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   261
                        BYPRODUCTS ${dst_file_names}
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   262
                        COMMENT "Copying byproducts `${file_names}` to ${output_dir}"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   263
                        VERBATIM
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   264
                        COMMAND_EXPAND_LISTS
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   265
    )
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   266
endfunction()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   267
16038
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   268
# Copy the artifacts generated by cargo to the appropriate destination.
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   269
#
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   270
# Parameters:
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   271
# - target_name: The name of the Rust target
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   272
# - output_dir_prop_names: The property name(s) controlling the destination (e.g.
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   273
#   `LIBRARY_OUTPUT_DIRECTORY` or `PDB_OUTPUT_DIRECTORY;RUNTIME_OUTPUT_DIRECTORY`)
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   274
# - cargo_build_dir: the directory cargo build places it's output artifacts in.
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   275
# - filenames: the file names of any output artifacts as a list.
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   276
function(_corrosion_copy_byproducts target_name output_dir_prop_names cargo_build_dir file_names)
16021
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   277
        cmake_language(EVAL CODE "
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   278
            cmake_language(DEFER
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   279
                CALL
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   280
                _corrosion_copy_byproduct_deferred
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   281
                [[${target_name}]]
16038
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   282
                [[${output_dir_prop_names}]]
16021
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   283
                [[${cargo_build_dir}]]
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   284
                [[${file_names}]]
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   285
            )
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   286
        ")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   287
endfunction()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   288
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   289
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   290
# Add targets for the static and/or shared libraries of the rust target.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   291
# The generated byproduct names are returned via the `OUT_<type>_BYPRODUCTS` arguments.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   292
function(_corrosion_add_library_target)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   293
    set(OPTIONS "")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   294
    set(ONE_VALUE_KEYWORDS
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   295
        WORKSPACE_MANIFEST_PATH
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   296
        TARGET_NAME
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   297
        OUT_ARCHIVE_OUTPUT_BYPRODUCTS
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   298
        OUT_SHARED_LIB_BYPRODUCTS
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   299
        OUT_PDB_BYPRODUCT
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   300
    )
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   301
    set(MULTI_VALUE_KEYWORDS LIB_KINDS)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   302
    cmake_parse_arguments(PARSE_ARGV 0 CALT "${OPTIONS}" "${ONE_VALUE_KEYWORDS}" "${MULTI_VALUE_KEYWORDS}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   303
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   304
    if(DEFINED CALT_UNPARSED_ARGUMENTS)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   305
        message(FATAL_ERROR "Internal error - unexpected arguments: ${CALT_UNPARSED_ARGUMENTS}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   306
    elseif(DEFINED CALT_KEYWORDS_MISSING_VALUES)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   307
        message(FATAL_ERROR "Internal error - the following keywords had no associated value(s):"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   308
            "${CALT_KEYWORDS_MISSING_VALUES}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   309
    endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   310
    list(TRANSFORM ONE_VALUE_KEYWORDS PREPEND CALT_ OUTPUT_VARIABLE required_arguments)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   311
    foreach(required_argument ${required_arguments} )
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   312
        if(NOT DEFINED "${required_argument}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   313
            message(FATAL_ERROR "Internal error: Missing required argument ${required_argument}."
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   314
                "Complete argument list: ${ARGN}"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   315
            )
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   316
        endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   317
    endforeach()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   318
    if("staticlib" IN_LIST CALT_LIB_KINDS)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   319
        set(has_staticlib TRUE)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   320
    endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   321
    if("cdylib" IN_LIST CALT_LIB_KINDS)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   322
        set(has_cdylib TRUE)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   323
    endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   324
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   325
    if(NOT (has_staticlib OR has_cdylib))
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   326
        message(FATAL_ERROR "Unknown library type(s): ${CALT_LIB_KINDS}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   327
    endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   328
    set(workspace_manifest_path "${CALT_WORKSPACE_MANIFEST_PATH}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   329
    set(target_name "${CALT_TARGET_NAME}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   330
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   331
    set(is_windows "")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   332
    set(is_windows_gnu "")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   333
    set(is_windows_msvc "")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   334
    set(is_macos "")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   335
    if(Rust_CARGO_TARGET_OS STREQUAL "windows")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   336
        set(is_windows TRUE)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   337
        if(Rust_CARGO_TARGET_ENV STREQUAL "msvc")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   338
            set(is_windows_msvc TRUE)
16038
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   339
        elseif(Rust_CARGO_TARGET_ENV STREQUAL "gnu" OR Rust_CARGO_TARGET_ENV STREQUAL "gnullvm")
16021
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   340
            set(is_windows_gnu TRUE)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   341
        endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   342
    elseif(Rust_CARGO_TARGET_OS STREQUAL "darwin")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   343
        set(is_macos TRUE)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   344
    endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   345
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   346
    # target file names
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   347
    string(REPLACE "-" "_" lib_name "${target_name}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   348
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   349
    if(is_windows_msvc)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   350
        set(static_lib_name "${lib_name}.lib")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   351
    else()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   352
        set(static_lib_name "lib${lib_name}.a")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   353
    endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   354
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   355
    if(is_windows)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   356
        set(dynamic_lib_name "${lib_name}.dll")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   357
    elseif(is_macos)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   358
        set(dynamic_lib_name "lib${lib_name}.dylib")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   359
    else()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   360
        set(dynamic_lib_name "lib${lib_name}.so")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   361
    endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   362
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   363
    if(is_windows_msvc)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   364
        set(implib_name "${lib_name}.dll.lib")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   365
    elseif(is_windows_gnu)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   366
        set(implib_name "lib${lib_name}.dll.a")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   367
    elseif(is_windows)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   368
        message(FATAL_ERROR "Unknown windows environment - Can't determine implib name")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   369
    endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   370
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   371
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   372
    set(pdb_name "${lib_name}.pdb")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   373
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   374
    set(archive_output_byproducts "")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   375
    if(has_staticlib)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   376
        list(APPEND archive_output_byproducts ${static_lib_name})
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   377
    endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   378
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   379
    if(has_cdylib)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   380
        set("${CALT_OUT_SHARED_LIB_BYPRODUCTS}" "${dynamic_lib_name}" PARENT_SCOPE)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   381
        if(is_windows)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   382
            list(APPEND archive_output_byproducts ${implib_name})
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   383
        endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   384
        if(is_windows_msvc)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   385
            set("${CALT_OUT_PDB_BYPRODUCT}" "${pdb_name}" PARENT_SCOPE)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   386
        endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   387
    endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   388
    set("${CALT_OUT_ARCHIVE_OUTPUT_BYPRODUCTS}" "${archive_output_byproducts}" PARENT_SCOPE)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   389
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   390
    if(has_staticlib)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   391
        add_library(${target_name}-static STATIC IMPORTED GLOBAL)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   392
        add_dependencies(${target_name}-static cargo-build_${target_name})
16038
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   393
        set_target_properties(${target_name}-static PROPERTIES COR_FILE_NAME ${static_lib_name})
16021
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   394
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   395
        _corrosion_set_imported_location("${target_name}-static" "IMPORTED_LOCATION"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   396
                "ARCHIVE_OUTPUT_DIRECTORY"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   397
                "${static_lib_name}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   398
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   399
        # Todo: NO_STD target property?
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   400
        if(NOT COR_NO_STD)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   401
            set_property(
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   402
                    TARGET ${target_name}-static
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   403
                    PROPERTY INTERFACE_LINK_LIBRARIES ${Rust_CARGO_TARGET_LINK_NATIVE_LIBS}
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   404
            )
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   405
            set_property(
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   406
                    TARGET ${target_name}-static
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   407
                    PROPERTY INTERFACE_LINK_OPTIONS ${Rust_CARGO_TARGET_LINK_OPTIONS}
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   408
            )
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   409
            if(is_macos)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   410
                set_property(TARGET ${target_name}-static
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   411
                        PROPERTY INTERFACE_LINK_DIRECTORIES "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   412
                        )
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   413
            endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   414
        endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   415
    endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   416
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   417
    if(has_cdylib)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   418
        add_library(${target_name}-shared SHARED IMPORTED GLOBAL)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   419
        add_dependencies(${target_name}-shared cargo-build_${target_name})
16038
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   420
        set_target_properties(${target_name}-shared PROPERTIES COR_FILE_NAME ${dynamic_lib_name})
16021
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   421
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   422
        # Todo: (Not new issue): What about IMPORTED_SONAME and IMPORTED_NO_SYSTEM?
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   423
        _corrosion_set_imported_location("${target_name}-shared" "IMPORTED_LOCATION"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   424
                "LIBRARY_OUTPUT_DIRECTORY"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   425
                "${dynamic_lib_name}"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   426
        )
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   427
        # In the future we would probably prefer to let Rust set the soname for packages >= 1.0.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   428
        # This is tracked in issue #333.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   429
        set_target_properties(${target_name}-shared PROPERTIES IMPORTED_NO_SONAME TRUE)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   430
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   431
        if(is_windows)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   432
            _corrosion_set_imported_location("${target_name}-shared" "IMPORTED_IMPLIB"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   433
                    "ARCHIVE_OUTPUT_DIRECTORY"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   434
                    "${implib_name}"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   435
            )
16038
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   436
            set_target_properties(${target_name}-shared PROPERTIES COR_IMPLIB_FILE_NAME ${implib_name})
16021
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   437
        endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   438
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   439
        if(is_macos)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   440
            set_property(TARGET ${target_name}-shared
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   441
                    PROPERTY INTERFACE_LINK_DIRECTORIES "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   442
                    )
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   443
        endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   444
    endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   445
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   446
    if(has_cdylib AND has_staticlib)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   447
        if(BUILD_SHARED_LIBS)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   448
            target_link_libraries(${target_name} INTERFACE ${target_name}-shared)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   449
        else()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   450
            target_link_libraries(${target_name} INTERFACE ${target_name}-static)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   451
        endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   452
    elseif(has_cdylib)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   453
        target_link_libraries(${target_name} INTERFACE ${target_name}-shared)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   454
    else()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   455
        target_link_libraries(${target_name} INTERFACE ${target_name}-static)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   456
    endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   457
endfunction()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   458
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   459
function(_corrosion_add_bin_target workspace_manifest_path bin_name out_bin_byproduct out_pdb_byproduct)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   460
    if(NOT bin_name)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   461
        message(FATAL_ERROR "No bin_name in _corrosion_add_bin_target for target ${target_name}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   462
    endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   463
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   464
    string(REPLACE "-" "_" bin_name_underscore "${bin_name}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   465
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   466
    set(pdb_name "${bin_name_underscore}.pdb")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   467
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   468
    if(Rust_CARGO_TARGET_ENV STREQUAL "msvc")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   469
        set(${out_pdb_byproduct} "${pdb_name}" PARENT_SCOPE)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   470
    endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   471
16038
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   472
    # Potential .exe suffix will be added later, also depending on possible hostbuild
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   473
    # target property
16021
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   474
    set(bin_filename "${bin_name}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   475
    set(${out_bin_byproduct} "${bin_filename}" PARENT_SCOPE)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   476
    add_dependencies(${bin_name} cargo-build_${bin_name})
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   477
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   478
    if(Rust_CARGO_TARGET_OS STREQUAL "darwin")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   479
        set_property(TARGET ${bin_name}
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   480
                PROPERTY INTERFACE_LINK_DIRECTORIES "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   481
                )
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   482
    endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   483
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   484
    _corrosion_set_imported_location("${bin_name}" "IMPORTED_LOCATION"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   485
                        "RUNTIME_OUTPUT_DIRECTORY"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   486
                        "${bin_filename}"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   487
    )
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   488
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   489
endfunction()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   490
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   491
16038
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   492
include(CorrosionGenerator)
16021
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   493
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   494
# Note: `cmake_language(GET_MESSAGE_LOG_LEVEL <output_variable>)` requires CMake 3.25,
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   495
# so we offer our own option to control verbosity of downstream commands (e.g. cargo build)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   496
if (CORROSION_VERBOSE_OUTPUT)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   497
    set(_CORROSION_VERBOSE_OUTPUT_FLAG --verbose CACHE INTERNAL "")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   498
else()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   499
    # We want to silence some less important commands by default.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   500
    set(_CORROSION_QUIET_OUTPUT_FLAG --quiet CACHE INTERNAL "")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   501
endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   502
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   503
set(_CORROSION_CARGO_VERSION ${Rust_CARGO_VERSION} CACHE INTERNAL "cargo version used by corrosion")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   504
set(_CORROSION_RUST_CARGO_TARGET ${Rust_CARGO_TARGET} CACHE INTERNAL "target triple used by corrosion")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   505
set(_CORROSION_RUST_CARGO_HOST_TARGET ${Rust_CARGO_HOST_TARGET} CACHE INTERNAL "host triple used by corrosion")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   506
set(_CORROSION_RUSTC "${RUSTC_EXECUTABLE}" CACHE INTERNAL  "Path to rustc used by corrosion")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   507
set(_CORROSION_CARGO "${CARGO_EXECUTABLE}" CACHE INTERNAL "Path to cargo used by corrosion")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   508
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   509
string(REPLACE "-" "_" _CORROSION_RUST_CARGO_TARGET_UNDERSCORE "${Rust_CARGO_TARGET}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   510
set(_CORROSION_RUST_CARGO_TARGET_UNDERSCORE "${_CORROSION_RUST_CARGO_TARGET_UNDERSCORE}" CACHE INTERNAL "lowercase target triple with underscores")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   511
string(TOUPPER "${_CORROSION_RUST_CARGO_TARGET_UNDERSCORE}" _CORROSION_TARGET_TRIPLE_UPPER)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   512
set(_CORROSION_RUST_CARGO_TARGET_UPPER
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   513
        "${_CORROSION_TARGET_TRIPLE_UPPER}"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   514
        CACHE INTERNAL
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   515
        "target triple in uppercase with underscore"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   516
)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   517
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   518
# We previously specified some Custom properties as part of our public API, however the chosen names prevented us from
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   519
# supporting CMake versions before 3.19. In order to both support older CMake versions and not break existing code
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   520
# immediately, we are using a different property name depending on the CMake version. However users avoid using
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   521
# any of the properties directly, as they are no longer part of the public API and are to be considered deprecated.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   522
# Instead use the corrosion_set_... functions as documented in the Readme.
16038
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   523
set(_CORR_PROP_FEATURES CORROSION_FEATURES CACHE INTERNAL "")
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   524
set(_CORR_PROP_ALL_FEATURES CORROSION_ALL_FEATURES CACHE INTERNAL "")
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   525
set(_CORR_PROP_NO_DEFAULT_FEATURES CORROSION_NO_DEFAULT_FEATURES CACHE INTERNAL "")
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   526
set(_CORR_PROP_ENV_VARS CORROSION_ENVIRONMENT_VARIABLES CACHE INTERNAL "")
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   527
set(_CORR_PROP_HOST_BUILD CORROSION_USE_HOST_BUILD CACHE INTERNAL "")
16021
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   528
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   529
# Add custom command to build one target in a package (crate)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   530
#
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   531
# A target may be either a specific bin
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   532
function(_add_cargo_build out_cargo_build_out_dir)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   533
    set(options NO_LINKER_OVERRIDE)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   534
    set(one_value_args PACKAGE TARGET MANIFEST_PATH WORKSPACE_MANIFEST_PATH)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   535
    set(multi_value_args BYPRODUCTS TARGET_KINDS)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   536
    cmake_parse_arguments(
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   537
        ACB
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   538
        "${options}"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   539
        "${one_value_args}"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   540
        "${multi_value_args}"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   541
        ${ARGN}
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   542
    )
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   543
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   544
    if(DEFINED ACB_UNPARSED_ARGUMENTS)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   545
        message(FATAL_ERROR "Internal error - unexpected arguments: "
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   546
            ${ACB_UNPARSED_ARGUMENTS})
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   547
    elseif(DEFINED ACB_KEYWORDS_MISSING_VALUES)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   548
        message(FATAL_ERROR "Internal error - missing values for the following arguments: "
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   549
                ${ACB_KEYWORDS_MISSING_VALUES})
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   550
    endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   551
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   552
    set(package_name "${ACB_PACKAGE}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   553
    set(target_name "${ACB_TARGET}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   554
    set(path_to_toml "${ACB_MANIFEST_PATH}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   555
    set(target_kinds "${ACB_TARGET_KINDS}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   556
    set(workspace_manifest_path "${ACB_WORKSPACE_MANIFEST_PATH}")
16038
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   557
    set(build_byproducts "${ACB_BYPRODUCTS}")
16021
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   558
16038
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   559
    unset(cargo_rustc_crate_types)
16021
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   560
    if(NOT target_kinds)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   561
        message(FATAL_ERROR "TARGET_KINDS not specified")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   562
    elseif("staticlib" IN_LIST target_kinds OR "cdylib" IN_LIST target_kinds)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   563
        set(cargo_rustc_filter "--lib")
16038
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   564
        if("${Rust_VERSION}" VERSION_GREATER_EQUAL "1.64")
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   565
            # https://doc.rust-lang.org/1.64.0/cargo/commands/cargo-rustc.html
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   566
            # `--crate-type` is documented since Rust 1.64 for `cargo rustc`.
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   567
            # We just unconditionally set it when available, to support overriding the crate type.
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   568
            # Due to https://github.com/rust-lang/cargo/issues/14498 we can't use one argument and pass a
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   569
            # comma seperated list. Instead we use multiple arguments.
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   570
            set(cargo_rustc_crate_types "${target_kinds}")
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   571
            list(TRANSFORM cargo_rustc_crate_types PREPEND "--crate-type=")
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   572
        endif()
16021
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   573
    elseif("bin" IN_LIST target_kinds)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   574
        set(cargo_rustc_filter "--bin=${target_name}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   575
    else()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   576
        message(FATAL_ERROR "TARGET_KINDS contained unknown kind `${target_kind}`")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   577
    endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   578
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   579
    if (NOT IS_ABSOLUTE "${path_to_toml}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   580
        set(path_to_toml "${CMAKE_SOURCE_DIR}/${path_to_toml}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   581
    endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   582
    get_filename_component(workspace_toml_dir ${path_to_toml} DIRECTORY )
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   583
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   584
    if (CMAKE_VS_PLATFORM_NAME)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   585
        set (build_dir "${CMAKE_VS_PLATFORM_NAME}/$<CONFIG>")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   586
    elseif(COR_IS_MULTI_CONFIG)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   587
        set (build_dir "$<CONFIG>")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   588
    else()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   589
        set (build_dir .)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   590
    endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   591
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   592
    # If a CMake sysroot is specified, forward it to the linker rustc invokes, too. CMAKE_SYSROOT is documented
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   593
    # to be passed via --sysroot, so we assume that when it's set, the linker supports this option in that style.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   594
    if(CMAKE_CROSSCOMPILING AND CMAKE_SYSROOT)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   595
        set(corrosion_link_args "--sysroot=${CMAKE_SYSROOT}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   596
    endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   597
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   598
    if(COR_ALL_FEATURES)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   599
        set(all_features_arg --all-features)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   600
    endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   601
    if(COR_NO_DEFAULT_FEATURES)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   602
        set(no_default_features_arg --no-default-features)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   603
    endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   604
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   605
    set(global_rustflags_target_property "$<TARGET_GENEX_EVAL:${target_name},$<TARGET_PROPERTY:${target_name},INTERFACE_CORROSION_RUSTFLAGS>>")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   606
    set(local_rustflags_target_property  "$<TARGET_GENEX_EVAL:${target_name},$<TARGET_PROPERTY:${target_name},INTERFACE_CORROSION_LOCAL_RUSTFLAGS>>")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   607
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   608
    # todo: this probably should be TARGET_GENEX_EVAL
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   609
    set(features_target_property "$<GENEX_EVAL:$<TARGET_PROPERTY:${target_name},${_CORR_PROP_FEATURES}>>")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   610
    set(features_genex "$<$<BOOL:${features_target_property}>:--features=$<JOIN:${features_target_property},$<COMMA>>>")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   611
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   612
    # target property overrides corrosion_import_crate argument
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   613
    set(all_features_target_property "$<GENEX_EVAL:$<TARGET_PROPERTY:${target_name},${_CORR_PROP_ALL_FEATURES}>>")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   614
    set(all_features_arg "$<$<BOOL:${all_features_target_property}>:--all-features>")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   615
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   616
    set(no_default_features_target_property "$<GENEX_EVAL:$<TARGET_PROPERTY:${target_name},${_CORR_PROP_NO_DEFAULT_FEATURES}>>")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   617
    set(no_default_features_arg "$<$<BOOL:${no_default_features_target_property}>:--no-default-features>")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   618
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   619
    set(build_env_variable_genex "$<GENEX_EVAL:$<TARGET_PROPERTY:${target_name},${_CORR_PROP_ENV_VARS}>>")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   620
    set(hostbuild_override "$<BOOL:$<TARGET_PROPERTY:${target_name},${_CORR_PROP_HOST_BUILD}>>")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   621
    set(if_not_host_build_condition "$<NOT:${hostbuild_override}>")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   622
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   623
    set(corrosion_link_args "$<${if_not_host_build_condition}:${corrosion_link_args}>")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   624
    # We always set `--target`, so that cargo always places artifacts into a directory with the
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   625
    # target triple.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   626
    set(cargo_target_option "--target=$<IF:${hostbuild_override},${_CORROSION_RUST_CARGO_HOST_TARGET},${_CORROSION_RUST_CARGO_TARGET}>")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   627
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   628
    # The target may be a filepath to custom target json file. For host targets we assume that they are built-in targets.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   629
    _corrosion_strip_target_triple(${_CORROSION_RUST_CARGO_TARGET} stripped_target_triple)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   630
    set(target_artifact_dir "$<IF:${hostbuild_override},${_CORROSION_RUST_CARGO_HOST_TARGET},${stripped_target_triple}>")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   631
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   632
    set(flags_genex "$<GENEX_EVAL:$<TARGET_PROPERTY:${target_name},INTERFACE_CORROSION_CARGO_FLAGS>>")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   633
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   634
    set(explicit_linker_property "$<TARGET_PROPERTY:${target_name},INTERFACE_CORROSION_LINKER>")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   635
    set(explicit_linker_defined "$<BOOL:${explicit_linker_property}>")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   636
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   637
    set(cargo_profile_target_property "$<TARGET_GENEX_EVAL:${target_name},$<TARGET_PROPERTY:${target_name},INTERFACE_CORROSION_CARGO_PROFILE>>")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   638
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   639
    # Option to override the rustc/cargo binary to something other than the global default
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   640
    set(rustc_override "$<TARGET_PROPERTY:${target_name},INTERFACE_CORROSION_RUSTC>")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   641
    set(cargo_override "$<TARGET_PROPERTY:${target_name},INTERFACE_CORROSION_CARGO>")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   642
    set(rustc_bin "$<IF:$<BOOL:${rustc_override}>,${rustc_override},${_CORROSION_RUSTC}>")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   643
    set(cargo_bin "$<IF:$<BOOL:${cargo_override}>,${cargo_override},${_CORROSION_CARGO}>")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   644
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   645
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   646
    # Rust will add `-lSystem` as a flag for the linker on macOS. Adding the -L flag via RUSTFLAGS only fixes the
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   647
    # problem partially - buildscripts still break, since they won't receive the RUSTFLAGS. This seems to only be a
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   648
    # problem if we specify the linker ourselves (which we do, since this is necessary for e.g. linking C++ code).
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   649
    # We can however set `LIBRARY_PATH`, which is propagated to the build-script-build properly.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   650
    if(NOT CMAKE_CROSSCOMPILING AND CMAKE_SYSTEM_NAME STREQUAL "Darwin")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   651
        # not needed anymore on macos 13 (and causes issues)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   652
        if(${CMAKE_SYSTEM_VERSION} VERSION_LESS 22)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   653
        set(cargo_library_path "LIBRARY_PATH=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   654
        endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   655
    elseif(CMAKE_CROSSCOMPILING AND CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   656
        if(${CMAKE_HOST_SYSTEM_VERSION} VERSION_LESS 22)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   657
            set(cargo_library_path "$<${hostbuild_override}:LIBRARY_PATH=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib>")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   658
        endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   659
    endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   660
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   661
    set(cargo_profile_set "$<BOOL:${cargo_profile_target_property}>")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   662
    # In the default case just specify --release or nothing to stay compatible with
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   663
    # older rust versions.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   664
    set(default_profile_option "$<$<NOT:$<OR:$<CONFIG:Debug>,$<CONFIG:>>>:--release>")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   665
    # evaluates to either `--profile=<custom_profile>`, `--release` or nothing (for debug).
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   666
    set(cargo_profile "$<IF:${cargo_profile_set},--profile=${cargo_profile_target_property},${default_profile_option}>")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   667
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   668
    # If the profile name is `dev` change the dir name to `debug`.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   669
    set(is_dev_profile "$<STREQUAL:${cargo_profile_target_property},dev>")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   670
    set(profile_dir_override "$<${is_dev_profile}:debug>")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   671
    set(profile_dir_is_overridden "$<BOOL:${profile_dir_override}>")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   672
    set(custom_profile_build_type_dir "$<IF:${profile_dir_is_overridden},${profile_dir_override},${cargo_profile_target_property}>")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   673
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   674
    set(default_build_type_dir "$<IF:$<OR:$<CONFIG:Debug>,$<CONFIG:>>,debug,release>")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   675
    set(build_type_dir "$<IF:${cargo_profile_set},${custom_profile_build_type_dir},${default_build_type_dir}>")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   676
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   677
    set(cargo_target_dir "${CMAKE_BINARY_DIR}/${build_dir}/cargo/build")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   678
    set(cargo_build_dir "${cargo_target_dir}/${target_artifact_dir}/${build_type_dir}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   679
    set("${out_cargo_build_out_dir}" "${cargo_build_dir}" PARENT_SCOPE)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   680
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   681
    set(corrosion_cc_rs_flags)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   682
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   683
    if(CMAKE_C_COMPILER)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   684
        # This variable is read by cc-rs (often used in build scripts) to determine the c-compiler.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   685
        # It can still be overridden if the user sets the non underscore variant via the environment variables
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   686
        # on the target.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   687
        list(APPEND corrosion_cc_rs_flags "CC_${_CORROSION_RUST_CARGO_TARGET_UNDERSCORE}=${CMAKE_C_COMPILER}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   688
    endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   689
    if(CMAKE_CXX_COMPILER)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   690
        list(APPEND corrosion_cc_rs_flags "CXX_${_CORROSION_RUST_CARGO_TARGET_UNDERSCORE}=${CMAKE_CXX_COMPILER}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   691
    endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   692
    # cc-rs doesn't seem to support `llvm-ar` (commandline syntax), wo we might as well just use
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   693
    # the default AR.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   694
    if(CMAKE_AR AND NOT (Rust_CARGO_TARGET_ENV STREQUAL "msvc"))
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   695
        list(APPEND corrosion_cc_rs_flags "AR_${_CORROSION_RUST_CARGO_TARGET_UNDERSCORE}=${CMAKE_AR}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   696
    endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   697
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   698
    # Since we instruct cc-rs to use the compiler found by CMake, it is likely one that requires also
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   699
    # specifying the target sysroot to use. CMake's generator makes sure to pass --sysroot with
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   700
    # CMAKE_OSX_SYSROOT. Fortunately the compilers Apple ships also respect the SDKROOT environment
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   701
    # variable, which we can set for use when cc-rs invokes the compiler.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   702
    if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin" AND CMAKE_OSX_SYSROOT)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   703
        list(APPEND corrosion_cc_rs_flags "SDKROOT=${CMAKE_OSX_SYSROOT}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   704
    endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   705
16038
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   706
    # Ensure that cc-rs targets same Apple platform version as the CMake build
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   707
    if(CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND CMAKE_OSX_DEPLOYMENT_TARGET)
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   708
        list(APPEND corrosion_cc_rs_flags "MACOSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET}")
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   709
    endif()
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   710
16021
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   711
    corrosion_add_target_local_rustflags("${target_name}" "$<$<BOOL:${corrosion_link_args}>:-Clink-args=${corrosion_link_args}>")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   712
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   713
    # todo: this should probably also be guarded by if_not_host_build_condition.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   714
    if(COR_NO_STD)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   715
        corrosion_add_target_local_rustflags("${target_name}" "-Cdefault-linker-libraries=no")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   716
    else()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   717
        corrosion_add_target_local_rustflags("${target_name}" "-Cdefault-linker-libraries=yes")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   718
    endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   719
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   720
    set(global_joined_rustflags "$<JOIN:${global_rustflags_target_property}, >")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   721
    set(global_rustflags_genex "$<$<BOOL:${global_rustflags_target_property}>:RUSTFLAGS=${global_joined_rustflags}>")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   722
    set(local_rustflags_delimiter "$<$<BOOL:${local_rustflags_target_property}>:-->")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   723
    set(local_rustflags_genex "$<$<BOOL:${local_rustflags_target_property}>:${local_rustflags_target_property}>")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   724
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   725
    set(deps_link_languages_prop "$<TARGET_PROPERTY:_cargo-build_${target_name},CARGO_DEPS_LINKER_LANGUAGES>")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   726
    set(deps_link_languages "$<TARGET_GENEX_EVAL:_cargo-build_${target_name},${deps_link_languages_prop}>")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   727
    set(target_uses_cxx  "$<IN_LIST:CXX,${deps_link_languages}>")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   728
    unset(default_linker)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   729
    # With the MSVC ABI rustc only supports directly invoking the linker - Invoking cl as the linker driver is not supported.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   730
    if(NOT (Rust_CARGO_TARGET_ENV STREQUAL "msvc" OR COR_NO_LINKER_OVERRIDE))
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   731
        set(default_linker "$<IF:$<BOOL:${target_uses_cxx}>,${CMAKE_CXX_COMPILER},${CMAKE_C_COMPILER}>")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   732
    endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   733
    # Used to set a linker for a specific target-triple.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   734
    set(cargo_target_linker_var "CARGO_TARGET_${_CORROSION_RUST_CARGO_TARGET_UPPER}_LINKER")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   735
    set(linker "$<IF:${explicit_linker_defined},${explicit_linker_property},${default_linker}>")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   736
    set(cargo_target_linker $<$<BOOL:${linker}>:${cargo_target_linker_var}=${linker}>)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   737
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   738
    if(Rust_CROSSCOMPILING AND (CMAKE_C_COMPILER_TARGET OR CMAKE_CXX_COMPILER_TARGET))
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   739
        set(linker_target_triple "$<IF:$<BOOL:${target_uses_cxx}>,${CMAKE_CXX_COMPILER_TARGET},${CMAKE_C_COMPILER_TARGET}>")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   740
        set(rustflag_linker_arg "-Clink-args=--target=${linker_target_triple}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   741
        set(rustflag_linker_arg "$<${if_not_host_build_condition}:${rustflag_linker_arg}>")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   742
        # Skip adding the linker argument, if the linker is explicitly set, since the
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   743
        # explicit_linker_property will not be set when this function runs.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   744
        # Passing this rustflag is necessary for clang.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   745
        corrosion_add_target_local_rustflags("${target_name}" "$<$<NOT:${explicit_linker_defined}>:${rustflag_linker_arg}>")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   746
    endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   747
16038
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   748
    message(DEBUG "TARGET ${target_name} produces byproducts ${build_byproducts}")
16021
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   749
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   750
    add_custom_target(
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   751
        _cargo-build_${target_name}
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   752
        # Build crate
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   753
        COMMAND
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   754
            ${CMAKE_COMMAND} -E env
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   755
                "${build_env_variable_genex}"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   756
                "${global_rustflags_genex}"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   757
                "${cargo_target_linker}"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   758
                "${corrosion_cc_rs_flags}"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   759
                "${cargo_library_path}"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   760
                "CORROSION_BUILD_DIR=${CMAKE_CURRENT_BINARY_DIR}"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   761
                "CARGO_BUILD_RUSTC=${rustc_bin}"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   762
            "${cargo_bin}"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   763
                rustc
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   764
                ${cargo_rustc_filter}
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   765
                ${cargo_target_option}
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   766
                ${_CORROSION_VERBOSE_OUTPUT_FLAG}
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   767
                ${all_features_arg}
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   768
                ${no_default_features_arg}
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   769
                ${features_genex}
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   770
                --package ${package_name}
16038
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   771
                ${cargo_rustc_crate_types}
16021
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   772
                --manifest-path "${path_to_toml}"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   773
                --target-dir "${cargo_target_dir}"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   774
                ${cargo_profile}
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   775
                ${flags_genex}
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   776
                # Any arguments to cargo must be placed before this line
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   777
                ${local_rustflags_delimiter}
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   778
                ${local_rustflags_genex}
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   779
16038
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   780
        # Note: `BYPRODUCTS` may not contain **target specific** generator expressions.
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   781
        # This means we cannot use `${cargo_build_dir}`, since it currently uses `$<TARGET_PROPERTY>`
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   782
        # to determine the correct target directory, depending on if the hostbuild target property is
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   783
        # set or not.
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   784
        # BYPRODUCTS  "${cargo_build_dir}/${build_byproducts}"
16021
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   785
        # The build is conducted in the directory of the Manifest, so that configuration files such as
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   786
        # `.cargo/config.toml` or `toolchain.toml` are applied as expected.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   787
        WORKING_DIRECTORY "${workspace_toml_dir}"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   788
        USES_TERMINAL
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   789
        COMMAND_EXPAND_LISTS
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   790
        VERBATIM
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   791
    )
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   792
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   793
    # User exposed custom target, that depends on the internal target.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   794
    # Corrosion post build steps are added on the internal target, which
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   795
    # ensures that they run before any user defined post build steps on this
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   796
    # target.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   797
    add_custom_target(
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   798
        cargo-build_${target_name}
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   799
        ALL
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   800
    )
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   801
    add_dependencies(cargo-build_${target_name} _cargo-build_${target_name})
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   802
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   803
    # Add custom target before actual build that user defined custom commands (e.g. code generators) can
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   804
    # use as a hook to do something before the build. This mainly exists to not expose the `_cargo-build` targets.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   805
    add_custom_target(cargo-prebuild_${target_name})
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   806
    add_dependencies(_cargo-build_${target_name} cargo-prebuild_${target_name})
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   807
    if(NOT TARGET cargo-prebuild)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   808
        add_custom_target(cargo-prebuild)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   809
    endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   810
    add_dependencies(cargo-prebuild cargo-prebuild_${target_name})
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   811
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   812
    add_custom_target(
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   813
        cargo-clean_${target_name}
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   814
        COMMAND
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   815
            "${cargo_bin}" clean ${cargo_target_option}
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   816
            -p ${package_name} --manifest-path ${path_to_toml}
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   817
        WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/${build_dir}
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   818
        USES_TERMINAL
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   819
    )
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   820
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   821
    if (NOT TARGET cargo-clean)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   822
        add_custom_target(cargo-clean)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   823
    endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   824
    add_dependencies(cargo-clean cargo-clean_${target_name})
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   825
endfunction()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   826
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   827
#[=======================================================================[.md:
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   828
ANCHOR: corrosion-import-crate
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   829
```cmake
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   830
corrosion_import_crate(
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   831
        MANIFEST_PATH <path/to/cargo.toml>
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   832
        [ALL_FEATURES]
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   833
        [NO_DEFAULT_FEATURES]
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   834
        [NO_STD]
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   835
        [NO_LINKER_OVERRIDE]
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   836
        [LOCKED]
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   837
        [FROZEN]
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   838
        [PROFILE <cargo-profile>]
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   839
        [IMPORTED_CRATES <variable-name>]
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   840
        [CRATE_TYPES <crate_type1> ... <crate_typeN>]
16038
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   841
        [OVERRIDE_CRATE_TYPE <crate_name>=<crate_type1,crate_type2,...> ...]
16021
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   842
        [CRATES <crate1> ... <crateN>]
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   843
        [FEATURES <feature1> ... <featureN>]
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   844
        [FLAGS <flag1> ... <flagN>]
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   845
)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   846
```
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   847
* **MANIFEST_PATH**: Path to a [Cargo.toml Manifest] file.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   848
* **ALL_FEATURES**: Equivalent to [--all-features] passed to cargo build
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   849
* **NO_DEFAULT_FEATURES**: Equivalent to [--no-default-features] passed to cargo build
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   850
* **NO_STD**:  Disable linking of standard libraries (required for no_std crates).
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   851
* **NO_LINKER_OVERRIDE**: Will let Rust/Cargo determine which linker to use instead of corrosion (when linking is invoked by Rust)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   852
* **LOCKED**: Pass [`--locked`] to cargo build and cargo metadata.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   853
* **FROZEN**: Pass [`--frozen`] to cargo build and cargo metadata.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   854
* **PROFILE**: Specify cargo build profile (`dev`/`release` or a [custom profile]; `bench` and `test` are not supported)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   855
* **IMPORTED_CRATES**: Save the list of imported crates into the variable with the provided name in the current scope.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   856
* **CRATE_TYPES**: Only import the specified crate types. Valid values: `staticlib`, `cdylib`, `bin`.
16038
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   857
* **OVERRIDE_CRATE_TYPE**: Override the crate-types of a cargo crate with the given comma-separated values.
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   858
                           Internally uses the `rustc` flag [`--crate-type`] to override the crate-type.
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   859
                           Valid values for the crate types are the library types `staticlib` and `cdylib`.
16021
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   860
* **CRATES**: Only import the specified crates from a workspace. Values: Crate names.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   861
* **FEATURES**: Enable the specified features. Equivalent to [--features] passed to `cargo build`.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   862
* **FLAGS**:  Arbitrary flags to `cargo build`.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   863
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   864
[custom profile]: https://doc.rust-lang.org/cargo/reference/profiles.html#custom-profiles
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   865
[--all-features]: https://doc.rust-lang.org/cargo/reference/features.html#command-line-feature-options
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   866
[--no-default-features]: https://doc.rust-lang.org/cargo/reference/features.html#command-line-feature-options
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   867
[--features]: https://doc.rust-lang.org/cargo/reference/features.html#command-line-feature-options
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   868
[`--locked`]: https://doc.rust-lang.org/cargo/commands/cargo.html#manifest-options
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   869
[`--frozen`]: https://doc.rust-lang.org/cargo/commands/cargo.html#manifest-options
16038
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   870
[`--crate-type`]: https://doc.rust-lang.org/rustc/command-line-arguments.html#--crate-type-a-list-of-types-of-crates-for-the-compiler-to-emit
16021
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   871
[Cargo.toml Manifest]: https://doc.rust-lang.org/cargo/appendix/glossary.html#manifest
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   872
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   873
ANCHOR_END: corrosion-import-crate
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   874
#]=======================================================================]
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   875
function(corrosion_import_crate)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   876
    set(OPTIONS ALL_FEATURES NO_DEFAULT_FEATURES NO_STD NO_LINKER_OVERRIDE LOCKED FROZEN)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   877
    set(ONE_VALUE_KEYWORDS MANIFEST_PATH PROFILE IMPORTED_CRATES)
16038
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   878
    set(MULTI_VALUE_KEYWORDS CRATE_TYPES CRATES FEATURES FLAGS OVERRIDE_CRATE_TYPE)
16021
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   879
    cmake_parse_arguments(COR "${OPTIONS}" "${ONE_VALUE_KEYWORDS}" "${MULTI_VALUE_KEYWORDS}" ${ARGN})
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   880
    list(APPEND CMAKE_MESSAGE_CONTEXT "corrosion_import_crate")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   881
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   882
    if(DEFINED COR_UNPARSED_ARGUMENTS)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   883
        message(AUTHOR_WARNING "Unexpected arguments: " ${COR_UNPARSED_ARGUMENTS}
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   884
            "\nCorrosion will ignore these unexpected arguments."
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   885
            )
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   886
    endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   887
    if(DEFINED COR_KEYWORDS_MISSING_VALUES)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   888
        message(DEBUG "Note: the following keywords passed to corrosion_import_crate had no associated value(s): "
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   889
            ${COR_KEYWORDS_MISSING_VALUES}
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   890
        )
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   891
    endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   892
    if (NOT DEFINED COR_MANIFEST_PATH)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   893
        message(FATAL_ERROR "MANIFEST_PATH is a required keyword to corrosion_add_crate")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   894
    endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   895
    _corrosion_option_passthrough_helper(NO_LINKER_OVERRIDE COR no_linker_override)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   896
    _corrosion_option_passthrough_helper(LOCKED COR locked)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   897
    _corrosion_option_passthrough_helper(FROZEN COR frozen)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   898
    _corrosion_arg_passthrough_helper(CRATES COR crate_allowlist)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   899
    _corrosion_arg_passthrough_helper(CRATE_TYPES COR crate_types)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   900
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   901
    if(COR_PROFILE)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   902
        if(Rust_VERSION VERSION_LESS 1.57.0)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   903
            message(FATAL_ERROR "Selecting custom profiles via `PROFILE` requires at least rust 1.57.0, but you "
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   904
                        "have ${Rust_VERSION}."
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   905
        )
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   906
        # The profile name could be part of a Generator expression, so this won't catch all occurences.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   907
        # Since it is hard to add an error message for genex, we don't do that here.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   908
        elseif("${COR_PROFILE}" STREQUAL "test" OR "${COR_PROFILE}" STREQUAL "bench")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   909
            message(FATAL_ERROR "Corrosion does not support building Rust crates with the cargo profiles"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   910
                    " `test` or `bench`. These profiles add a hash to the output artifact name that we"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   911
                    " cannot predict. Please consider using a custom cargo profile which inherits from the"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   912
                    " built-in profile instead."
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   913
            )
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   914
        endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   915
    endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   916
16038
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   917
    # intended to be used with foreach(... ZIP_LISTS ...), meaning
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   918
    # that the crate_types at index i of `override_crate_type_types_list` are
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   919
    # for the package_name at index i of `override_crate_type_package_name_list`.
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   920
    # It would really be nice if CMake had structs or dicts.
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   921
    unset(override_crate_type_package_name_list)
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   922
    unset(override_crate_type_types_list)
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   923
    unset(OVERRIDE_CRATE_TYPE_ARGS)
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   924
    if(DEFINED COR_OVERRIDE_CRATE_TYPE)
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   925
        string(JOIN " " usage_help
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   926
               "Each argument to OVERRIDE_CRATE_TYPE must be of the form `<package_name>=<crate_type(s)>."
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   927
               "The package_name must be a valid cargo package name and the crate_type must be "
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   928
               "a comma-seperated list with valid values being `staticlib`, `cdylib` and `bin`"
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   929
        )
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   930
        foreach(entry IN LISTS COR_OVERRIDE_CRATE_TYPE)
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   931
            string(REPLACE "=" ";" key_val_list ${entry})
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   932
            list(LENGTH key_val_list key_val_list_len)
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   933
            if(NOT key_val_list_len EQUAL "2")
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   934
                message(FATAL_ERROR "Invalid argument: `${entry}` for parameter OVERRIDE_CRATE_TYPE!\n"
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   935
                    "${usage_help}"
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   936
                )
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   937
            endif()
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   938
            list(GET key_val_list "0" package_name)
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   939
            list(GET key_val_list "1" crate_types)
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   940
            list(APPEND override_crate_type_package_name_list "${package_name}")
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   941
            list(APPEND override_crate_type_types_list "${crate_types}")
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   942
        endforeach()
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   943
        list(LENGTH override_crate_type_package_name_list num_override_packages)
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   944
        list(LENGTH override_crate_type_types_list num_override_packages2)
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   945
        if("${Rust_VERSION}" VERSION_LESS "1.64")
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   946
            message(WARNING "OVERRIDE_CRATE_TYPE requires at Rust 1.64 or newer. Ignoring the option")
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   947
        elseif(NOT num_override_packages EQUAL num_override_packages2)
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   948
            message(WARNING "Internal error while parsing OVERRIDE_CRATE_TYPE arguments.\n"
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   949
                    "Corrosion will ignore this argument and continue."
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   950
            )
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   951
        else()
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   952
            # Pass by ref: we intentionally pass the list names here!
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   953
            set(override_crate_types_arg "OVERRIDE_CRATE_TYPE_ARGS" "override_crate_type_package_name_list" "override_crate_type_types_list")
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   954
        endif()
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   955
    endif()
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   956
16021
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   957
    if (NOT IS_ABSOLUTE "${COR_MANIFEST_PATH}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   958
        set(COR_MANIFEST_PATH ${CMAKE_CURRENT_SOURCE_DIR}/${COR_MANIFEST_PATH})
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   959
    endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   960
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   961
    set(additional_cargo_flags ${COR_FLAGS})
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   962
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   963
    if(COR_LOCKED AND NOT "--locked" IN_LIST additional_cargo_flags)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   964
        list(APPEND additional_cargo_flags  "--locked")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   965
    endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   966
    if(COR_FROZEN AND NOT "--frozen" IN_LIST additional_cargo_flags)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   967
        list(APPEND additional_cargo_flags  "--frozen")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   968
    endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   969
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   970
    set(imported_crates "")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   971
16038
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   972
    _generator_add_cargo_targets(
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   973
        MANIFEST_PATH
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   974
            "${COR_MANIFEST_PATH}"
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   975
        IMPORTED_CRATES
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   976
            imported_crates
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   977
        ${crate_allowlist}
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   978
        ${crate_types}
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   979
        ${no_linker_override}
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   980
        ${override_crate_types_arg}
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
   981
    )
16021
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   982
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   983
    # Not target props yet:
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   984
    # NO_STD
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   985
    # NO_LINKER_OVERRIDE # We could simply zero INTERFACE_CORROSION_LINKER if this is set.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   986
    # LOCKED / FROZEN get merged into FLAGS after cargo metadata.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   987
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   988
    # Initialize the target properties with the arguments to corrosion_import_crate.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   989
    set_target_properties(
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   990
            ${imported_crates}
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   991
            PROPERTIES
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   992
                "${_CORR_PROP_ALL_FEATURES}" "${COR_ALL_FEATURES}"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   993
                "${_CORR_PROP_NO_DEFAULT_FEATURES}" "${COR_NO_DEFAULT_FEATURES}"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   994
                "${_CORR_PROP_FEATURES}" "${COR_FEATURES}"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   995
                INTERFACE_CORROSION_CARGO_PROFILE "${COR_PROFILE}"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   996
                INTERFACE_CORROSION_CARGO_FLAGS "${additional_cargo_flags}"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   997
    )
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   998
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   999
    # _CORR_PROP_ENV_VARS
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1000
    if(DEFINED COR_IMPORTED_CRATES)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1001
        set(${COR_IMPORTED_CRATES} ${imported_crates} PARENT_SCOPE)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1002
    endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1003
endfunction()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1004
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1005
function(corrosion_set_linker target_name linker)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1006
    if(NOT linker)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1007
        message(FATAL_ERROR "The linker passed to `corrosion_set_linker` may not be empty")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1008
    elseif(NOT TARGET "${target_name}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1009
        message(FATAL_ERROR "The target `${target_name}` does not exist.")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1010
    endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1011
    if(MSVC)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1012
        message(WARNING "Explicitly setting the linker with the MSVC toolchain is currently not supported and ignored")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1013
    endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1014
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1015
    if(TARGET "${target_name}-static" AND NOT TARGET "${target_name}-shared")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1016
        message(WARNING "The target ${target_name} builds a static library."
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1017
            "The linker is never invoked for a static library so specifying a linker has no effect."
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1018
        )
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1019
    endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1020
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1021
    set_property(
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1022
        TARGET ${target_name}
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1023
        PROPERTY INTERFACE_CORROSION_LINKER "${linker}"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1024
    )
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1025
endfunction()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1026
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1027
function(corrosion_set_hostbuild target_name)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1028
    # Configure the target to be compiled for the Host target and ignore any cross-compile configuration.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1029
    set_property(
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1030
            TARGET ${target_name}
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1031
            PROPERTY ${_CORR_PROP_HOST_BUILD} 1
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1032
    )
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1033
endfunction()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1034
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1035
# Add flags for rustc (RUSTFLAGS) which affect the target and all of it's Rust dependencies
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1036
#
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1037
# Additional rustflags may be passed as optional parameters after rustflag.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1038
# Please note, that if you import multiple targets from a package or workspace, but set different
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1039
# Rustflags via this function, the Rust dependencies will have to be rebuilt when changing targets.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1040
# Consider `corrosion_add_target_local_rustflags()` as an alternative to avoid this.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1041
function(corrosion_add_target_rustflags target_name rustflag)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1042
    # Additional rustflags may be passed as optional parameters after rustflag.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1043
    set_property(
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1044
            TARGET ${target_name}
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1045
            APPEND
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1046
            PROPERTY INTERFACE_CORROSION_RUSTFLAGS ${rustflag} ${ARGN}
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1047
    )
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1048
endfunction()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1049
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1050
# Add flags for rustc (RUSTFLAGS) which only affect the target, but none of it's (Rust) dependencies
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1051
#
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1052
# Additional rustflags may be passed as optional parameters after rustc_flag.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1053
function(corrosion_add_target_local_rustflags target_name rustc_flag)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1054
    # Set Rustflags via `cargo rustc` which only affect the current crate, but not dependencies.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1055
    set_property(
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1056
            TARGET ${target_name}
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1057
            APPEND
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1058
            PROPERTY INTERFACE_CORROSION_LOCAL_RUSTFLAGS ${rustc_flag} ${ARGN}
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1059
    )
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1060
endfunction()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1061
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1062
function(corrosion_set_env_vars target_name env_var)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1063
    # Additional environment variables may be passed as optional parameters after env_var.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1064
    set_property(
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1065
        TARGET ${target_name}
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1066
        APPEND
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1067
        PROPERTY ${_CORR_PROP_ENV_VARS} ${env_var} ${ARGN}
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1068
    )
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1069
endfunction()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1070
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1071
function(corrosion_set_cargo_flags target_name)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1072
    # corrosion_set_cargo_flags(<target_name> [<flag1> ... ])
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1073
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1074
    set_property(
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1075
            TARGET ${target_name}
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1076
            APPEND
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1077
            PROPERTY INTERFACE_CORROSION_CARGO_FLAGS ${ARGN}
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1078
    )
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1079
endfunction()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1080
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1081
function(corrosion_set_features target_name)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1082
    # corrosion_set_features(<target_name> [ALL_FEATURES=Bool] [NO_DEFAULT_FEATURES] [FEATURES <feature1> ... ])
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1083
    set(options NO_DEFAULT_FEATURES)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1084
    set(one_value_args ALL_FEATURES)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1085
    set(multi_value_args FEATURES)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1086
    cmake_parse_arguments(
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1087
            PARSE_ARGV 1
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1088
            SET
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1089
            "${options}"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1090
            "${one_value_args}"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1091
            "${multi_value_args}"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1092
    )
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1093
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1094
    if(DEFINED SET_ALL_FEATURES)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1095
        set_property(
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1096
                TARGET ${target_name}
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1097
                PROPERTY ${_CORR_PROP_ALL_FEATURES} ${SET_ALL_FEATURES}
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1098
        )
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1099
    endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1100
    if(SET_NO_DEFAULT_FEATURES)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1101
        set_property(
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1102
                TARGET ${target_name}
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1103
                PROPERTY ${_CORR_PROP_NO_DEFAULT_FEATURES} 1
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1104
        )
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1105
    endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1106
    if(SET_FEATURES)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1107
        set_property(
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1108
                TARGET ${target_name}
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1109
                APPEND
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1110
                PROPERTY ${_CORR_PROP_FEATURES} ${SET_FEATURES}
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1111
        )
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1112
    endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1113
endfunction()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1114
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1115
function(corrosion_link_libraries target_name)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1116
    if(TARGET "${target_name}-static")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1117
        message(DEBUG "The target ${target_name} builds a static Rust library."
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1118
                "Calling `target_link_libraries()` instead."
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1119
        )
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1120
        target_link_libraries("${target_name}-static" INTERFACE ${ARGN})
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1121
        if(NOT TARGET "${target_name}-shared")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1122
            # Early return, since Rust won't invoke the linker for static libraries
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1123
            return()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1124
        endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1125
    endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1126
    foreach(library ${ARGN})
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1127
        set_property(
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1128
            TARGET _cargo-build_${target_name}
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1129
            APPEND
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1130
            PROPERTY CARGO_DEPS_LINKER_LANGUAGES
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1131
            $<TARGET_PROPERTY:${library},LINKER_LANGUAGE>
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1132
        )
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1133
16038
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1134
        if (TARGET "${library}")
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1135
            corrosion_add_target_local_rustflags(${target_name}
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1136
                "-L$<TARGET_LINKER_FILE_DIR:${library}>"
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1137
                "-l$<TARGET_LINKER_FILE_BASE_NAME:${library}>"
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1138
            )
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1139
            add_dependencies(_cargo-build_${target_name} ${library})
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1140
        elseif(IS_ABSOLUTE "${library}")
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1141
            # Linking via full path (See https://doc.rust-lang.org/rustc/command-line-arguments.html#linking-modifiers-verbatim)
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1142
            corrosion_add_target_local_rustflags(${target_name} "-Clink-arg=${library}")
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1143
        else()
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1144
            # We have to assume ${library} is a non-CMake library name
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1145
            corrosion_add_target_local_rustflags(${target_name} "-l${library}")
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1146
        endif()
16021
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1147
    endforeach()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1148
endfunction()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1149
16038
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1150
#[=======================================================================[.md:
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1151
ANCHOR: corrosion-install
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1152
** EXPERIMENTAL **: This function is currently still considered experimental
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1153
  and is not officially released yet. Feedback and Suggestions are welcome.
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1154
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1155
```cmake
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1156
corrosion_install(TARGETS <target1> ... <targetN> [EXPORT <export-name>]
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1157
                  [[ARCHIVE|LIBRARY|RUNTIME|PUBLIC_HEADER]
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1158
                   [DESTINATION <dir>]
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1159
                   [PERMISSIONS <permissions...>]
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1160
                   [CONFIGURATIONS [Debug|Release|<other-configuration>]]
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1161
                  ] [...])
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1162
```
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1163
* **TARGETS**: Target or targets to install.
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1164
* **EXPORT**: Creates an export that can be installed with `install(EXPORT)`. <export-name> must be globally unique.
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1165
             Also creates a file at ${CMAKE_BINARY_DIR}/corrosion/<export-name>Corrosion.cmake that must be included in the installed config file.
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1166
* **ARCHIVE**/**LIBRARY**/**RUNTIME**/PUBLIC_HEADER: Designates that the following settings only apply to that specific type of object.
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1167
* **DESTINATION**: The subdirectory within the CMAKE_INSTALL_PREFIX that a specific object should be placed. Defaults to values from GNUInstallDirs.
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1168
* **PERMISSIONS**: The permissions of files copied into the install prefix.
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1169
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1170
Any `PUBLIC` or `INTERFACE` [file sets] will be installed.
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1171
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1172
[file sets]: https://cmake.org/cmake/help/latest/command/target_sources.html#file-sets
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1173
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1174
ANCHOR_END: corrosion-install
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1175
#]=======================================================================]
16021
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1176
function(corrosion_install)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1177
    # Default install dirs
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1178
    include(GNUInstallDirs)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1179
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1180
    # Parse arguments to corrosion_install
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1181
    list(GET ARGN 0 INSTALL_TYPE)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1182
    list(REMOVE_AT ARGN 0)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1183
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1184
    # The different install types that are supported. Some targets may have more than one of these
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1185
    # types. For example, on Windows, a shared library will have both an ARCHIVE component and a
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1186
    # RUNTIME component.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1187
    set(INSTALL_TARGET_TYPES ARCHIVE LIBRARY RUNTIME PRIVATE_HEADER PUBLIC_HEADER)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1188
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1189
    # Arguments to each install target type
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1190
    set(OPTIONS)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1191
    set(ONE_VALUE_ARGS DESTINATION)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1192
    set(MULTI_VALUE_ARGS PERMISSIONS CONFIGURATIONS)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1193
    set(TARGET_ARGS ${OPTIONS} ${ONE_VALUE_ARGS} ${MULTI_VALUE_ARGS})
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1194
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1195
    if (INSTALL_TYPE STREQUAL "TARGETS")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1196
        # Extract targets
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1197
        set(INSTALL_TARGETS)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1198
        list(LENGTH ARGN ARGN_LENGTH)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1199
        set(DELIMITERS EXPORT ${INSTALL_TARGET_TYPES} ${TARGET_ARGS})
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1200
        while(ARGN_LENGTH)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1201
            # If we hit another keyword, stop - we've found all the targets
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1202
            list(GET ARGN 0 FRONT)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1203
            if (FRONT IN_LIST DELIMITERS)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1204
                break()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1205
            endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1206
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1207
            list(APPEND INSTALL_TARGETS ${FRONT})
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1208
            list(REMOVE_AT ARGN 0)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1209
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1210
            # Update ARGN_LENGTH
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1211
            list(LENGTH ARGN ARGN_LENGTH)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1212
        endwhile()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1213
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1214
        # Check if there are any args left before proceeding
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1215
        list(LENGTH ARGN ARGN_LENGTH)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1216
        if (ARGN_LENGTH)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1217
            list(GET ARGN 0 FRONT)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1218
            if (FRONT STREQUAL "EXPORT")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1219
                list(REMOVE_AT ARGN 0) # Pop "EXPORT"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1220
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1221
                list(GET ARGN 0 EXPORT_NAME)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1222
                list(REMOVE_AT ARGN 0) # Pop <export-name>
16038
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1223
                set(EXTRA_TARGETS_EXPORT_NAME ${EXPORT_NAME}Corrosion.cmake)
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1224
                set(EXPORT_NAME EXPORT ${EXPORT_NAME})
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1225
                set(EXPORT_FILE_PATH "${CMAKE_BINARY_DIR}/corrosion/${EXTRA_TARGETS_EXPORT_NAME}")
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1226
                # Remove first, since otherwise we will append to the file on every reconfigure.
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1227
                # Assumes that the corrosion_install will only be called once for a given EXPORT_NAME.
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1228
                file(REMOVE "${EXPORT_FILE_PATH}")
16021
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1229
            endif()
16038
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1230
        else()
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1231
            # Prevent variable set in user code from interfering
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1232
            set(EXPORT_NAME)
16021
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1233
        endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1234
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1235
        # Loop over all arguments and get options for each install target type
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1236
        list(LENGTH ARGN ARGN_LENGTH)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1237
        while(ARGN_LENGTH)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1238
            # Check if we're dealing with arguments for a specific install target type, or with
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1239
            # default options for all target types.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1240
            list(GET ARGN 0 FRONT)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1241
            if (FRONT IN_LIST INSTALL_TARGET_TYPES)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1242
                set(INSTALL_TARGET_TYPE ${FRONT})
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1243
                list(REMOVE_AT ARGN 0)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1244
            else()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1245
                set(INSTALL_TARGET_TYPE DEFAULT)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1246
            endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1247
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1248
            # Gather the arguments to this install type
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1249
            set(ARGS)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1250
            while(ARGN_LENGTH)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1251
                # If the next keyword is an install target type, then break - arguments have been
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1252
                # gathered.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1253
                list(GET ARGN 0 FRONT)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1254
                if (FRONT IN_LIST INSTALL_TARGET_TYPES)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1255
                    break()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1256
                endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1257
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1258
                list(APPEND ARGS ${FRONT})
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1259
                list(REMOVE_AT ARGN 0)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1260
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1261
                list(LENGTH ARGN ARGN_LENGTH)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1262
            endwhile()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1263
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1264
            # Parse the arguments and register the file install
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1265
            cmake_parse_arguments(
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1266
                COR "${OPTIONS}" "${ONE_VALUE_ARGS}" "${MULTI_VALUE_ARGS}" ${ARGS})
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1267
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1268
            if (COR_DESTINATION)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1269
                set(COR_INSTALL_${INSTALL_TARGET_TYPE}_DESTINATION ${COR_DESTINATION})
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1270
            endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1271
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1272
            if (COR_PERMISSIONS)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1273
                set(COR_INSTALL_${INSTALL_TARGET_TYPE}_PERMISSIONS ${COR_PERMISSIONS})
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1274
            endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1275
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1276
            if (COR_CONFIGURATIONS)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1277
                set(COR_INSTALL_${INSTALL_TARGET_TYPE}_CONFIGURATIONS ${COR_CONFIGURATIONS})
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1278
            endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1279
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1280
            # Update ARG_LENGTH
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1281
            list(LENGTH ARGN ARGN_LENGTH)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1282
        endwhile()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1283
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1284
        # Default permissions for all files
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1285
        set(DEFAULT_PERMISSIONS OWNER_WRITE OWNER_READ GROUP_READ WORLD_READ)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1286
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1287
        # Loop through each install target and register file installations
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1288
        foreach(INSTALL_TARGET ${INSTALL_TARGETS})
16038
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1289
            if(NOT TARGET ${INSTALL_TARGET})
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1290
                message(FATAL_ERROR "Install target ${INSTALL_TARGET} is not a valid target")
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1291
            endif()
16021
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1292
            # Don't both implementing target type differentiation using generator expressions since
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1293
            # TYPE cannot change after target creation
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1294
            get_property(
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1295
                TARGET_TYPE
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1296
                TARGET ${INSTALL_TARGET} PROPERTY TYPE
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1297
            )
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1298
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1299
            # Install executable files first
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1300
            if (TARGET_TYPE STREQUAL "EXECUTABLE")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1301
                if (DEFINED COR_INSTALL_RUNTIME_DESTINATION)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1302
                    set(DESTINATION ${COR_INSTALL_RUNTIME_DESTINATION})
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1303
                elseif (DEFINED COR_INSTALL_DEFAULT_DESTINATION)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1304
                    set(DESTINATION ${COR_INSTALL_DEFAULT_DESTINATION})
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1305
                else()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1306
                    set(DESTINATION ${CMAKE_INSTALL_BINDIR})
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1307
                endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1308
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1309
                if (DEFINED COR_INSTALL_RUNTIME_PERMISSIONS)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1310
                    set(PERMISSIONS ${COR_INSTALL_RUNTIME_PERMISSIONS})
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1311
                elseif (DEFINED COR_INSTALL_DEFAULT_PERMISSIONS)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1312
                    set(PERMISSIONS ${COR_INSTALL_DEFAULT_PERMISSIONS})
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1313
                else()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1314
                    set(
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1315
                        PERMISSIONS
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1316
                        ${DEFAULT_PERMISSIONS} OWNER_EXECUTE GROUP_EXECUTE WORLD_EXECUTE)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1317
                endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1318
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1319
                if (DEFINED COR_INSTALL_RUNTIME_CONFIGURATIONS)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1320
                    set(CONFIGURATIONS CONFIGURATIONS ${COR_INSTALL_RUNTIME_CONFIGURATIONS})
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1321
                elseif (DEFINED COR_INSTALL_DEFAULT_CONFIGURATIONS)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1322
                    set(CONFIGURATIONS CONFIGURATIONS ${COR_INSTALL_DEFAULT_CONFIGURATIONS})
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1323
                else()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1324
                    set(CONFIGURATIONS)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1325
                endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1326
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1327
                install(
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1328
                    FILES $<TARGET_FILE:${INSTALL_TARGET}>
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1329
                    DESTINATION ${DESTINATION}
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1330
                    PERMISSIONS ${PERMISSIONS}
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1331
                    ${CONFIGURATIONS}
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1332
                )
16038
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1333
            elseif(TARGET_TYPE STREQUAL "INTERFACE_LIBRARY")
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1334
                if(TARGET ${INSTALL_TARGET}-static)
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1335
                    if (DEFINED COR_INSTALL_ARCHIVE_DESTINATION)
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1336
                        set(DESTINATION ${COR_INSTALL_ARCHIVE_DESTINATION})
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1337
                    elseif (DEFINED COR_INSTALL_DEFAULT_DESTINATION)
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1338
                        set(DESTINATION ${COR_INSTALL_DEFAULT_DESTINATION})
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1339
                    else()
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1340
                        set(DESTINATION ${CMAKE_INSTALL_LIBDIR})
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1341
                    endif()
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1342
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1343
                    if (DEFINED COR_INSTALL_ARCHIVE_PERMISSIONS)
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1344
                        set(PERMISSIONS ${COR_INSTALL_ARCHIVE_PERMISSIONS})
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1345
                    elseif (DEFINED COR_INSTALL_DEFAULT_PERMISSIONS)
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1346
                        set(PERMISSIONS ${COR_INSTALL_DEFAULT_PERMISSIONS})
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1347
                    else()
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1348
                        set(PERMISSIONS ${DEFAULT_PERMISSIONS})
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1349
                    endif()
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1350
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1351
                    if (DEFINED COR_INSTALL_ARCHIVE_CONFIGURATIONS)
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1352
                        set(CONFIGURATIONS CONFIGURATIONS ${COR_INSTALL_ARCHIVE_CONFIGURATIONS})
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1353
                    elseif (DEFINED COR_INSTALL_DEFAULT_CONFIGURATIONS)
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1354
                        set(CONFIGURATIONS CONFIGURATIONS ${COR_INSTALL_DEFAULT_CONFIGURATIONS})
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1355
                    else()
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1356
                        set(CONFIGURATIONS)
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1357
                    endif()
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1358
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1359
                    install(
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1360
                            FILES $<TARGET_PROPERTY:${INSTALL_TARGET}-static,IMPORTED_LOCATION>
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1361
                            DESTINATION ${DESTINATION}
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1362
                            PERMISSIONS ${PERMISSIONS}
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1363
                            ${CONFIGURATIONS}
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1364
                    )
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1365
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1366
                    if(EXPORT_NAME)
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1367
                        get_target_property(COR_FILE_NAME ${INSTALL_TARGET}-static COR_FILE_NAME)
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1368
                        file(APPEND "${EXPORT_FILE_PATH}"
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1369
"
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1370
add_library(${INSTALL_TARGET}-static STATIC IMPORTED)
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1371
set_target_properties(${INSTALL_TARGET}-static
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1372
    PROPERTIES
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1373
    IMPORTED_LOCATION \"\${PACKAGE_PREFIX_DIR}/${DESTINATION}/${COR_FILE_NAME}\"
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1374
)
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1375
"
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1376
                        )
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1377
                    endif()
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1378
                endif()
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1379
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1380
                if(TARGET ${INSTALL_TARGET}-shared)
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1381
                    if (DEFINED COR_INSTALL_LIBRARY_DESTINATION)
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1382
                        set(DESTINATION ${COR_INSTALL_LIBRARY_DESTINATION})
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1383
                    elseif (DEFINED COR_INSTALL_DEFAULT_DESTINATION)
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1384
                        set(DESTINATION ${COR_INSTALL_DEFAULT_DESTINATION})
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1385
                    else()
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1386
                        set(DESTINATION ${CMAKE_INSTALL_LIBDIR})
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1387
                    endif()
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1388
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1389
                    if (DEFINED COR_INSTALL_LIBRARY_PERMISSIONS)
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1390
                        set(PERMISSIONS ${COR_INSTALL_LIBRARY_PERMISSIONS})
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1391
                    elseif (DEFINED COR_INSTALL_DEFAULT_PERMISSIONS)
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1392
                        set(PERMISSIONS ${COR_INSTALL_DEFAULT_PERMISSIONS})
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1393
                    else()
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1394
                        set(
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1395
                            PERMISSIONS
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1396
                            ${DEFAULT_PERMISSIONS} OWNER_EXECUTE GROUP_EXECUTE WORLD_EXECUTE
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1397
                        )
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1398
                    endif()
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1399
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1400
                    if (DEFINED COR_INSTALL_LIBRARY_CONFIGURATIONS)
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1401
                        set(CONFIGURATIONS CONFIGURATIONS ${COR_INSTALL_LIBRARY_CONFIGURATIONS})
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1402
                    elseif (DEFINED COR_INSTALL_DEFAULT_CONFIGURATIONS)
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1403
                        set(CONFIGURATIONS CONFIGURATIONS ${COR_INSTALL_DEFAULT_CONFIGURATIONS})
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1404
                    else()
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1405
                        set(CONFIGURATIONS)
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1406
                    endif()
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1407
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1408
                    install(
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1409
                            IMPORTED_RUNTIME_ARTIFACTS ${INSTALL_TARGET}-shared
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1410
                            PERMISSIONS ${PERMISSIONS}
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1411
                            DESTINATION ${DESTINATION}
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1412
                            ${CONFIGURATIONS}
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1413
                    )
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1414
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1415
                    if(EXPORT_NAME)
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1416
                        get_target_property(COR_FILE_NAME ${INSTALL_TARGET}-shared COR_FILE_NAME)
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1417
                        file(APPEND "${EXPORT_FILE_PATH}"
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1418
"
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1419
add_library(${INSTALL_TARGET}-shared SHARED IMPORTED)
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1420
set_target_properties(${INSTALL_TARGET}-shared
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1421
    PROPERTIES
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1422
    IMPORTED_LOCATION \"\${PACKAGE_PREFIX_DIR}/${DESTINATION}/${COR_FILE_NAME}\"
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1423
)
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1424
"
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1425
                            )
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1426
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1427
                            get_target_property(COR_IMPLIB_FILE_NAME ${INSTALL_TARGET}-shared COR_IMPLIB_FILE_NAME)
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1428
                            if (NOT COR_IMPLIB_FILE_NAME MATCHES .*-NOTFOUND)
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1429
                                file(APPEND "${EXPORT_FILE_PATH}"
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1430
"
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1431
set_target_properties(${INSTALL_TARGET}-shared
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1432
    PROPERTIES
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1433
    IMPORTED_IMPLIB \"\${PACKAGE_PREFIX_DIR}/${DESTINATION}/${COR_IMPLIB_FILE_NAME}\"
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1434
)"
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1435
                                )
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1436
                            endif()
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1437
                    endif()
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1438
                endif()
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1439
            else()
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1440
                message(FATAL_ERROR "Unknown target type ${TARGET_TYPE} for install target ${INSTALL_TARGET}")
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1441
            endif()
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1442
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1443
            # Executables can also have export tables, so they _might_ also need header files
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1444
            if (DEFINED COR_INSTALL_PUBLIC_HEADER_DESTINATION)
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1445
                set(DESTINATION ${COR_INSTALL_PUBLIC_HEADER_DESTINATION})
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1446
            elseif (DEFINED COR_INSTALL_DEFAULT_DESTINATION)
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1447
                set(DESTINATION ${COR_INSTALL_DEFAULT_DESTINATION})
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1448
            else()
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1449
                set(DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1450
            endif()
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1451
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1452
            if (DEFINED COR_INSTALL_PUBLIC_HEADER_PERMISSIONS)
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1453
                set(PERMISSIONS ${COR_INSTALL_PUBLIC_HEADER_PERMISSIONS})
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1454
            elseif (DEFINED COR_INSTALL_DEFAULT_PERMISSIONS)
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1455
                set(PERMISSIONS ${COR_INSTALL_DEFAULT_PERMISSIONS})
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1456
            else()
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1457
                # Directories need OWNER_EXECUTE in order to be deletable by owner
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1458
                set(PERMISSIONS ${DEFAULT_PERMISSIONS} OWNER_EXECUTE)
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1459
            endif()
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1460
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1461
            if (DEFINED COR_INSTALL_PUBLIC_HEADER_CONFIGURATIONS)
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1462
                set(CONFIGURATIONS CONFIGURATIONS ${COR_INSTALL_PUBLIC_HEADER_CONFIGURATIONS})
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1463
            elseif (DEFINED COR_INSTALL_DEFAULT_CONFIGURATIONS)
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1464
                set(CONFIGURATIONS CONFIGURATIONS ${COR_INSTALL_DEFAULT_CONFIGURATIONS})
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1465
            else()
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1466
                set(CONFIGURATIONS)
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1467
            endif()
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1468
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1469
            get_target_property(FILE_SET ${INSTALL_TARGET} INTERFACE_HEADER_SETS)
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1470
            if(NOT FILE_SET OR FILE_SET MATCHES .*-NOTFOUND)
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1471
                set(TARGET_HAS_FILE_SET FALSE)
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1472
            else()
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1473
                set(TARGET_HAS_FILE_SET TRUE)
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1474
            endif()
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1475
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1476
            if(NOT TARGET_HAS_FILE_SET)
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1477
                if(EXPORT_NAME)
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1478
                    # We still need to generate a EXPORT but we can't do that with install(DIRECTORY)
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1479
                    install(TARGETS ${INSTALL_TARGET} ${EXPORT_NAME})
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1480
                endif()
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1481
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1482
                set(PUBLIC_HEADER_PROPERTIES INCLUDE_DIRECTORIES PUBLIC_INCLUDE_DIRECTORIES INTERFACE_INCLUDE_DIRECTORIES)
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1483
                foreach(PUBLIC_HEADER_PROPERTY ${PUBLIC_HEADER_PROPERTIES})
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1484
                    get_target_property(PUBLIC_HEADER ${INSTALL_TARGET} ${PUBLIC_HEADER_PROPERTY})
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1485
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1486
                    if(NOT PUBLIC_HEADER MATCHES .*-NOTFOUND)
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1487
                        foreach(INCLUDE_DIRECTORY ${PUBLIC_HEADER})
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1488
                            install(
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1489
                                    DIRECTORY ${INCLUDE_DIRECTORY}
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1490
                                    DESTINATION .
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1491
                                    FILE_PERMISSIONS ${PERMISSIONS}
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1492
                                    DIRECTORY_PERMISSIONS ${PERMISSIONS}
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1493
                                    ${CONFIGURATIONS}
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1494
                            )
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1495
                        endforeach()
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1496
                    endif()
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1497
                endforeach()
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1498
            else()
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1499
                install(
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1500
                        TARGETS ${INSTALL_TARGET}
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1501
                        ${EXPORT_NAME}
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1502
                        FILE_SET HEADERS
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1503
                        DESTINATION ${DESTINATION}
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1504
                        PERMISSIONS ${PERMISSIONS}
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1505
                        ${CONFIGURATIONS}
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1506
                )
16021
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1507
            endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1508
        endforeach()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1509
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1510
    elseif(INSTALL_TYPE STREQUAL "EXPORT")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1511
        message(FATAL_ERROR "install(EXPORT ...) not yet implemented")
16038
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1512
    else()
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1513
        message(FATAL_ERROR "Unknown arg: ${INSTALL_TYPE}")
16021
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1514
    endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1515
endfunction()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1516
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1517
#[=======================================================================[.md:
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1518
** EXPERIMENTAL **: This function is currently still considered experimental
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1519
  and is not officially released yet. Feedback and Suggestions are welcome.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1520
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1521
ANCHOR: corrosion_add_cxxbridge
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1522
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1523
```cmake
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1524
corrosion_add_cxxbridge(cxx_target
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1525
        CRATE <imported_target_name>
16038
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1526
        REGEN_TARGET <regen_target_name>
16021
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1527
        [FILES <file1.rs> <file2.rs>]
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1528
)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1529
```
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1530
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1531
Adds build-rules to create C++ bindings using the [cxx] crate.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1532
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1533
### Arguments:
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1534
* `cxxtarget`: Name of the C++ library target for the bindings, which corrosion will create.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1535
* **FILES**: Input Rust source file containing #[cxx::bridge].
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1536
* **CRATE**: Name of an imported Rust target. Note: Parameter may be renamed before release
16038
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1537
* **REGEN_TARGET**: Name of a custom target that will regenerate the cxx bindings **without** recompiling. Note: Parameter may be renamed before release
16021
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1538
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1539
#### Currently missing arguments
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1540
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1541
The following arguments to cxxbridge **currently** have no way to be passed by the user:
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1542
- `--cfg`
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1543
- `--cxx-impl-annotations`
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1544
- `--include`
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1545
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1546
The created rules approximately do the following:
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1547
- Check which version of `cxx` the Rust crate specified by the `CRATE` argument depends on.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1548
- Check if the exact same version of `cxxbridge-cmd` is installed (available in `PATH`)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1549
- If not, create a rule to build the exact same version of `cxxbridge-cmd`.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1550
- Create rules to run `cxxbridge` and generate
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1551
  - The `rust/cxx.h` header
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1552
  - A header and source file for each of the files specified in `FILES`
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1553
- The generated sources (and header include directories) are added to the `cxxtarget` CMake
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1554
  library target.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1555
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1556
### Limitations
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1557
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1558
We currently require the `CRATE` argument to be a target imported by Corrosion, however,
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1559
Corrosion does not import `rlib` only libraries. As a workaround users can add
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1560
`staticlib` to their list of crate kinds. In the future this may be solved more properly,
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1561
by either adding an option to also import Rlib targets (without build rules) or by
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1562
adding a `MANIFEST_PATH` argument to this function, specifying where the crate is.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1563
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1564
### Contributing
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1565
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1566
Specifically some more realistic test / demo projects and feedback about limitations would be
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1567
welcome.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1568
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1569
[cxx]: https://github.com/dtolnay/cxx
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1570
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1571
ANCHOR_END: corrosion_add_cxxbridge
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1572
#]=======================================================================]
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1573
function(corrosion_add_cxxbridge cxx_target)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1574
    set(OPTIONS)
16038
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1575
    set(ONE_VALUE_KEYWORDS CRATE REGEN_TARGET)
16021
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1576
    set(MULTI_VALUE_KEYWORDS FILES)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1577
    cmake_parse_arguments(PARSE_ARGV 1 _arg "${OPTIONS}" "${ONE_VALUE_KEYWORDS}" "${MULTI_VALUE_KEYWORDS}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1578
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1579
    set(required_keywords CRATE FILES)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1580
    foreach(keyword ${required_keywords})
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1581
        if(NOT DEFINED "_arg_${keyword}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1582
            message(FATAL_ERROR "Missing required parameter `${keyword}`.")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1583
        elseif("${_arg_${keyword}}" STREQUAL "")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1584
            message(FATAL_ERROR "Required parameter `${keyword}` may not be set to an empty string.")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1585
        endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1586
    endforeach()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1587
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1588
    get_target_property(manifest_path "${_arg_CRATE}" INTERFACE_COR_PACKAGE_MANIFEST_PATH)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1589
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1590
    if(NOT EXISTS "${manifest_path}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1591
        message(FATAL_ERROR "Internal error: No package manifest found at ${manifest_path}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1592
    endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1593
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1594
    get_filename_component(manifest_dir ${manifest_path} DIRECTORY)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1595
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1596
    execute_process(COMMAND ${CMAKE_COMMAND} -E env
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1597
        "CARGO_BUILD_RUSTC=${_CORROSION_RUSTC}"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1598
        ${_CORROSION_CARGO} tree -i cxx --depth=0
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1599
        WORKING_DIRECTORY "${manifest_dir}"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1600
        RESULT_VARIABLE cxx_version_result
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1601
        OUTPUT_VARIABLE cxx_version_output
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1602
    )
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1603
    if(NOT "${cxx_version_result}" EQUAL "0")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1604
        message(FATAL_ERROR "Crate ${_arg_CRATE} does not depend on cxx.")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1605
    endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1606
    if(cxx_version_output MATCHES "cxx v([0-9]+.[0-9]+.[0-9]+)")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1607
        set(cxx_required_version "${CMAKE_MATCH_1}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1608
    else()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1609
        message(FATAL_ERROR "Failed to parse cxx version from cargo tree output: `cxx_version_output`")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1610
    endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1611
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1612
    # First check if a suitable version of cxxbridge is installed
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1613
    find_program(INSTALLED_CXXBRIDGE cxxbridge PATHS "$ENV{HOME}/.cargo/bin/")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1614
    mark_as_advanced(INSTALLED_CXXBRIDGE)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1615
    if(INSTALLED_CXXBRIDGE)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1616
        execute_process(COMMAND ${INSTALLED_CXXBRIDGE} --version OUTPUT_VARIABLE cxxbridge_version_output)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1617
        if(cxxbridge_version_output MATCHES "cxxbridge ([0-9]+.[0-9]+.[0-9]+)")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1618
            set(cxxbridge_version "${CMAKE_MATCH_1}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1619
        else()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1620
            set(cxxbridge_version "")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1621
        endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1622
    endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1623
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1624
    set(cxxbridge "")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1625
    if(cxxbridge_version)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1626
        if(cxxbridge_version VERSION_EQUAL cxx_required_version)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1627
            set(cxxbridge "${INSTALLED_CXXBRIDGE}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1628
            if(NOT TARGET "cxxbridge_v${cxx_required_version}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1629
                # Add an empty target.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1630
                add_custom_target("cxxbridge_v${cxx_required_version}"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1631
                    )
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1632
            endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1633
        endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1634
    endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1635
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1636
    # No suitable version of cxxbridge was installed, so use custom target to build correct version.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1637
    if(NOT cxxbridge)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1638
        if(NOT TARGET "cxxbridge_v${cxx_required_version}")
16038
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1639
            unset(executable_postfix)
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1640
            if(Rust_CARGO_HOST_OS STREQUAL "windows")
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1641
                set(executable_postfix ".exe")
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1642
            endif()
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1643
            add_custom_command(OUTPUT "${CMAKE_BINARY_DIR}/corrosion/cxxbridge_v${cxx_required_version}/bin/cxxbridge${executable_postfix}"
16021
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1644
                COMMAND
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1645
                ${CMAKE_COMMAND} -E make_directory "${CMAKE_BINARY_DIR}/corrosion/cxxbridge_v${cxx_required_version}"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1646
                COMMAND
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1647
                    ${CMAKE_COMMAND} -E env
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1648
                        "CARGO_BUILD_RUSTC=${_CORROSION_RUSTC}"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1649
                    ${_CORROSION_CARGO} install
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1650
                    cxxbridge-cmd
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1651
                    --version "${cxx_required_version}"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1652
                    --root "${CMAKE_BINARY_DIR}/corrosion/cxxbridge_v${cxx_required_version}"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1653
                    --quiet
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1654
                    # todo: use --target-dir to potentially reuse artifacts
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1655
                COMMENT "Building cxxbridge (version ${cxx_required_version})"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1656
                )
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1657
            add_custom_target("cxxbridge_v${cxx_required_version}"
16038
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1658
                DEPENDS "${CMAKE_BINARY_DIR}/corrosion/cxxbridge_v${cxx_required_version}/bin/cxxbridge${executable_postfix}"
16021
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1659
                )
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1660
        endif()
16038
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1661
        set(cxxbridge "${CMAKE_BINARY_DIR}/corrosion/cxxbridge_v${cxx_required_version}/bin/cxxbridge${executable_postfix}")
16021
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1662
    endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1663
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1664
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1665
    # The generated folder structure will be of the following form
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1666
    #
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1667
    #    CMAKE_CURRENT_BINARY_DIR
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1668
    #        corrosion_generated
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1669
    #            cxxbridge
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1670
    #                <cxx_target>
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1671
    #                    include
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1672
    #                        <cxx_target>
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1673
    #                            <headers>
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1674
    #                        rust
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1675
    #                            cxx.h
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1676
    #                    src
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1677
    #                        <sourcefiles>
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1678
    #            cbindgen
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1679
    #                ...
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1680
    #            other
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1681
    #                ...
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1682
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1683
    set(corrosion_generated_dir "${CMAKE_CURRENT_BINARY_DIR}/corrosion_generated")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1684
    set(generated_dir "${corrosion_generated_dir}/cxxbridge/${cxx_target}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1685
    set(header_placement_dir "${generated_dir}/include/${cxx_target}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1686
    set(source_placement_dir "${generated_dir}/src")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1687
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1688
    add_library(${cxx_target} STATIC)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1689
    target_include_directories(${cxx_target}
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1690
        PUBLIC
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1691
            $<BUILD_INTERFACE:${generated_dir}/include>
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1692
            $<INSTALL_INTERFACE:include>
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1693
    )
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1694
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1695
    # cxx generated code is using c++11 features in headers, so propagate c++11 as minimal requirement
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1696
    target_compile_features(${cxx_target} PUBLIC cxx_std_11)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1697
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1698
    # Todo: target_link_libraries is only necessary for rust2c projects.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1699
    # It is possible that checking if the rust crate is an executable is a sufficient check,
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1700
    # but some more thought may be needed here.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1701
    # Maybe we should also let the user do this, since for c2rust, the user also has to call
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1702
    # corrosion_link_libraries() themselves.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1703
    get_target_property(crate_target_type ${_arg_CRATE} TYPE)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1704
    if (NOT crate_target_type STREQUAL "EXECUTABLE")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1705
        target_link_libraries(${cxx_target} PRIVATE ${_arg_CRATE})
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1706
    endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1707
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1708
    file(MAKE_DIRECTORY "${generated_dir}/include/rust")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1709
    add_custom_command(
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1710
            OUTPUT "${generated_dir}/include/rust/cxx.h"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1711
            COMMAND
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1712
            ${cxxbridge} --header --output "${generated_dir}/include/rust/cxx.h"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1713
            DEPENDS "cxxbridge_v${cxx_required_version}"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1714
            COMMENT "Generating rust/cxx.h header"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1715
    )
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1716
16038
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1717
    set(GENERATED_FILES "${generated_dir}/include/rust/cxx.h")
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1718
16021
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1719
    foreach(filepath ${_arg_FILES})
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1720
        get_filename_component(filename ${filepath} NAME_WE)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1721
        get_filename_component(directory ${filepath} DIRECTORY)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1722
        set(directory_component "")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1723
        if(directory)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1724
            set(directory_component "${directory}/")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1725
        endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1726
        # todo: convert potentially absolute paths to relative paths..
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1727
        set(cxx_header ${directory_component}${filename}.h)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1728
        set(cxx_source ${directory_component}${filename}.cpp)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1729
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1730
        # todo: not all projects may use the `src` directory.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1731
        set(rust_source_path "${manifest_dir}/src/${filepath}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1732
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1733
        file(MAKE_DIRECTORY "${header_placement_dir}/${directory}" "${source_placement_dir}/${directory}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1734
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1735
        add_custom_command(
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1736
            OUTPUT
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1737
            "${header_placement_dir}/${cxx_header}"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1738
            "${source_placement_dir}/${cxx_source}"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1739
            COMMAND
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1740
                ${cxxbridge} ${rust_source_path} --header --output "${header_placement_dir}/${cxx_header}"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1741
            COMMAND
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1742
                ${cxxbridge} ${rust_source_path}
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1743
                    --output "${source_placement_dir}/${cxx_source}"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1744
                    --include "${cxx_target}/${cxx_header}"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1745
            DEPENDS "cxxbridge_v${cxx_required_version}" "${rust_source_path}"
16038
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1746
            COMMENT "Generating cxx bindings for crate ${_arg_CRATE} and file src/${filepath}"
16021
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1747
        )
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1748
16038
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1749
        list(APPEND GENERATED_FILES
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1750
            "${header_placement_dir}/${cxx_header}"
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1751
            "${source_placement_dir}/${cxx_source}")
16021
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1752
    endforeach()
16038
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1753
    target_sources(${cxx_target} PRIVATE ${GENERATED_FILES})
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1754
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1755
    if(DEFINED _arg_REGEN_TARGET)
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1756
        add_custom_target(${_arg_REGEN_TARGET}
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1757
            DEPENDS ${GENERATED_FILES}
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1758
            COMMENT "Generated cxx bindings for crate ${_arg_CRATE}")
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1759
    endif()
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1760
16021
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1761
endfunction()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1762
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1763
#[=======================================================================[.md:
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1764
ANCHOR: corrosion_cbindgen
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1765
```cmake
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1766
corrosion_cbindgen(
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1767
        TARGET <imported_target_name>
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1768
        HEADER_NAME <output_header_name>
16038
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1769
        [CARGO_PACKAGE <cargo_package_name>]
16021
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1770
        [MANIFEST_DIRECTORY <package_manifest_directory>]
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1771
        [CBINDGEN_VERSION <version>]
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1772
        [FLAGS <flag1> ... <flagN>]
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1773
)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1774
```
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1775
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1776
A helper function which uses [cbindgen] to generate C/C++ bindings for a Rust crate.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1777
If `cbindgen` is not in `PATH` the helper function will automatically try to download
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1778
`cbindgen` and place the built binary into `CMAKE_BINARY_DIR`. The binary is shared
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1779
between multiple invocations of this function.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1780
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1781
16038
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1782
* **TARGET**: The name of an imported Rust library target, for which bindings should be generated.
16021
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1783
              If the target was not previously imported by Corrosion, because the crate only produces an
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1784
              `rlib`, you must additionally specify `MANIFEST_DIRECTORY`.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1785
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1786
* **MANIFEST_DIRECTORY**: Directory of the package defining the library crate bindings should be generated for.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1787
    If you want to avoid specifying `MANIFEST_DIRECTORY` you could add a `staticlib` target to your package
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1788
    manifest as a workaround to make corrosion import the crate.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1789
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1790
* **HEADER_NAME**: The name of the generated header file. This will be the name which you include in your C/C++ code
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1791
                    (e.g. `#include "myproject/myheader.h" if you specify `HEADER_NAME "myproject/myheader.h"`.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1792
* **CBINDGEN_VERSION**: Version requirement for cbindgen. Exact semantics to be specified. Currently not implemented.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1793
* **FLAGS**: Arbitrary other flags for `cbindgen`. Run `cbindgen --help` to see the possible flags.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1794
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1795
[cbindgen]: https://github.com/eqrion/cbindgen
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1796
16038
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1797
### Current limitations
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1798
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1799
- Cbindgens (optional) macro expansion feature internally actually builds the crate / runs the build script.
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1800
  For this to work as expected in all cases, we probably need to set all the same environment variables
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1801
  as when corrosion builds the crate. However the crate is a **library**, so we would need to figure out which
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1802
  target builds it - and if there are multiple, potentially generate bindings per-target?
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1803
  Alternatively we could add support of setting some environment variables on rlibs, and pulling that
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1804
  information in when building the actual corrosion targets
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1805
  Alternatively we could restrict corrosions support of this feature to actual imported staticlib/cdylib targets.
16021
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1806
ANCHOR_END: corrosion_cbindgen
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1807
#]=======================================================================]
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1808
function(corrosion_experimental_cbindgen)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1809
    set(OPTIONS "")
16038
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1810
    set(ONE_VALUE_KEYWORDS
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1811
            TARGET
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1812
            MANIFEST_DIRECTORY
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1813
            HEADER_NAME
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1814
            CBINDGEN_VERSION)
16021
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1815
    set(MULTI_VALUE_KEYWORDS "FLAGS")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1816
    cmake_parse_arguments(PARSE_ARGV 0 CCN "${OPTIONS}" "${ONE_VALUE_KEYWORDS}" "${MULTI_VALUE_KEYWORDS}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1817
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1818
    set(required_keywords TARGET HEADER_NAME)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1819
    foreach(keyword ${required_keywords})
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1820
        if(NOT DEFINED "CCN_${keyword}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1821
            message(FATAL_ERROR "Missing required parameter `${keyword}`.")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1822
        elseif("${CCN_${keyword}}" STREQUAL "")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1823
            message(FATAL_ERROR "Required parameter `${keyword}` may not be set to an empty string.")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1824
        endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1825
    endforeach()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1826
    set(rust_target "${CCN_TARGET}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1827
    unset(package_manifest_dir)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1828
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1829
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1830
    set(hostbuild_override "$<BOOL:$<TARGET_PROPERTY:${rust_target},${_CORR_PROP_HOST_BUILD}>>")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1831
    set(cbindgen_target_triple "$<IF:${hostbuild_override},${_CORROSION_RUST_CARGO_HOST_TARGET},${_CORROSION_RUST_CARGO_TARGET}>")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1832
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1833
    if(TARGET "${rust_target}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1834
        get_target_property(package_manifest_path "${rust_target}" INTERFACE_COR_PACKAGE_MANIFEST_PATH)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1835
        if(NOT EXISTS "${package_manifest_path}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1836
            message(FATAL_ERROR "Internal error: No package manifest found at ${package_manifest_path}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1837
        endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1838
        get_filename_component(package_manifest_dir "${package_manifest_path}" DIRECTORY)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1839
        # todo: as an optimization we could cache the cargo metadata output (but --no-deps makes that slightly more complicated)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1840
    else()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1841
        if(NOT DEFINED CCN_MANIFEST_DIRECTORY)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1842
            message(FATAL_ERROR
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1843
                "`${rust_target}` is not a target imported by corrosion and `MANIFEST_DIRECTORY` was not provided."
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1844
            )
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1845
        else()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1846
            set(package_manifest_dir "${CCN_MANIFEST_DIRECTORY}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1847
        endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1848
    endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1849
16038
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1850
    get_target_property(rust_cargo_package "${rust_target}" COR_CARGO_PACKAGE_NAME )
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1851
    if(NOT rust_cargo_package)
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1852
        message(FATAL_ERROR "Internal Error: Could not determine cargo package name for cbindgen. "
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1853
        )
16021
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1854
    endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1855
    message(STATUS "Using package ${rust_cargo_package} as crate for cbindgen")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1856
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1857
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1858
    set(output_header_name "${CCN_HEADER_NAME}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1859
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1860
    find_program(installed_cbindgen cbindgen)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1861
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1862
    # Install the newest cbindgen version into our build tree.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1863
    if(installed_cbindgen)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1864
        set(cbindgen "${installed_cbindgen}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1865
    else()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1866
        set(local_cbindgen_install_dir "${CMAKE_BINARY_DIR}/corrosion/cbindgen")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1867
        unset(executable_postfix)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1868
        if(Rust_CARGO_HOST_OS STREQUAL "windows")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1869
            set(executable_postfix ".exe")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1870
        endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1871
        set(cbindgen "${local_cbindgen_install_dir}/bin/cbindgen${executable_postfix}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1872
        if(NOT TARGET "_corrosion_cbindgen")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1873
            file(MAKE_DIRECTORY "${local_cbindgen_install_dir}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1874
            add_custom_command(OUTPUT "${cbindgen}"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1875
                COMMAND ${CMAKE_COMMAND}
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1876
                -E env
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1877
                "CARGO_BUILD_RUSTC=${_CORROSION_RUSTC}"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1878
                ${_CORROSION_CARGO} install
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1879
                    cbindgen
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1880
                    --root "${local_cbindgen_install_dir}"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1881
                    ${_CORROSION_QUIET_OUTPUT_FLAG}
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1882
                COMMENT "Building cbindgen"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1883
                )
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1884
            add_custom_target("_corrosion_cbindgen"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1885
                DEPENDS "${cbindgen}"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1886
                )
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1887
        endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1888
    endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1889
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1890
    set(corrosion_generated_dir "${CMAKE_CURRENT_BINARY_DIR}/corrosion_generated")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1891
    set(generated_dir "${corrosion_generated_dir}/cbindgen/${rust_target}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1892
    set(header_placement_dir "${generated_dir}/include/")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1893
    set(depfile_placement_dir "${generated_dir}/depfile")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1894
    set(generated_depfile "${depfile_placement_dir}/${output_header_name}.d")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1895
    set(generated_header "${header_placement_dir}/${output_header_name}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1896
    message(STATUS "rust target is ${rust_target}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1897
    if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.23")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1898
        target_sources(${rust_target}
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1899
            INTERFACE
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1900
            FILE_SET HEADERS
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1901
            BASE_DIRS "${header_placement_dir}"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1902
            FILES "${header_placement_dir}/${output_header_name}"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1903
        )
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1904
    else()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1905
        # Note: not clear to me how install would best work before CMake 3.23
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1906
        target_include_directories(${rust_target}
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1907
            INTERFACE
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1908
            $<BUILD_INTERFACE:${header_placement_dir}>
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1909
            $<INSTALL_INTERFACE:include>
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1910
            )
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1911
    endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1912
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1913
    # This may be different from $header_placement_dir since the user specified HEADER_NAME may contain
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1914
    # relative directories.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1915
    get_filename_component(generated_header_dir "${generated_header}" DIRECTORY)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1916
    file(MAKE_DIRECTORY "${generated_header_dir}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1917
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1918
    unset(depfile_cbindgen_arg)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1919
    unset(depfile_cmake_arg)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1920
    get_filename_component(generated_depfile_dir "${generated_depfile}" DIRECTORY)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1921
    file(MAKE_DIRECTORY "${generated_depfile_dir}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1922
    set(depfile_cbindgen_arg "--depfile=${generated_depfile}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1923
16038
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1924
    add_custom_command(
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1925
        OUTPUT
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1926
        "${generated_header}"
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1927
        COMMAND
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1928
        "${CMAKE_COMMAND}" -E env
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1929
            TARGET="${cbindgen_target_triple}"
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1930
            "${cbindgen}"
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1931
                    --output "${generated_header}"
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1932
                    --crate "${rust_cargo_package}"
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1933
                    ${depfile_cbindgen_arg}
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1934
                    ${CCN_FLAGS}
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1935
        COMMENT "Generate cbindgen bindings for package ${rust_cargo_package} and output header ${generated_header}"
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1936
        DEPFILE "${generated_depfile}"
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1937
        COMMAND_EXPAND_LISTS
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1938
        WORKING_DIRECTORY "${package_manifest_dir}"
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1939
    )
16021
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1940
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1941
    if(NOT installed_cbindgen)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1942
        add_custom_command(
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1943
            OUTPUT "${generated_header}"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1944
            APPEND
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1945
            DEPENDS _corrosion_cbindgen
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1946
        )
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1947
    endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1948
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1949
    if(NOT TARGET "_corrosion_cbindgen_${rust_target}_bindings")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1950
        add_custom_target(_corrosion_cbindgen_${rust_target}_bindings
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1951
                COMMENT "Generate cbindgen bindings for package ${rust_cargo_package}"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1952
        )
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1953
    endif()
16038
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1954
    # Users might want to call cbindgen multiple times, e.g. to generate separate C++ and C header files.
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1955
    string(MAKE_C_IDENTIFIER "${output_header_name}" header_identifier )
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1956
    add_custom_target("_corrosion_cbindgen_${rust_target}_bindings_${header_identifier}"
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1957
            DEPENDS "${generated_header}"
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1958
            COMMENT "Generate ${generated_header} for ${rust_target}"
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  1959
    )
16021
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1960
    add_dependencies("_corrosion_cbindgen_${rust_target}_bindings" "_corrosion_cbindgen_${rust_target}_bindings_${header_identifier}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1961
    add_dependencies(${rust_target} "_corrosion_cbindgen_${rust_target}_bindings")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1962
endfunction()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1963
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1964
# Parse the version of a Rust package from it's package manifest (Cargo.toml)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1965
function(corrosion_parse_package_version package_manifest_path out_package_version)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1966
    if(NOT EXISTS "${package_manifest_path}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1967
        message(FATAL_ERROR "Package manifest `${package_manifest_path}` does not exist.")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1968
    endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1969
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1970
    file(READ "${package_manifest_path}" package_manifest)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1971
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1972
    # Find the package table. It may contain arrays, so match until \n\[, which should mark the next
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1973
    # table. Note: backslashes must be doubled to escape the backslash for the bracket. LF is single
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1974
    # backslash however. On windows the line also ends in \n, so matching against \n\[ is sufficient
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1975
    # to detect an opening bracket on a new line.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1976
    set(package_table_regex "\\[package\\](.*)\n\\[")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1977
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1978
    string(REGEX MATCH "${package_table_regex}" _package_table "${package_manifest}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1979
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1980
    if(CMAKE_MATCH_COUNT EQUAL "1")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1981
        set(package_table "${CMAKE_MATCH_1}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1982
    else()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1983
        message(DEBUG
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1984
                "Failed to find `[package]` table in package manifest `${package_manifest_path}`.\n"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1985
                "Matches: ${CMAKE_MATCH_COUNT}\n"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1986
        )
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1987
        set(${out_package_version}
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1988
            "NOTFOUND"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1989
            PARENT_SCOPE
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1990
        )
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1991
    endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1992
    # Match `version = "0.3.2"`, `"version" = "0.3.2" Contains one matching group for the version
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1993
    set(version_regex "[\r]?\n[\"']?version[\"']?[ \t]*=[ \t]*[\"']([0-9\.]+)[\"']")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1994
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1995
    string(REGEX MATCH "${version_regex}" _version "${package_table}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1996
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1997
    if("${package_table}" MATCHES "${version_regex}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1998
        set(${out_package_version}
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  1999
            "${CMAKE_MATCH_1}"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  2000
            PARENT_SCOPE
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  2001
        )
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  2002
    else()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  2003
        message(DEBUG "Failed to extract package version from manifest `${package_manifest_path}`.")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  2004
        set(${out_package_version}
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  2005
            "NOTFOUND"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  2006
            PARENT_SCOPE
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  2007
        )
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  2008
    endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  2009
endfunction()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  2010
16038
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  2011
function(_corrosion_initialize_properties target_name)
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  2012
    # Initialize the `<XYZ>_OUTPUT_DIRECTORY` properties based on `CMAKE_<XYZ>_OUTPUT_DIRECTORY`.
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  2013
    foreach(output_var RUNTIME_OUTPUT_DIRECTORY ARCHIVE_OUTPUT_DIRECTORY LIBRARY_OUTPUT_DIRECTORY PDB_OUTPUT_DIRECTORY)
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  2014
        if (DEFINED "CMAKE_${output_var}")
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  2015
            set_property(TARGET ${target_name} PROPERTY "${output_var}" "${CMAKE_${output_var}}")
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  2016
        endif()
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  2017
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  2018
        foreach(config_type ${CMAKE_CONFIGURATION_TYPES})
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  2019
            string(TOUPPER "${config_type}" config_type_upper)
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  2020
            if (DEFINED "CMAKE_${output_var}_${config_type_upper}")
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  2021
                set_property(TARGET ${target_name} PROPERTY "${output_var}_${config_type_upper}" "${CMAKE_${output_var}_${config_type_upper}}")
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  2022
            endif()
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  2023
        endforeach()
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  2024
    endforeach()
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  2025
endfunction()
d903f8d2395a - Update corrosion
unC0Rr
parents: 16021
diff changeset
  2026
16021
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  2027
# Helper macro to pass through an optional `OPTION` argument parsed via `cmake_parse_arguments`
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  2028
# to another function that takes the same OPTION.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  2029
# If the option was set, then the variable <var_name> will be set to the same option name again,
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  2030
# otherwise <var_name> will be unset.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  2031
macro(_corrosion_option_passthrough_helper option_name prefix var_name)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  2032
    if(${${prefix}_${option_name}})
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  2033
        set("${var_name}" "${option_name}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  2034
    else()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  2035
        unset("${var_name}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  2036
    endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  2037
endmacro()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  2038
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  2039
# Helper macro to pass through an optional argument with value(s), parsed via `cmake_parse_arguments`,
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  2040
# to another function that takes the same keyword + associated values.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  2041
# If the argument was given, then the variable <var_name> will be a list of the argument name and the values,
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  2042
# which will be expanded, when calling the function (assuming no quotes).
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  2043
macro(_corrosion_arg_passthrough_helper arg_name prefix var_name)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  2044
    if(DEFINED "${prefix}_${arg_name}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  2045
        set("${var_name}" "${arg_name}" "${${prefix}_${arg_name}}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  2046
    else()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  2047
        unset("${var_name}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  2048
    endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  2049
endmacro()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  2050
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  2051
list(POP_BACK CMAKE_MESSAGE_CONTEXT)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
  2052