diff --git a/.gitignore b/.gitignore
index b3cff7e..71fe5ae 100644
--- a/.gitignore
+++ b/.gitignore
@@ -24,3 +24,6 @@
/vcnet/packages
/xcode/mxml.xcodeproj/project.xcworkspace
/xcode/mxml.xcodeproj/xcuserdata
+
+# CMake
+build/
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..7f5dd4b
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,88 @@
+cmake_minimum_required(VERSION 3.19) # First to support Apple Silicon.
+project(mxml C)
+enable_testing()
+
+# Don't allow source tree pollution.
+if(" ${CMAKE_SOURCE_DIR}" STREQUAL " ${CMAKE_BINARY_DIR}")
+ message(FATAL_ERROR "
+FATAL: In-source builds are not allowed.
+ You should create a separate directory for build files.
+")
+endif()
+
+if(WIN32)
+ # set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) # C++
+
+ add_compile_definitions(
+ _WIN32_WINNT=0x0601
+ )
+endif(WIN32)
+
+set(MXML_PRIVATE
+ mxml-attr.c
+ mxml-file.c
+ mxml-get.c
+ mxml-index.c
+ mxml-node.c
+ mxml-options.c
+ mxml-private.c
+ mxml-search.c
+ mxml-set.c
+)
+
+set(MXML_PUBLIC
+ mxml.h
+
+ config.h # TODO: Cmake configure.
+)
+
+set(MXML_COLLECTIVE
+ ${MXML_PRIVATE}
+ ${MXML_PUBLIC}
+)
+
+add_library(${PROJECT_NAME}
+ ${MXML_COLLECTIVE}
+)
+
+# Dfine the header(s) for this library and add to build path.
+target_include_directories(${PROJECT_NAME} PUBLIC
+ $
+)
+
+install(TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME}LibraryConfig
+ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} # For Windows
+)
+
+# Importable from the install directory.
+# Config file per-project dir or into "cmake".
+install(EXPORT ${PROJECT_NAME}LibraryConfig DESTINATION share/${PROJECT_NAME}Library/cmake)
+
+# Importable from the build directory.
+export(TARGETS ${PROJECT_NAME} FILE ${PROJECT_NAME}/LibraryConfig.cmake)
+
+# ==================== TESTS ====================
+add_executable(${PROJECT_NAME}-test
+ testmxml.c
+)
+
+add_custom_command(
+ TARGET ${PROJECT_NAME}-test
+ COMMAND ${CMAKE_COMMAND} -E copy
+ ${CMAKE_CURRENT_SOURCE_DIR}/test.xml
+ $
+)
+
+target_link_libraries(${PROJECT_NAME}-test
+ ${PROJECT_NAME}
+)
+
+include(ExternalData)
+ExternalData_Add_Test(
+ NAME test-mxml
+ ${PROJECT_NAME}-test
+ DATA{test.xml}
+)
+
diff --git a/test.xmlfd b/test.xmlfd
new file mode 100644
index 0000000..3f260a7
--- /dev/null
+++ b/test.xmlfd
@@ -0,0 +1,29 @@
+
+
+
+ 123
+ Now is the time for all good men to come to the aid of their
+country.
+
+
+