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