Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update CMake #13

Merged
merged 5 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 48 additions & 15 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ jobs:
os: ubuntu-latest
- compiler: djgpp-2.0.5-gcc-4.8.5 # To test compatibility for Adplay - DOS
os: ubuntu-latest
- compiler: cmake
os: ubuntu-latest
- compiler: cmake
os: macos-latest
- compiler: cmake
os: windows-latest

fail-fast: false

Expand All @@ -27,8 +33,8 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: Install packages (Linux)
if: ${{ runner.os == 'Linux' }}
- name: Install packages (autotools, Linux)
if: ${{ runner.os == 'Linux' && matrix.compiler != 'cmake'}}
run: |
sudo apt update
sudo apt install -y texlive-latex-base texinfo
Expand Down Expand Up @@ -63,8 +69,8 @@ jobs:
fi
fi

- name: Install packages (macOS)
if: ${{ runner.os == 'macOS' }}
- name: Install packages (autotools, macOS)
if: ${{ runner.os == 'macOS' && matrix.compiler != 'cmake'}}
run: |
# Allow core dumps
sudo sh -c 'touch /cores/test && rm /cores/test && chmod -R 0777 /cores'
Expand All @@ -73,36 +79,39 @@ jobs:
#brew install --cask mactex-no-gui
brew install automake libtool texinfo

- name: Install LLVM and Clang
if: ${{ matrix.compiler == 'clang' && runner.os != 'macOS' }}
- name: Install LLVM and Clang (autotools)
if: ${{ matrix.compiler == 'clang' && runner.os != 'macOS'}}
uses: KyleMayes/install-llvm-action@v1
with:
version: "10.0"

- name: Set GCC-4.8 environment
- name: Set GCC-4.8 environment (autotools)
if: ${{ matrix.compiler == 'gcc-4.8' }}
run: echo 'compile_opts=CC=gcc-4.8 CXX=g++-4.8' >> $GITHUB_ENV

- name: Set GCC environment
- name: Set GCC environment (autotools)
if: ${{ matrix.compiler == 'gcc' && runner.os == 'macOS' }}
run: echo 'compile_opts=CC=gcc CXX=g++' >> $GITHUB_ENV

- name: Set Clang environment
- name: Set Clang environment (autotools)
if: ${{ matrix.compiler == 'clang' }}
run: echo 'compile_opts=CC=clang CXX=clang++' >> $GITHUB_ENV

- name: Set DJGPP environment
- name: Set DJGPP environment (autotools)
if: ${{ startsWith(matrix.compiler, 'djgpp') }}
run: |
echo 'compile_opts=--host=i586-pc-msdosdjgpp --prefix=/usr/local/djgpp CXXFLAGS=-Wno-deprecated CPPFLAGS=-Wno-deprecated PKG_CONFIG_PATH=/usr/local/djgpp/lib/pkgconfig' >> $GITHUB_ENV
echo 'usr/local//djgpp/bin/' >> $GITHUB_PATH

- name: autoreconf
- name: autoreconf (autotools)
if: ${{matrix.compiler != 'cmake'}}
run: autoreconf -i
- name: configure
- name: configure (autotools)
if: ${{matrix.compiler != 'cmake'}}
run: ./configure ${{ env.compile_opts }} || cat config.log

- name: make
- name: make (autotools)
if: ${{matrix.compiler != 'cmake'}}
run: |
ulimit -c unlimited -S
if [[ ${{ runner.os }} == "macOS" ]]; then
Expand All @@ -122,6 +131,30 @@ jobs:
make distcheck ${{ env.compile_opts }}
fi

- name: Prepare test results (Linux)
if: ${{ runner.os == 'Linux' && !startsWith(matrix.compiler, 'djgpp')}}
- name: Prepare test results (autotools, Linux)
if: ${{ runner.os == 'Linux' && !startsWith(matrix.compiler, 'djgpp') && matrix.compiler != 'cmake'}}
run: make check

- name: Get cmake and ninja (cmake)
if: ${{matrix.compiler == 'cmake'}}
uses: lukka/get-cmake@latest

- name: Find MSVC (cmake on Windows)
if: ${{matrix.compiler == 'cmake'}}
uses: ilammy/msvc-dev-cmd@v1

- name: Checkout repository (cmake)
if: ${{matrix.compiler == 'cmake'}}
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Build (cmake)
if: ${{matrix.compiler == 'cmake'}}
uses: lukka/run-cmake@v10
env:
VCPKG_ROOT:
# workaround for https://github.com/lukka/run-cmake/issues/142
with:
configurePreset: shared
buildPreset: shared
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,6 @@ doc/libbinio.cps
doc/libbinio.cp
doc/libbinio.aux
doc/libbinio.tps
CMakeUserPresets.json
/out/
/.vs/
149 changes: 131 additions & 18 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,25 +1,138 @@
cmake_minimum_required(VERSION 3.13)
cmake_minimum_required(VERSION 3.16..3.25)

