You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
89 lines
1.9 KiB
89 lines
1.9 KiB
4 months ago
|
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
|
||
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/>
|
||
|
)
|
||
|
|
||
|
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_FILE_DIR:${PROJECT_NAME}-test>
|
||
|
)
|
||
|
|
||
|
target_link_libraries(${PROJECT_NAME}-test
|
||
|
${PROJECT_NAME}
|
||
|
)
|
||
|
|
||
|
include(ExternalData)
|
||
|
ExternalData_Add_Test(
|
||
|
NAME test-mxml
|
||
|
${PROJECT_NAME}-test
|
||
|
DATA{test.xml}
|
||
|
)
|
||
|
|