Compare commits

...

5 Commits

Author SHA1 Message Date
342a8236a1 simplified libxml library build 2024-07-09 22:34:36 +07:00
b87def5376 Makefile.old was deleted 2024-07-09 22:11:56 +07:00
4c0bbcabdc Libxml was added from CPM 2024-07-09 20:09:27 +07:00
580c9e47dc CPM was added to CMake 2024-07-09 16:00:04 +07:00
c705b07972 .gitignore was added 2024-07-09 15:59:14 +07:00
17 changed files with 62 additions and 73 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
build/

View File

@@ -2,29 +2,41 @@ cmake_minimum_required(VERSION 3.12)
project(cyberiadaml VERSION 1.0) project(cyberiadaml VERSION 1.0)
find_package(LibXml2 REQUIRED) include(cmake/CPM.cmake)
if(!LibXml2_FOUND)
message(FATAL_ERROR "Cannot find libxml2 library")
endif()
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -D__DEBUG__") set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -D__DEBUG__")
add_library(cyberiadaml SHARED cyberiadaml.c utf8enc.c cyb_types.c cyb_string.c geometry.c) CPMAddPackage(
target_include_directories(cyberiadaml PUBLIC NAME LibXml2
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> VERSION 2.13.2
$<INSTALL_INTERFACE:include/cyberiada> GITHUB_REPOSITORY GNOME/libxml2
"${LIBXML2_INCLUDE_DIR}") OPTIONS
target_link_directories(cyberiadaml PUBLIC "${LIBXML2_LIBRARY}") "LIBXML2_WITH_PYTHON OFF"
target_link_libraries(cyberiadaml PUBLIC "LIBXML2_WITH_TESTS OFF"
"${LIBXML2_LIBRARIES}" )
m)
add_executable(cyberiada_test test.c) add_library(
target_include_directories(cyberiada_test PUBLIC cyberiadaml
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> SHARED
$<INSTALL_INTERFACE:include/cyberiada>) src/cyberiadaml.c
target_link_directories(cyberiada_test PUBLIC "${PROJECT_BINARY_DIR}") src/utf8enc.c
target_link_libraries(cyberiada_test PUBLIC cyberiadaml) src/cyb_types.c
src/cyb_string.c
src/geometry.c
)
target_include_directories(cyberiadaml PRIVATE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:include/cyberiada>)
target_link_libraries(cyberiadaml PRIVATE LibXml2::LibXml2)
add_executable(cyberiada_test src/test.c)
target_include_directories(cyberiada_test PRIVATE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:include/cyberiada>)
target_link_directories(cyberiada_test PRIVATE "${PROJECT_BINARY_DIR}")
target_link_libraries(cyberiada_test PRIVATE cyberiadaml)
install(TARGETS cyberiadaml DESTINATION lib EXPORT cyberiadaml) install(TARGETS cyberiadaml DESTINATION lib EXPORT cyberiadaml)
install(FILES cyberiadaml.h ${CMAKE_CURRENT_SOURCE_DIR}/cyberiadaml.h install(FILES cyberiadaml.h ${CMAKE_CURRENT_SOURCE_DIR}/cyberiadaml.h
@@ -33,7 +45,10 @@ install(EXPORT cyberiadaml DESTINATION lib/cmake)
configure_file( configure_file(
${PROJECT_SOURCE_DIR}/cyberiadaml-config.cmake.in ${PROJECT_SOURCE_DIR}/cyberiadaml-config.cmake.in
${PROJECT_BINARY_DIR}/cyberiadaml-config.cmake @ONLY) ${PROJECT_BINARY_DIR}/cyberiadaml-config.cmake @ONLY
)
install(FILES ${PROJECT_BINARY_DIR}/cyberiadaml-config.cmake install(
DESTINATION lib/cmake) FILES ${PROJECT_BINARY_DIR}/cyberiadaml-config.cmake
DESTINATION lib/cmake
)

View File

@@ -1,51 +0,0 @@
LIB_TARGET_STATIC := libcyberiadaml.a
LIB_TARGET_DYNAMIC := libcyberiadaml.so
ifeq ($(DYNAMIC), 1)
LIB_TARGET := $(LIB_TARGET_DYNAMIC)
else
LIB_TARGET := $(LIB_TARGET_STATIC)
endif
TEST_TARGET := cyberiada_test
LIB_SOURCES := cyberiadaml.c utf8enc.c cyb_types.c cyb_string.c
TEST_SOURCES := test.c
LIB_OBJECTS := $(patsubst %.c, %.o, $(LIB_SOURCES))
TEST_OBJECTS := $(patsubst %.c, %.o, $(TEST_SOURCES))
ifeq ($(DEBUG), yes)
CFLAGS := -Werror -Wall -Wstrict-prototypes -Wmissing-prototypes -Wshadow -Wconversion -fPIC -g3 -D__DEBUG__
LFLAGS :=
else ifeq ($(DEBUG), asan)
CFLAGS := -Wall -Wstrict-prototypes -Wmissing-prototypes -Wshadow -Wconversion -fsanitize=address -fPIC -g3 -D__DEBUG__
LFLAGS := -fsanitize=address -static-libasan
else
CFLAGS := -fPIC
LFLAGS :=
endif
INCLUDE := -I. -I/usr/include/libxml2
LIBS := -L/usr/lib -lxml2 -lm
TEST_LIBS := -L. -lcyberiadaml
$(LIB_TARGET): $(LIB_OBJECTS)
ifeq ($(DYNAMIC), yes)
gcc -shared $(LIBS) $(LIB_OBJECTS) -o $@
else
ar rcs $@ $(LIB_OBJECTS)
endif
$(TEST_TARGET): $(TEST_OBJECTS) $(LIB_TARGET) $(LIB_ORJECTS)
gcc $(TEST_OBJECTS) $(LFLAGS) -Wl,--no-as-needed $(LIBS) $(TEST_LIBS) -o $@
%.o: %.c
gcc -c $< $(CFLAGS) $(INCLUDE) -o $@
clean:
rm -f *~ *.o $(TARGET) $(TEST_TARGET) $(LIB_TARGET_STATIC) $(LIB_TARGET_DYNAMIC)
test: $(TEST_TARGET)
all: $(LIB_TARGET) $(TEST_TARGET)
.PHONY: all clean test

24
cmake/CPM.cmake Normal file
View File

@@ -0,0 +1,24 @@
# SPDX-License-Identifier: MIT
#
# SPDX-FileCopyrightText: Copyright (c) 2019-2023 Lars Melchior and contributors
set(CPM_DOWNLOAD_VERSION 0.40.0)
set(CPM_HASH_SUM "7b354f3a5976c4626c876850c93944e52c83ec59a159ae5de5be7983f0e17a2a")
if(CPM_SOURCE_CACHE)
set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
elseif(DEFINED ENV{CPM_SOURCE_CACHE})
set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
else()
set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
endif()
# Expand relative path. This is important if the provided path contains a tilde (~)
get_filename_component(CPM_DOWNLOAD_LOCATION ${CPM_DOWNLOAD_LOCATION} ABSOLUTE)
file(DOWNLOAD
https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake
${CPM_DOWNLOAD_LOCATION} EXPECTED_HASH SHA256=${CPM_HASH_SUM}
)
include(${CPM_DOWNLOAD_LOCATION})

View File