Skip to content

Commit

Permalink
CMake instead of autotools; Windows fixes; Snip superfluous files, an…
Browse files Browse the repository at this point in the history
…d rename README => .md
  • Loading branch information
TinoDidriksen committed Aug 20, 2024
1 parent a2dbb18 commit 24e6bc9
Show file tree
Hide file tree
Showing 32 changed files with 483 additions and 3,959 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# https://editorconfig.org/
root = yes
root = true

[*]
charset = utf-8
Expand Down
6 changes: 2 additions & 4 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ jobs:
- name: dependencies
run: |
sudo apt-get -qy update
sudo apt-get -qfy install --no-install-recommends build-essential automake autotools-dev pkg-config libutfcpp-dev libxml2-dev libxml2-utils python3-dev python3-setuptools swig
- name: autoreconf
run: autoreconf -fvi
sudo apt-get -qfy install --no-install-recommends build-essential cmake pkg-config libutfcpp-dev libxml2-dev libxml2-utils python3-dev python3-setuptools swig
- name: configure
run: ./configure --disable-static --enable-python-bindings
run: cmake -DENABLE_PYTHON_BINDINGS=ON .
- name: build
run: make -j4 V=1 VERBOSE=1
- name: tests
Expand Down
32 changes: 8 additions & 24 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,30 +1,13 @@
*.pyc
**/*.deps/
/build/
/build*/
/.ccls-cache/
/*.pc
/aclocal.m4
/autom4te.cache
/compile
/config.guess
/config.log
/config.status
/config.sub
/configure
/depcomp
/INSTALL
/install-sh
/libtool
/ltmain.sh
/lttoolbox/.libs
/m4/libtool.m4
/m4/lt~obsolete.m4
/m4/ltoptions.m4
/m4/ltsugar.m4
/m4/ltversion.m4
/Makefile
/Makefile.in
/missing
Makefile
CMakeCache.txt
CMakeFiles
CTestTestfile.cmake
cmake_install.cmake
install_manifest.txt

# Prerequisites
*.d
Expand Down Expand Up @@ -75,6 +58,7 @@
/lttoolbox/lt-expand
/lttoolbox/lt-append
/lttoolbox/lsx-comp
/lttoolbox/lsx-comp.1
/lttoolbox/lt-paradigm
/lttoolbox/lt-invert
/lttoolbox/lt-restrict
Expand Down
30 changes: 0 additions & 30 deletions .travis.yml

This file was deleted.

159 changes: 159 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
cmake_minimum_required(VERSION 3.12 FATAL_ERROR)
cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
project(lttoolbox
VERSION 3.7.11
LANGUAGES CXX C
)
set(VERSION ${PROJECT_VERSION})
set(VERSION_ABI 3)
set(PACKAGE_NAME ${PROJECT_NAME})
set(PACKAGE_BUGREPORT "apertium-stuff@lists.sourceforge.net")

add_definitions("-DPACKAGE_VERSION=\"${PROJECT_VERSION}\"")

set(MASTER_PROJECT OFF)
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
set(MASTER_PROJECT ON)
endif ()

# Release or Debug
if(MASTER_PROJECT AND NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release")
endif()

set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_MACOSX_RPATH ON)

include(GNUInstallDirs)

option(BUILD_SHARED_LIBS "Set to OFF to use static library" ON)
option(BUILD_TESTING "Set to OFF to disable tests" ON)
option(ENABLE_PYTHON_BINDINGS "Set to ON to build the Python wrapper" OFF)

if(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /utf-8 /std:c++latest /Zc:__cplusplus /permissive- /W4 /MP")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /O2")
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /LTCG")
set(CMAKE_C_FLAGS ${CMAKE_CXX_FLAGS})
set(CMAKE_C_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE})
else()
set(_FLAGS_COMMON "-Wall -Wextra -Wno-missing-field-initializers -Wno-deprecated -Wno-unused-parameter -fPIC")

include(CheckCCompilerFlag)
include(CheckCXXCompilerFlag)

foreach(flag "-Wno-unused-result" "-flto")
string(REGEX REPLACE "[^A-Za-z0-9]" "-" _flag ${flag})
CHECK_CXX_COMPILER_FLAG(${flag} COMPILER_SUPPORTS_${_flag})
if(COMPILER_SUPPORTS_${_flag})
set(_FLAGS_COMMON "${_FLAGS_COMMON} ${flag}")
endif()
endforeach()
if(COMPILER_SUPPORTS_flto)
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} -flto")
endif()

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_FLAGS_COMMON} -fvisibility-inlines-hidden")

# Enable latest possible C standard
foreach(flag "-std=c2x" "-std=c11" "-std=c1x" "-std=c99")
string(REGEX REPLACE "[^a-z0-9]" "-" _flag ${flag})
CHECK_C_COMPILER_FLAG(${flag} COMPILER_SUPPORTS_${_flag})
if(COMPILER_SUPPORTS_${_flag})
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${flag}")
break()
endif()
endforeach()

# Require latest possible C++ standard
foreach(flag "-std=c++23" "-std=c++2b" "-std=c++20" "-std=c++2a" "-std=c++17")
string(REGEX REPLACE "[^a-z0-9]" "-" _flag ${flag})
CHECK_CXX_COMPILER_FLAG(${flag} COMPILER_SUPPORTS_${_flag})
if(COMPILER_SUPPORTS_${_flag})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}")
set(_ENABLED_CXX ${flag})
break()
endif()
endforeach()
if(NOT _ENABLED_CXX)
message(FATAL_ERROR "Could not enable at least C++17 - upgrade your compiler")
endif()

# Generate pkg-config file
set(prefix ${CMAKE_INSTALL_PREFIX})
set(exec_prefix "\${prefix}")
set(libdir "\${exec_prefix}/${CMAKE_INSTALL_LIBDIR}")
set(includedir "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}")
configure_file(lttoolbox.pc.in lttoolbox.pc @ONLY)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/lttoolbox.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig/")
endif()

try_compile(SIZET_NOT_CSTDINT ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/lttoolbox/check-cstdint.cc)
if(SIZET_NOT_CSTDINT)
add_definitions(-DSIZET_NOT_CSTDINT)
endif()

find_package(LibXml2 REQUIRED)
include_directories(${LIBXML2_INCLUDE_DIR})

if(WIN32)
add_definitions(-D_SECURE_SCL=0 -D_ITERATOR_DEBUG_LEVEL=0 -D_CRT_SECURE_NO_DEPRECATE -DWIN32_LEAN_AND_MEAN -DVC_EXTRALEAN -DNOMINMAX)
add_definitions(-DSTDC_HEADERS -DREGEX_MALLOC)
include_directories("lttoolbox/win32")
else()
add_definitions(-D_POSIX_C_SOURCE=200112 -D_GNU_SOURCE)
endif()

if(NOT APPLE)
find_package(Threads REQUIRED)
endif()

# Unlocked I/O functions
include(CheckSymbolExists)
set(CMAKE_REQUIRED_DEFINITIONS -D_POSIX_C_SOURCE=200112 -D_GNU_SOURCE)
foreach(func fread_unlocked fwrite_unlocked fgetc_unlocked fputc_unlocked fputs_unlocked fmemopen)
string(TOUPPER ${func} _uc)
CHECK_SYMBOL_EXISTS(${func} "stdio.h" HAVE_DECL_${_uc})
if(HAVE_DECL_${_uc})
add_definitions(-DHAVE_DECL_${_uc})
endif()
endforeach()
unset(CMAKE_REQUIRED_DEFINITIONS)

# getopt
find_path(GETOPT_INCLUDE getopt.h)
include_directories(${GETOPT_INCLUDE})
if(VCPKG_TOOLCHAIN)
find_library(GETOPT_LIB NAMES getopt REQUIRED)
add_definitions(-DHAVE_GETOPT_LONG)
else()
set(GETOPT_LIB)
CHECK_SYMBOL_EXISTS(getopt_long "getopt.h" HAVE_DECL_GETOPT_LONG)
if(HAVE_DECL_GETOPT_LONG)
add_definitions(-DHAVE_GETOPT_LONG)
endif()
endif()

# ICU
find_package(ICU COMPONENTS i18n io uc REQUIRED)

# utf8cpp / utfcpp
find_path(UTFCPP_INCLUDE_DIRS utf8.h PATH_SUFFIXES utf8cpp utfcpp utf8 REQUIRED)
include_directories(${UTFCPP_INCLUDE_DIRS})

include_directories(${CMAKE_CURRENT_SOURCE_DIR})

if(BUILD_TESTING)
enable_testing()
find_package(Python 3.8 REQUIRED)
set(PYTHON_EXECUTABLE ${Python_EXECUTABLE})
set(ENV{CTEST_OUTPUT_ON_FAILURE} 1)
set(CMAKE_CTEST_ARGUMENTS "-VV")
endif()

add_subdirectory(lttoolbox)

if(ENABLE_PYTHON_BINDINGS)
add_subdirectory(python)
endif()
Loading

0 comments on commit 24e6bc9

Please sign in to comment.