project(libbinio)
list(PREPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

include(CheckTypeSize)
check_type_size("long long" SIZEOF_LONG_LONG)
if(HAVE_SIZEOF_LONG_LONG)
set(TYPE_INT "long long")
else()
set(TYPE_INT "long")
###
### Project
###

project(libbinio VERSION 1.5)

if(CMAKE_VERSION VERSION_LESS 3.21)
# Set "top level" if the current CMake is too old to do so in project().
string(COMPARE EQUAL "${CMAKE_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}" libbinio_IS_TOP_LEVEL)
endif()

###
### C++ Language
###

if(NOT DEFINED CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 17)
endif()
if(NOT DEFINED CMAKE_CXX_STANDARD_REQUIRED)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
endif()
if(NOT DEFINED CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD OFF)
endif()
check_type_size("long double" SIZEOF_LONG_DOUBLE)
if(HAVE_SIZEOF_LONG_DOUBLE)
set(TYPE_FLOAT "long double")
else()
set(TYPE_FLOAT "double")

add_compile_definitions($<$<CONFIG:Debug>:DEBUG>)

if(MSVC)
# Tell MSVC to use UTF-8 when reading the source code and when generating the
# object file. Otherwise, both the compiler's input and output can vary
# depending on the current user code page. (MSVC always uses UTF-8
# internally.)
# https://learn.microsoft.com/en-us/cpp/build/reference/utf-8-set-source-and-executable-character-sets-to-utf-8
add_compile_options("/utf-8")
endif()

###
### Library type
###

if(DEFINED libbinio_BUILD_SHARED_LIBS)
set(BUILD_SHARED_LIBS "${libbinio_BUILD_SHARED_LIBS}")
endif ()
set(libbinio_BUILD_SHARED_LIBS "${BUILD_SHARED_LIBS}")

if(BUILD_SHARED_LIBS AND NOT DEFINED CMAKE_INTERPROCEDURAL_OPTIMIZATION)
message(STATUS "Enabling interprocedural optimization")
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_DEBUG OFF)
endif()

# TODO: check library exists
set(ENABLE_IOSTREAM 1)
set(ENABLE_STRING 1)
set(ISO_STDLIB 1)
set(WITH_MATH 1)

if(WIN32)
if(BUILD_SHARED_LIBS)
set(CMAKE_DEBUG_POSTFIX "d")
else()
set(CMAKE_RELEASE_POSTFIX "_static")
set(CMAKE_RELWITHDEBINFO_POSTFIX "_static")
set(CMAKE_DEBUG_POSTFIX "_staticd")
endif()
endif()

###
### Configuration checks
###

include(CheckTypeSize)
include(CheckCXXSourceCompiles)
include(CheckLibraryExists)

# Use a function for the configuration to keep the any variables in their own
# local scope (e.g., CMAKE_REQUIRED_LIBRARIES).
function(configure_libbinio)
if(UNIX)
check_library_exists(m sin "" HAVE_LIB_M)
if(HAVE_LIB_M)
list(APPEND CMAKE_REQUIRED_LIBRARIES m)
set(HAVE_LIB_M 1 PARENT_SCOPE)
endif()
endif()

check_type_size("long long" SIZEOF_LONG_LONG)
if(HAVE_SIZEOF_LONG_LONG)
set(TYPE_INT "long long" CACHE STRING "Integer type")
else()
set(TYPE_INT "long" CACHE STRING "Integer type")
endif()

check_type_size("long double" SIZEOF_LONG_DOUBLE)
if(HAVE_SIZEOF_LONG_DOUBLE)
set(TYPE_FLOAT "long double" CACHE STRING "Floating point type")
else()
set(TYPE_FLOAT "double" CACHE STRING "Floating point type")
endif()

check_cxx_source_compiles(
"
#include <math.h>
int main(int, char**)
{ (void)ldexp(1.0, 5); }
"
HAVE_LDEXP)
if(NOT HAVE_LDEXP)
set(HAVE_LDEXP 0)
endif()

include(TestForANSIStreamHeaders)

if(${CMAKE_NO_ANSI_STREAM_HEADERS})
set(HAVE_STREAMS 0)
else()
set(HAVE_STREAMS 1)
endif()

set(ENABLE_IOSTREAM ${HAVE_STREAMS} CACHE STRING "Enable IOStream")
set(ENABLE_STRING 1 CACHE STRING "Enable string")
set(ISO_STDLIB ${HAVE_STREAMS} CACHE STRING "Use ISO stdlib")
set(WITH_MATH ${HAVE_LDEXP} CACHE STRING "Use math.h")
endfunction()

configure_libbinio()

###
### Core
###

add_subdirectory(doc)
add_subdirectory(src)

option(libbinio_INCLUDE_PACKAGING "Include packaging rules for libbinio" "${libbinio_IS_TOP_LEVEL}")

if(libbinio_INCLUDE_PACKAGING)
add_subdirectory(packaging)
endif()
Loading
Loading