|
1 | 1 | cmake_minimum_required(VERSION 3.12)
|
2 |
| -project(wasmtime C) |
| 2 | +project(wasmtime) |
3 | 3 |
|
4 | 4 | set(WASMTIME_USER_CARGO_BUILD_OPTIONS "" CACHE STRING "Additional cargo flags (such as --features) to apply to the build command")
|
5 | 5 | option(BUILD_SHARED_LIBS "Build using shared libraries" OFF)
|
| 6 | +option(BUILD_TESTS "Build tests" ON) |
6 | 7 | option(WASMTIME_ALWAYS_BUILD "If cmake should always invoke cargo to build wasmtime" ON)
|
7 | 8 | option(WASMTIME_FASTEST_RUNTIME "Set flags designed to optimize runtime performance" OFF)
|
8 | 9 | set(WASMTIME_TARGET "" CACHE STRING "Rust target to build for")
|
@@ -129,3 +130,43 @@ add_custom_target(headers-to-doc
|
129 | 130 | -DWASMTIME_HEADER_DST=${CMAKE_BINARY_DIR}/include
|
130 | 131 | -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/install-headers.cmake
|
131 | 132 | DEPENDS ${headers})
|
| 133 | + |
| 134 | +if (NOT CMAKE_CXX_STANDARD) |
| 135 | + message(STATUS "Cannot detect C++ Standard. Switching to C++17 by default !!") |
| 136 | + set(CMAKE_CXX_STANDARD 17) |
| 137 | +endif() |
| 138 | +message(STATUS "CMAKE_CXX_STANDARD is ${CMAKE_CXX_STANDARD}") |
| 139 | +if (NOT CMAKE_CXX_STANDARD GREATER_EQUAL 17) |
| 140 | + message(FATAL_ERROR "WASMTIME_CPP library does not support ${CMAKE_CXX_STANDARD}") |
| 141 | +endif() |
| 142 | +set(CMAKE_CXX_STANDARD_REQUIRED True) |
| 143 | + |
| 144 | +option(ENABLE_CODE_ANALYSIS "Run code analysis" OFF) |
| 145 | +message(STATUS "ENABLE_CODE_ANALYSIS ${ENABLE_CODE_ANALYSIS}") |
| 146 | + |
| 147 | +if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") |
| 148 | + add_compile_options (-fdiagnostics-color=always) |
| 149 | +elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") |
| 150 | + add_compile_options (-fcolor-diagnostics) |
| 151 | +endif () |
| 152 | + |
| 153 | +add_library(wasmtime-cpp INTERFACE) |
| 154 | +target_link_libraries(wasmtime-cpp INTERFACE wasmtime) |
| 155 | +if (MSVC) |
| 156 | + target_compile_options(wasmtime-cpp INTERFACE /DWASM_API_EXTERN= /DWASI_API_EXTERN=) |
| 157 | + target_link_libraries(wasmtime-cpp INTERFACE ws2_32 bcrypt advapi32 userenv ntdll shell32 ole32) |
| 158 | +else() |
| 159 | + target_link_libraries(wasmtime-cpp INTERFACE stdc++ pthread) |
| 160 | +endif() |
| 161 | + |
| 162 | +target_include_directories( |
| 163 | + wasmtime-cpp |
| 164 | + INTERFACE |
| 165 | + ${PROJECT_SOURCE_DIR}/include) |
| 166 | + |
| 167 | +if (BUILD_TESTS) |
| 168 | + message(STATUS "Building tests") |
| 169 | + set(INSTALL_GTEST OFF CACHE BOOL "" FORCE) |
| 170 | + enable_testing() |
| 171 | + add_subdirectory(tests) |
| 172 | +endif() |
0 commit comments