# nanowasm, a tiny WebAssembly/Wasm interpreter # Copyright (C) 2023-2025 Xavier Del Campo Romero # # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at https://mozilla.org/MPL/2.0/. cmake_minimum_required(VERSION 3.19) project(nanowasm LANGUAGES C VERSION 0.0.0) option(NW_EXAMPLES "Build examples") option(NW_LOG "Enables logging to stderr") option(NW_LOG_CUSTOM "Allows user code to define nwp_log. Enables NW_LOG") option(NW_CHECK_CODE "Check opcodes inside code section (slow).") add_library(${PROJECT_NAME}) target_include_directories(${PROJECT_NAME} PUBLIC include PRIVATE private_include) set(compilers "GNU" "Clang" "TinyCC" ) if(NW_LOG_CUSTOM) set(NW_LOG ON) endif() foreach(c ${compilers}) if(CMAKE_C_COMPILER_ID STREQUAL ${c}) set(cflags_np -pedantic -Wall ) if(CMAKE_BUILD_TYPE STREQUAL "Debug") set(cflags_np ${cflags_np} -Og -g) else() set(cflags_np ${cflags_np} -Os) endif() break() endif() endforeach() include(CheckCompilerFlag) foreach(f ${cflags_np}) string(REPLACE "-" "_" var supported_${f}) check_compiler_flag(C ${f} ${var}) if(${var}) set(sup_cflags ${sup_cflags} ${f}) endif() endforeach() if(NW_LOG) target_compile_definitions(${PROJECT_NAME} PRIVATE NW_LOG) endif() if(NW_EXAMPLES) add_subdirectory(examples) endif() target_compile_options(${PROJECT_NAME} PRIVATE ${sup_cflags}) set_target_properties(${PROJECT_NAME} PROPERTIES C_STANDARD 90 C_EXTENSIONS OFF) add_subdirectory(src) install(TARGETS ${PROJECT_NAME})