|
| 1 | +cmake_minimum_required(VERSION 3.16) |
| 2 | +project(codegen VERSION 0.0.1 LANGUAGES CXX |
| 3 | + DESCRIPTION "The JSON Schema code generator" |
| 4 | + HOMEPAGE_URL "https://github.com/sourcemeta-research/codegen") |
| 5 | +list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake") |
| 6 | + |
| 7 | +# Options |
| 8 | +option(CODEGEN_IR "Build the Codegen IR library" ON) |
| 9 | +option(CODEGEN_TYPESCRIPT "Build the Codegen IR library" ON) |
| 10 | +option(CODEGEN_TESTS "Build the Codegen tests" OFF) |
| 11 | +option(CODEGEN_CONTRIB "Build the Codegen contrib programs" OFF) |
| 12 | +option(CODEGEN_DOCS "Build the Codegen docs" OFF) |
| 13 | +option(CODEGEN_INSTALL "Install the Codegen library" ON) |
| 14 | +option(CODEGEN_ADDRESS_SANITIZER "Build Codegen with an address sanitizer" OFF) |
| 15 | +option(CODEGEN_UNDEFINED_SANITIZER "Build Codegen with an undefined behavior sanitizer" OFF) |
| 16 | + |
| 17 | +if(CODEGEN_INSTALL) |
| 18 | + include(GNUInstallDirs) |
| 19 | + include(CMakePackageConfigHelpers) |
| 20 | + configure_package_config_file( |
| 21 | + config.cmake.in |
| 22 | + "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake" |
| 23 | + INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}") |
| 24 | + write_basic_package_version_file( |
| 25 | + "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake" |
| 26 | + COMPATIBILITY SameMajorVersion) |
| 27 | + install(FILES |
| 28 | + "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake" |
| 29 | + "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake" |
| 30 | + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" |
| 31 | + COMPONENT sourcemeta_codegen_dev) |
| 32 | +endif() |
| 33 | + |
| 34 | +find_package(Core REQUIRED) |
| 35 | + |
| 36 | +# Don't force downstream consumers on it |
| 37 | +if(PROJECT_IS_TOP_LEVEL) |
| 38 | + sourcemeta_enable_simd() |
| 39 | +endif() |
| 40 | + |
| 41 | +if(CODEGEN_IR) |
| 42 | + add_subdirectory(src/ir) |
| 43 | +endif() |
| 44 | + |
| 45 | +if(CODEGEN_TYPESCRIPT) |
| 46 | + add_subdirectory(src/typescript) |
| 47 | +endif() |
| 48 | + |
| 49 | +if(CODEGEN_CONTRIB) |
| 50 | + add_subdirectory(contrib) |
| 51 | +endif() |
| 52 | + |
| 53 | +if(CODEGEN_ADDRESS_SANITIZER) |
| 54 | + sourcemeta_sanitizer(TYPE address) |
| 55 | +elseif(CODEGEN_UNDEFINED_SANITIZER) |
| 56 | + sourcemeta_sanitizer(TYPE undefined) |
| 57 | +endif() |
| 58 | + |
| 59 | +if(CODEGEN_DOCS) |
| 60 | + sourcemeta_target_doxygen(CONFIG "${PROJECT_SOURCE_DIR}/doxygen/Doxyfile.in" |
| 61 | + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/website") |
| 62 | +endif() |
| 63 | + |
| 64 | +if(PROJECT_IS_TOP_LEVEL) |
| 65 | + sourcemeta_target_clang_format(SOURCES |
| 66 | + contrib/*.cc |
| 67 | + src/*.h src/*.cc |
| 68 | + test/*.h test/*.cc) |
| 69 | +endif() |
| 70 | + |
| 71 | +# Testing |
| 72 | +if(CODEGEN_TESTS) |
| 73 | + enable_testing() |
| 74 | + |
| 75 | + if(CODEGEN_IR) |
| 76 | + add_subdirectory(test/ir) |
| 77 | + endif() |
| 78 | + |
| 79 | + if(CODEGEN_TYPESCRIPT) |
| 80 | + add_subdirectory(test/typescript) |
| 81 | + endif() |
| 82 | + |
| 83 | + if(PROJECT_IS_TOP_LEVEL) |
| 84 | + # Otherwise we need the child project to link |
| 85 | + # against the sanitizers too. |
| 86 | + if(NOT CODEGEN_ADDRESS_SANITIZER AND NOT CODEGEN_UNDEFINED_SANITIZER) |
| 87 | + add_subdirectory(test/packaging) |
| 88 | + endif() |
| 89 | + endif() |
| 90 | +endif() |
0 commit comments