Skip to content

Commit

Permalink
cmake code cleanup, update instalation procedure, update enum name co…
Browse files Browse the repository at this point in the history
…de (#18)

Co-authored-by: Artur Bać <[email protected]>
  • Loading branch information
arturbac and Artur Bać authored Dec 20, 2024
1 parent 245f7fc commit e29694c
Show file tree
Hide file tree
Showing 11 changed files with 445 additions and 424 deletions.
50 changes: 34 additions & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,17 @@ jobs:
- name: Install dependencies
run: |
sudo apt-get update && sudo apt-get install -y cmake ninja-build gcc-14 g++-14
- name: ci-gcc-glaze4
run: cmake --workflow --preset="ci-gcc-glaze4"
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-14 140
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-14 140
sudo update-alternatives --set gcc /usr/bin/gcc-14
sudo update-alternatives --set g++ /usr/bin/g++-14
g++ --version
- name: ci-gcc
run: cmake --workflow --preset="ci-gcc"

- name: ci-gcc-glaze4-c++26
run: cmake --workflow --preset="ci-gcc-glaze4-c++26"
- name: ci-gcc-c++26
run: cmake --workflow --preset="ci-gcc-c++26"

build-and-test-clang:
runs-on: ubuntu-24.04
Expand All @@ -39,18 +44,31 @@ jobs:
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y cmake g++-14 ninja-build clang-19 libfmt-dev libc++-19-dev libc++abi-19-dev
- name: ci-clang-libstdc++-glaze4
run: cmake --workflow --preset="ci-clang-libstdc++-glaze4"
- name: ci-clang-libc++-glaze4
run: cmake --workflow --preset="ci-clang-libc++-glaze4"
sudo apt-get update
sudo apt-get install -y cmake g++-14 ninja-build clang-19 libfmt-dev libc++-19-dev libc++abi-19-dev
sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-19 190
sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-19 190
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-14 140
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-14 140
sudo update-alternatives --set clang /usr/bin/clang-19
sudo update-alternatives --set clang++ /usr/bin/clang++-19
sudo update-alternatives --set gcc /usr/bin/gcc-14
sudo update-alternatives --set g++ /usr/bin/g++-14
clang++ --version
g++ --version
- name: ci-clang-libstdc++
run: cmake --workflow --preset="ci-clang-libstdc++"
- name: ci-clang-libc++
run: cmake --workflow --preset="ci-clang-libc++"

- name: ci-clang-libstdc++-glaze4-c++26
run: cmake --workflow --preset="ci-clang-libstdc++-glaze4-c++26"
- name: ci-clang-libc++-glaze4-c++26
run: cmake --workflow --preset="ci-clang-libc++-glaze4-c++26"
- name: ci-clang-libstdc++-c++26
run: cmake --workflow --preset="ci-clang-libstdc++-c++26"
- name: ci-clang-libc++-c++26
run: cmake --workflow --preset="ci-clang-libc++-c++26"

build-and-test-msvc:
runs-on: windows-latest
Expand Down
42 changes: 22 additions & 20 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
cmake_minimum_required(VERSION 3.21)
cmake_policy(SET CMP0167 NEW)
cmake_policy(SET CMP0175 NEW)

include(${CMAKE_CURRENT_LIST_DIR}/cmake/extract_version.cmake)
project(simple_enum
Expand All @@ -21,14 +23,14 @@ include(cmake/get_cpm.cmake)
CPMAddPackage("gh:TheLartians/[email protected]")

option(SIMPLE_ENUM_USE_GLAZE_3_1 "Use Glaze version 3.1" OFF)
option(SIMPLE_ENUM_USE_GLAZE_4_0 "Use Glaze version 4.0" ON)
option(SIMPLE_ENUM_USE_GLAZE_4_0 "Use Glaze version 4.2" ON)
option(SIMPLE_ENUM_ENABLE_TESTS "Enable unit tests" ON )
option(SIMPLE_ENUM_EXPORT_CMAKE_TARGETS "Enable cmake targets" ON)

if(SIMPLE_ENUM_USE_GLAZE_3_1)
set(GLAZE_GIT_TAG "v3.4.3")
elseif(SIMPLE_ENUM_USE_GLAZE_4_0)
set(GLAZE_GIT_TAG "v4.0.1")
set(GLAZE_GIT_TAG "v4.2.2")
else()
message(FATAL_ERROR "Please select a Glaze version by setting USE_GLAZE_3_1, or SIMPLE_ENUM_USE_GLAZE_4_0")
endif()
Expand Down Expand Up @@ -80,7 +82,6 @@ endif()



# Header-only library target
add_library(simple_enum INTERFACE)
if(PROJECT_IS_TOP_LEVEL)
add_library(simple_enum::simple_enum ALIAS simple_enum )
Expand All @@ -102,14 +103,16 @@ target_include_directories(simple_enum
INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${INCLUDE_INSTALL_DIR}>
)

include(GNUInstallDirs)
include(CMakePackageConfigHelpers)

install(TARGETS simple_enum
EXPORT simple_enum_targets
INCLUDES DESTINATION include
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)

install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/
DESTINATION include
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)

if(SIMPLE_ENUM_EXPORT_CMAKE_TARGETS)
Expand All @@ -120,20 +123,19 @@ if(SIMPLE_ENUM_EXPORT_CMAKE_TARGETS)
)
endif()

if( NOT MSVC)
packageProject(
NAME simple_enum
VERSION ${SIMPLE_ENUM_VERSION}
NAMESPACE simple_enum
BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}
INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include
INCLUDE_DESTINATION include
VERSION_HEADER "${CMAKE_CURRENT_SOURCE_DIR}/include/simple_enum/core.hpp"
COMPATIBILITY SameMinorVersion
DEPENDENCIES ""
DISABLE_VERSION_SUFFIX YES
)
endif()

configure_package_config_file(
cmake/simple_enumConfig.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/simple_enumConfig.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/simple_enum)

write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/presetsConfigVersion.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion)

install(FILES ${CMAKE_CURRENT_BINARY_DIR}/simple_enumConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/simple_enumConfigVersion.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/simple_enum)

if(PROJECT_IS_TOP_LEVEL AND SIMPLE_ENUM_ENABLE_TESTS)
include(cmake/unit_test_integration.cmake)
Expand Down
Loading

0 comments on commit e29694c

Please sign in to comment.