summaryrefslogtreecommitdiff
path: root/cmake
diff options
context:
space:
mode:
Diffstat (limited to 'cmake')
-rw-r--r--cmake/mcpc.cmake53
1 files changed, 53 insertions, 0 deletions
diff --git a/cmake/mcpc.cmake b/cmake/mcpc.cmake
new file mode 100644
index 0000000..8f396a7
--- /dev/null
+++ b/cmake/mcpc.cmake
@@ -0,0 +1,53 @@
+set(TINY_CONVMEM_MCPC_ROOT "${PROJECT_SOURCE_DIR}/third_party/mcpc")
+
+if(NOT EXISTS "${TINY_CONVMEM_MCPC_ROOT}/mcpc/mcpc.h")
+ message(FATAL_ERROR
+ "mcpc is not initialized. Run: git submodule update --init --recursive"
+ )
+endif()
+
+# The upstream CMake target at the pinned revision is incomplete. Keep this
+# source list aligned with mcpc/src/Makefile and do not modify the submodule.
+set(TINY_CONVMEM_MCPC_SOURCES
+ "${TINY_CONVMEM_MCPC_ROOT}/src/alloc.c"
+ "${TINY_CONVMEM_MCPC_ROOT}/src/log.c"
+ "${TINY_CONVMEM_MCPC_ROOT}/src/errcode.c"
+ "${TINY_CONVMEM_MCPC_ROOT}/src/anydata.c"
+ "${TINY_CONVMEM_MCPC_ROOT}/src/tool.c"
+ "${TINY_CONVMEM_MCPC_ROOT}/src/rsc.c"
+ "${TINY_CONVMEM_MCPC_ROOT}/src/prmpt.c"
+ "${TINY_CONVMEM_MCPC_ROOT}/src/server.c"
+ "${TINY_CONVMEM_MCPC_ROOT}/src/retbuf.c"
+ "${TINY_CONVMEM_MCPC_ROOT}/src/ucbr.c"
+ "${TINY_CONVMEM_MCPC_ROOT}/src/complt.c"
+ "${TINY_CONVMEM_MCPC_ROOT}/src/serlz.c"
+ "${TINY_CONVMEM_MCPC_ROOT}/src/mjson.c"
+)
+
+add_library(mcpc STATIC ${TINY_CONVMEM_MCPC_SOURCES})
+add_library(mcpc::mcpc ALIAS mcpc)
+
+target_include_directories(mcpc
+ SYSTEM PUBLIC "${TINY_CONVMEM_MCPC_ROOT}"
+ PRIVATE "${TINY_CONVMEM_MCPC_ROOT}/src"
+)
+target_compile_features(mcpc PUBLIC c_std_17)
+
+if(MSVC)
+ # These compatibility definitions affect mcpc's public headers as well as
+ # its implementation, so consumers must compile with the same view.
+ target_compile_definitions(mcpc PUBLIC
+ is_win=1
+ is_wincl=1
+ MCPC_C23PTCH_KW1
+ MCPC_C23PTCH_CKD1
+ MCPC_C23PTCH_UCHAR1
+ MCPC_C23GIVUP_FIXENUM
+ )
+ target_compile_options(mcpc PRIVATE /utf-8)
+ target_link_libraries(mcpc PUBLIC ws2_32)
+else()
+ message(WARNING
+ "Only Windows/MSVC is currently verified. Other toolchains are future work."
+ )
+endif()