Skip to content

Commit

Permalink
CMake; Windows fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
TinoDidriksen committed Aug 15, 2024
1 parent a2dbb18 commit c2fd464
Show file tree
Hide file tree
Showing 25 changed files with 402 additions and 3,637 deletions.
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
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 "[email protected]")

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)
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.5 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()
17 changes: 0 additions & 17 deletions Makefile.am

This file was deleted.

35 changes: 0 additions & 35 deletions autogen.sh

This file was deleted.

1 change: 1 addition & 0 deletions autogen.sh
35 changes: 35 additions & 0 deletions cmake.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env bash
set -e
args=()

while [[ $# > 0 ]];
do
case "$1" in
--prefix)
args+=("-DCMAKE_INSTALL_PREFIX=$2")
shift 2
;;
--prefix=*)
args+=("-DCMAKE_INSTALL_PREFIX=${1#*=}")
shift
;;
--enable-python-bindings)
args+=("-DENABLE_PYTHON_BINDINGS=ON")
shift
;;
*)
args+=("$1")
shift
;;
esac
done

set -- "${args[@]}"

D=$(dirname "$0")

echo "- rm -rf CMake caches"
rm -rf install_manifest.txt CMakeCache.txt *.cmake CMakeFiles [sp]*/CMakeFiles [sp]*/*.cmake _CPack_Packages Testing
echo "- cmake " "$@" "$D"
cmake "$@" "$D"
echo "- You may now perform: make -j8"
1 change: 1 addition & 0 deletions configure
Loading

0 comments on commit c2fd464

Please sign in to comment.