tools/corrosion/CMakeLists.txt
author unC0Rr
Mon, 16 Sep 2024 16:57:11 +0200
branchtransitional_engine
changeset 16063 09beeec033ba
parent 16050 6a3dc15b78b9
child 16067 d903f8d2395a
permissions -rw-r--r--
Sanitize maze mapgen code a bit
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
16050
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
     1
cmake_minimum_required(VERSION 3.15)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
     2
project(Corrosion
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
     3
    # Official releases will be major.minor.patch. When the `tweak` field is
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
     4
    # set it indicates that we are on a commit, that is not a officially
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
     5
    # tagged release. Users don't need to care about this, it is mainly to
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
     6
    # clearly see in configure logs which version was used, without needing to
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
     7
    # rely on `git`, since Corrosion may be installed or otherwise packaged.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
     8
    VERSION 0.5.0
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
     9
    LANGUAGES NONE
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    10
    HOMEPAGE_URL "https://corrosion-rs.github.io/corrosion/"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    11
)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    12
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    13
# Default behavior:
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    14
# - If the project is being used as a subdirectory, then don't build tests and
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    15
#   don't enable any languages.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    16
# - If this is a top level project, then build tests and enable the C++ compiler
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    17
if (NOT CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    18
    set(_CORROSION_TOP_LEVEL OFF)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    19
else()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    20
    set(_CORROSION_TOP_LEVEL ON)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    21
endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    22
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    23
# ==== Corrosion Configuration ====
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    24
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    25
option(
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    26
    CORROSION_DEV_MODE
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    27
    "Enables some additional features if you're developing Corrosion"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    28
    ${_CORROSION_TOP_LEVEL}
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    29
)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    30
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    31
option(
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    32
    CORROSION_BUILD_TESTS
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    33
    "Build Corrosion test project"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    34
    ${_CORROSION_TOP_LEVEL}
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
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    37
set(
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    38
  CORROSION_GENERATOR_EXECUTABLE CACHE STRING
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    39
  "Use prebuilt, non-bootstrapped corrosion-generator")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    40
mark_as_advanced(CORROSION_GENERATOR_EXECUTABLE)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    41
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    42
if (CORROSION_GENERATOR_EXECUTABLE)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    43
    add_executable(Corrosion::Generator IMPORTED GLOBAL)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    44
    set_property(
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    45
        TARGET Corrosion::Generator
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    46
        PROPERTY IMPORTED_LOCATION ${CORROSION_GENERATOR_EXECUTABLE})
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    47
    set(CORROSION_INSTALL_EXECUTABLE_DEFAULT OFF)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    48
elseif(CORROSION_NATIVE_TOOLING OR CMAKE_VERSION VERSION_LESS 3.19.0)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    49
        set(CORROSION_INSTALL_EXECUTABLE_DEFAULT "ON")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    50
else()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    51
    set(CORROSION_INSTALL_EXECUTABLE_DEFAULT OFF)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    52
endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    53
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    54
option(
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    55
    CORROSION_INSTALL_EXECUTABLE
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    56
    "Controls whether corrosion-generator is installed with the package"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    57
    ${CORROSION_INSTALL_EXECUTABLE_DEFAULT}
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    58
)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    59
mark_as_advanced(CORROSION_INSTALL_EXECUTABLE)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    60
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    61
if (_CORROSION_TOP_LEVEL)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    62
    # We need to enable a language for corrosions test to work.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    63
    # For projects using corrosion this is not needed
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    64
    enable_language(C)
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
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    67
# This little bit self-hosts the Corrosion toolchain to build the generator
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    68
# tool.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    69
#
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    70
# It is strongly encouraged to install Corrosion separately and use
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    71
# `find_package(Corrosion REQUIRED)` instead if that works with your workflow.
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    72
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    73
include(Corrosion)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    74
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    75
# Testing
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    76
if (CORROSION_BUILD_TESTS)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    77
    include(CTest)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    78
    add_subdirectory(test)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    79
endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    80
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    81
# If Corrosion is a subdirectory, do not enable its install code
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    82
if (NOT _CORROSION_TOP_LEVEL)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    83
    return()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    84
endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    85
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    86
# Installation
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    87
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    88
include(GNUInstallDirs)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    89
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    90
if(CORROSION_INSTALL_EXECUTABLE)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    91
    get_property(
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    92
            _CORROSION_GENERATOR_EXE
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    93
            TARGET Corrosion::Generator PROPERTY IMPORTED_LOCATION
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
    install(PROGRAMS "${_CORROSION_GENERATOR_EXE}" DESTINATION "${CMAKE_INSTALL_FULL_LIBEXECDIR}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    96
else()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    97
    message(DEBUG "Not installing corrosion-generator since "
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    98
        "`CORROSION_INSTALL_EXECUTABLE` is set to ${CORROSION_INSTALL_EXECUTABLE}"
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
endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   101
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   102
# Generate the Config file
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   103
include(CMakePackageConfigHelpers)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   104
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   105
configure_package_config_file(
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   106
    cmake/CorrosionConfig.cmake.in CorrosionConfig.cmake
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   107
    INSTALL_DESTINATION
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   108
        "${CMAKE_INSTALL_FULL_LIBDIR}/cmake/Corrosion"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   109
)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   110
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   111
write_basic_package_version_file(
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   112
    "${CMAKE_CURRENT_BINARY_DIR}/CorrosionConfigVersion.cmake"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   113
    VERSION ${PROJECT_VERSION}
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   114
    COMPATIBILITY
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   115
        SameMinorVersion # TODO: Should be SameMajorVersion when 1.0 is released
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   116
    ARCH_INDEPENDENT
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   117
)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   118
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   119
install(
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   120
    FILES
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   121
        "${CMAKE_CURRENT_BINARY_DIR}/CorrosionConfig.cmake"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   122
        "${CMAKE_CURRENT_BINARY_DIR}/CorrosionConfigVersion.cmake"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   123
    DESTINATION
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   124
        "${CMAKE_INSTALL_FULL_LIBDIR}/cmake/Corrosion"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   125
)
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
# These CMake scripts are needed both for the install and as a subdirectory
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   128
install(
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   129
    FILES
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   130
        cmake/Corrosion.cmake
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   131
        cmake/CorrosionGenerator.cmake
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   132
        cmake/FindRust.cmake
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   133
    DESTINATION
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   134
        "${CMAKE_INSTALL_FULL_DATADIR}/cmake"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   135
)