Streamline config.h between cmake and autotools
* Add a config.h for cmake which defines XML and ICU
* Use config.h from cmake instead of setting compile definitions
* Autotools: don't put config.h directly in src tree
* Autotools/cmake: install config.h
* Remove lcf_options.h and include lcf/config.h directly, and do it
first
Fix:
MODIFY
CMakeLists.txt
CMakeLists.txt
@@ -138,7 +138,6 @@ set(PUBLIC_HEADERS
src/lcf/flag_set.h
src/lcf/ini.h
src/lcf/inireader.h
- src/lcf/lcf_options.h
src/lcf/lcf_saveopt.h
src/lcf/ldb_reader.h
src/lcf/lmt_reader.h
@@ -222,6 +221,7 @@ set(PUBLIC_HEADERS
src/generated/lcf/rpg_variable.h
)
list(TRANSFORM PUBLIC_HEADERS PREPEND ${CMAKE_CURRENT_SOURCE_DIR}/)
+list(APPEND PUBLIC_HEADERS ${CMAKE_CURRENT_BINARY_DIR}/src/lcf/config.h)
target_sources(lcf PUBLIC ${PUBLIC_HEADERS})
@@ -237,6 +237,7 @@ endforeach()
# includes
target_include_directories(
lcf PUBLIC
+ ${CMAKE_CURRENT_BINARY_DIR}/src
${CMAKE_CURRENT_SOURCE_DIR}/src
${CMAKE_CURRENT_SOURCE_DIR}/src/generated
)
@@ -268,16 +269,16 @@ if(DISABLE_ICU)
else()
find_package(ICU COMPONENTS i18n uc data REQUIRED)
target_link_libraries(lcf ICU::i18n ICU::uc ICU::data)
- target_compile_definitions(lcf PRIVATE LCF_SUPPORT_ICU=1)
list(APPEND LIBLCF_DEPS "icu-i18n")
+ set(LCF_SUPPORT_ICU "1")
endif()
# expat
if(NOT DISABLE_XML)
find_package(EXPAT)
target_link_libraries(lcf EXPAT::EXPAT)
- target_compile_definitions(lcf PRIVATE LCF_SUPPORT_XML=1)
list(APPEND LIBLCF_DEPS "expat")
+ set(LCF_SUPPORT_XML "1")
endif()
# mime types
@@ -285,6 +286,8 @@ if(NOT DISABLE_UPDATE_MIMEDB AND NOT CMAKE_CROSSCOMPILING)
find_program(UPDATE_MIME_DATABASE update-mime-database)
endif()
+configure_file("${CMAKE_CURRENT_SOURCE_DIR}/builds/cmake.config.h.in" "src/lcf/config.h" @ONLY)
+
# .so version
set_property(TARGET lcf PROPERTY SOVERSION 0)

MODIFY
Makefile.am
Makefile.am
@@ -20,6 +20,7 @@ lcfincludedir = $(includedir)/lcf
lib_LTLIBRARIES = liblcf.la
liblcf_la_CPPFLAGS = \
$(AM_CPPFLAGS) \
+ -I$(srcdir)/autogen \
-I$(srcdir)/src \
-I$(srcdir)/src/generated
liblcf_la_CXXFLAGS = \
@@ -130,15 +131,14 @@ liblcf_la_SOURCES = \
src/generated/rpg_state.cpp \
src/generated/rpg_system.cpp
lcfinclude_HEADERS = \
+ autogen/lcf/config.h \
src/lcf/command_codes.h \
- src/lcf/config.h \
src/lcf/data.h \
src/lcf/encoder.h \
src/lcf/enum_tags.h \
src/lcf/flag_set.h \
src/lcf/ini.h \
src/lcf/inireader.h \
- src/lcf/lcf_options.h \
src/lcf/lcf_saveopt.h \
src/lcf/ldb_reader.h \
src/lcf/lmt_reader.h \

ADD
builds/autoconf.config.h.in
+
+/* Enable encoding detection (ICU) */
+#undef LCF_SUPPORT_ICU
+
+/* Enable XML reading support (expat) */
+#undef LCF_SUPPORT_XML

ADD
builds/cmake.config.h.in
+/* Generated by cmake */
+
+/* Enable encoding detection (ICU) */
+#cmakedefine LCF_SUPPORT_ICU @LCF_SUPPORT_ICU@
+
+/* Enable XML reading support (expat) */
+#cmakedefine LCF_SUPPORT_XML @LCF_SUPPORT_XML@
+

MODIFY
builds/liblcf-config.cmake.in
builds/liblcf-config.cmake.in
@@ -32,7 +32,7 @@ pkg_check_modules(PC_LIBLCF QUIET lcf)
# Look for the header file.
find_path(LIBLCF_INCLUDE_DIR
- NAMES "lcf/lcf_options.h"
+ NAMES "lcf/ldb_reader.h"
PATH_SUFFIXES liblcf lcf
HINTS ${PC_LIBLCF_INCLUDE_DIRS})

MODIFY
configure.ac
configure.ac
@@ -11,7 +11,9 @@ AM_SILENT_RULES([yes])
AC_CONFIG_MACRO_DIR([builds/autoconf/m4])
AC_CONFIG_SRCDIR([src/data.cpp])
-AC_CONFIG_HEADERS([src/lcf/config.h])
+# We want our public lcf/config.h to look like the cmake one. This tricks autoheader into generating
+# /config.h (which we don't use) and then configure uses our template for lcf/config.h
+AC_CONFIG_HEADERS([autogen/config.h autogen/lcf/config.h:builds/autoconf.config.h.in])
AC_LANG([C++])
# Checks for programs.

MODIFY
src/encoder.cpp
src/encoder.cpp
* file that was distributed with this source code.
*/
-#include "lcf/lcf_options.h"
+#include "lcf/config.h"
#include "lcf/encoder.h"
#include "lcf/reader_util.h"
#include "lcf/scope_guard.h"

DELETE
src/lcf/lcf_options.h
-/*
- * This file is part of liblcf. Copyright (c) 2020 liblcf authors.
- * https://github.com/EasyRPG/liblcf - https://easyrpg.org
- *
- * liblcf is Free/Libre Open Source Software, released under the MIT License.
- * For the full copyright and license information, please view the COPYING
- * file that was distributed with this source code.
- */
-
-#ifndef LCF_OPTIONS_H
-#define LCF_OPTIONS_H
-
-/*
- * Includes GNU Autotools build configuration parameters.
- * This option may have defined LCF_SUPPORT_XML and others.
- */
-#ifdef HAVE_CONFIG_H
-# include <lcf/config.h>
-#endif
-
-/**
- * Outputs information about read chunks on stdout during parsing
- */
-//#define LCF_DEBUG_TRACE
-
-#endif

MODIFY
src/lcf/reader_lcf.h
src/lcf/reader_lcf.h
#ifndef LCF_READER_LCF_H
#define LCF_READER_LCF_H
+#include "lcf/config.h"
+
#include <string>
#include <vector>
#include <iosfwd>
#include <cstdint>
#include <cinttypes>
#include <memory>
-#include "lcf/lcf_options.h"
#include "lcf/reader_util.h"
#include "lcf/encoder.h"

MODIFY
src/lcf/reader_xml.h
src/lcf/reader_xml.h
#ifndef LCF_READER_XML_H
#define LCF_READER_XML_H
+#include "lcf/config.h"
+
#include <string>
#include <vector>
#include <cstdio>
# include <expat.h>
#endif
#include <stdint.h>
-#include "lcf/lcf_options.h"
#include "lcf/reader_util.h"
namespace lcf {

MODIFY
src/lcf/writer_lcf.h
src/lcf/writer_lcf.h
#ifndef LCF_WRITER_LCF_H
#define LCF_WRITER_LCF_H
+#include "lcf/config.h"
+
#include <string>
#include <vector>
#include <iosfwd>
#include <memory>
#include <cassert>
#include <stdint.h>
-#include "lcf/lcf_options.h"
#include "lcf/reader_util.h"
#include "lcf/encoder.h"

MODIFY
src/reader_util.cpp
src/reader_util.cpp
* file that was distributed with this source code.
*/
-#include "lcf/lcf_options.h"
+#include "lcf/config.h"
#include "lcf/scope_guard.h"
#ifdef LCF_SUPPORT_ICU

MODIFY
src/rpg_fixup.cpp
src/rpg_fixup.cpp
* file that was distributed with this source code.
*/
-#include "lcf/lcf_options.h"
+#include "lcf/config.h"
#include "lcf/rpg_actor.h"
#include "lcf/rpg_mapinfo.h"
#include "lcf/rpg_system.h"

MODIFY
src/rpg_setup.cpp
src/rpg_setup.cpp
* file that was distributed with this source code.
*/
-#include "lcf/lcf_options.h"
+#include "lcf/config.h"
#include "lcf/rpg_actor.h"
#include "lcf/rpg_event.h"
#include "lcf/rpg_map.h"

Streamline config.h between cmake and autotools

* Add a config.h for cmake which defines XML and ICU
* Use config.h from cmake instead of setting compile definitions
* Autotools: don't put config.h directly in src tree
* Autotools/cmake: install config.h
* Remove lcf_options.h and include lcf/config.h directly, and do it
  first

Fix: #362