Skip to content

Commit

Permalink
Add tupl_dev dir and move codegen & tests there
Browse files Browse the repository at this point in the history
Focus on simple usage; provide tupl_impl.hpp so no codegen is needed.

The main directory was cluttered with codegen sources and the builds
eagerly ran codegen preprocessing and all tests, unnecessary for use.

Add a tupl_dev directory and move codegen sources and tests there.
A developer can run codegen there to create a tupl_dev/tupl_impl.hpp
that overrides the main directory file.

Remove the CMake developer preset; it only complicates things.
  • Loading branch information
willwray committed May 3, 2022
1 parent a067348 commit 0c258f2
Show file tree
Hide file tree
Showing 13 changed files with 855 additions and 218 deletions.
119 changes: 43 additions & 76 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
cmake_minimum_required(VERSION 3.15)

# Contents generated by 'cmake-init -h', manually edited to a standalone
# single file, with includes expanded inline

if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
message(
FATAL_ERROR
Expand All @@ -11,28 +14,19 @@ endif()

project(
tupl
VERSION 0.2.0
VERSION 0.3.0
DESCRIPTION "C++20 aggregate tuple"
HOMEPAGE_URL "https://github.com/willwray/tupl"
HOMEPAGE_URL "https://github.com/Lemurian-Labs/tupl"
LANGUAGES CXX
)

# This variable is set by project() in CMake 3.21+
# PROJECT_IS_TOP_LEVEL variable is set by project() in CMake 3.21+
string(
COMPARE EQUAL
"${CMAKE_SOURCE_DIR}" "${PROJECT_SOURCE_DIR}"
PROJECT_IS_TOP_LEVEL
)

# ---- Developer mode ----

# Developer mode enables targets and paths only relevant for developers.
# Targets needed to build the project must be provided unconditionally,
# so consumers can trivially build and package the project
if(PROJECT_IS_TOP_LEVEL)
option(tupl_DEVELOPER_MODE "Enable developer mode" OFF)
endif()

# ---- Warning guard ----

# target_include_directories with SYSTEM modifier requests the compiler
Expand All @@ -52,18 +46,10 @@ if(NOT PROJECT_IS_TOP_LEVEL)
endif()
endif()

# ---- Fetch dependencies; c_array_support & IREPEAT (for codegen) ----
# ---- Fetch dependency; c_array_support (for C array members) ----

include(FetchContent)

FetchContent_Declare(
irepeat
GIT_REPOSITORY https://github.com/willwray/IREPEAT
GIT_TAG v0.3
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
)

FetchContent_Declare(
c_array_support
GIT_REPOSITORY https://github.com/willwray/c_array_support
Expand All @@ -72,13 +58,8 @@ FetchContent_Declare(
BUILD_COMMAND ""
)

FetchContent_MakeAvailable(irepeat)

FetchContent_MakeAvailable(c_array_support)

add_library(irepeat INTERFACE)
target_include_directories(irepeat INTERFACE ${irepeat_SOURCE_DIR}/)

add_library(c_array_support INTERFACE)
target_include_directories(
c_array_support INTERFACE ${c_array_support_SOURCE_DIR}/)
Expand All @@ -88,98 +69,84 @@ target_include_directories(
add_library(tupl_tupl INTERFACE)
add_library(tupl::tupl ALIAS tupl_tupl)

target_link_libraries(tupl_tupl INTERFACE irepeat c_array_support)

set_property(
TARGET tupl_tupl PROPERTY
EXPORT_NAME tupl
)

target_include_directories(
tupl_tupl ${tupl_warning_guard}
tupl_tupl
INTERFACE
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>"
"$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}>"
)

target_compile_features(tupl_tupl INTERFACE cxx_std_20)

# ---- Install rules ----

if(NOT CMAKE_SKIP_INSTALL_RULES)
# include(cmake/install-rules.cmake)
# install-rules.cmake - BEGIN ---------------------
if(PROJECT_IS_TOP_LEVEL)
set(CMAKE_INSTALL_INCLUDEDIR tupl CACHE PATH "")
set(CMAKE_INSTALL_INCLUDEDIR include/tupl CACHE PATH "")
endif()

#include(CMakePackageConfigHelpers)
#include(GNUInstallDirs)

# Project is configured with no languages, so tell GNUInstallDirs the lib dir
set(CMAKE_INSTALL_LIBDIR lib CACHE PATH "")

include(CMakePackageConfigHelpers)
include(GNUInstallDirs)

# find_package(<package>) call for consumers to find this project
set(package tupl)

install(
DIRECTORY .
DIRECTORY include/
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
COMPONENT tupl_Development
)

#install(
# TARGETS tupl_tupl
# EXPORT tuplTargets
# INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
#)
#write_basic_package_version_file(
# "${package}ConfigVersion.cmake"
# COMPATIBILITY SameMajorVersion
# ARCH_INDEPENDENT
#)
# Allow package maintainers to override the path for the configs
install(
TARGETS tupl_tupl
EXPORT tuplTargets
INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
)

write_basic_package_version_file(
"${package}ConfigVersion.cmake"
COMPATIBILITY SameMajorVersion
ARCH_INDEPENDENT
)

# Allow package maintainers to freely override the path for the configs
set(
tupl_INSTALL_CMAKEDIR "${CMAKE_INSTALL_DATADIR}/${package}"
CACHE PATH "CMake package config location relative to the "
"install prefix"
CACHE PATH "CMake package config location relative to the install prefix"
)
mark_as_advanced(tupl_INSTALL_CMAKEDIR)

install(
FILES cmake/install-config.cmake
DESTINATION "${tupl_INSTALL_CMAKEDIR}"
RENAME "${package}Config.cmake"
COMPONENT tupl_Development
)

install(
FILES "${PROJECT_BINARY_DIR}/${package}ConfigVersion.cmake"
DESTINATION "${tupl_INSTALL_CMAKEDIR}"
COMPONENT tupl_Development
)

#install(
# EXPORT tuplTargets
# NAMESPACE tupl::
# DESTINATION "${tupl_INSTALL_CMAKEDIR}"
# COMPONENT tupl_Development
#)

if(PROJECT_IS_TOP_LEVEL)
include(CPack)
endif()
endif()

# ---- Developer mode ----

if(NOT tupl_DEVELOPER_MODE)
return()
elseif(NOT PROJECT_IS_TOP_LEVEL)
message(
AUTHOR_WARNING
"Developer mode is intended for developers of tupl"
install(
EXPORT tuplTargets
NAMESPACE tupl::
DESTINATION "${tupl_INSTALL_CMAKEDIR}"
COMPONENT tupl_Development
)
endif()

include(CTest)
if(BUILD_TESTING)
add_subdirectory(tests)
if(PROJECT_IS_TOP_LEVEL)
include(CPack)
endif()
# - install-rules.cmake - BEGIN ---------------------
endif()
35 changes: 0 additions & 35 deletions CMakePresets.json

This file was deleted.

44 changes: 7 additions & 37 deletions meson.build
Original file line number Diff line number Diff line change
@@ -1,45 +1,15 @@
project('tupl', 'cpp',
default_options : ['warning_level=3'],
version : '0.1'
default_options : ['cpp_std=c++20'],
version : '0.3'
)

c_array_support_dep = subproject('c_array_support').get_variable('c_array_support_dep')
IREPEAT_dep = subproject('IREPEAT').get_variable('IREPEAT_dep')

compiler_id = meson.get_compiler('cpp').get_id()

if compiler_id == 'msvc' or compiler_id == 'clang-cl'
extra_args = ['/std:c++latest','/Zc:preprocessor']
prepro_args = ['/std:c++latest','/Zc:preprocessor','/I.','-I..','/I..\subprojects\IREPEAT','/C','/EP','/TP','/P']
output_flag = '/Fi'
elif compiler_id == 'clang'
extra_args = ['-std=c++20']
prepro_args = ['-I.','-I..','-I../subprojects/IREPEAT','-MMD','-nostdinc','-C','-E','-P','-Wno-c++20-compat']
output_flag = '-o'
else
extra_args = ['-std=c++20']
prepro_args = ['-I.','-I..','-I../subprojects/IREPEAT','-MMD','-nostdinc','-C','-E','-P']
output_flag = '-o'
endif

tupl_impl_header = custom_target('tupl_impl.hpp',
input: 'tupl_impl_pre.hpp',
output: 'tupl_impl.hpp',
command: [meson.get_compiler('cpp').cmd_array(), prepro_args, output_flag+'@OUTPUT@', '@INPUT@'],
depfile: 'tupl_impl.d',
install: true,
install_dir: meson.source_root()
)

tupl_dep = declare_dependency(
dependencies: [c_array_support_dep, IREPEAT_dep],
dependencies: [c_array_support_dep],
include_directories : include_directories('.'),
compile_args : extra_args,
sources : [tupl_impl_header]
).partial_dependency(includes: true, compile_args: true, sources: true)

test('test tupl',
executable('test_tupl', 'tests/tupl_test.cpp',
dependencies: [c_array_support_dep, IREPEAT_dep, tupl_dep]
)
)

IREPEAT_dep = subproject('IREPEAT').get_variable('IREPEAT_dep')

subdir('tupl_dev')
61 changes: 24 additions & 37 deletions tupl.hpp
Original file line number Diff line number Diff line change
@@ -1,45 +1,30 @@
// Copyright (c) 2021 Will Wray https://keybase.io/willwray
// Copyright (c) 2022 Lemurian Labs https://lemurianlabs.com/
//
// Distributed under the Boost Software License, Version 1.0.
// http://www.boost.org/LICENSE_1_0.txt
//
// Repo: https://github.com/willwray/tupl
// Repo: https://github.com/Lemurian-Labs/tupl

#ifndef TUPL_HPP
#define TUPL_HPP
#ifndef LML_TUPL_HPP
#define LML_TUPL_HPP
/*
ltl::tupl
-=========-
tupl<T...>
==========
tupl is a C++20 tuple type implemented as struct specializations
for a variadic number of members T... up to 16 as provided.
DO NOT EDIT the file 'tupl_impl.hpp'.
The implementation in tupl_impl.hpp is generated by preprocessing
the file tupl_dev/tupl_impl_pre.hpp; edit this if you need to.
If more members are needed then follow instructions in tupl_dev
to generate a file tupl_dev/tupl_impl.hpp
A C++20 tuple type implemented as aggregate struct specializations.
Configured by default for up to 16 members of any allowed type.
Depends on <concepts> for assignable_from, ranges::swap CPO, etc.
Depends on <compare> for three-way operator <=> comparisons, etc.
Depends on <concepts> for assignable_from, ranges::swap CPO, etc.
Depends on <compare> for three-way operator <=> comparisons, etc.
(MSVC implementation also depends on <cstdint> for uintptr_t.)
The macro implementation in "tupl_impl_pre.hpp" should be preprocessed
on installation to generate "tupl_impl.hpp" header, but not obligatory;
if tupl_impl.hpp header isn't found on the include search paths then
tupl_impl_pre.hpp is used instead (it may give worse error messages).
You can manually preprocess tupl_impl_pre.hpp -> tupl_impl.hpp
with a command line like:
> cc -I./subprojects/IREPEAT -MMD -C -E -P -o tupl_impl.hpp
tupl_impl_pre.hpp
> cl /I:../subprojects/IREPEAT /Zc:preprocessor /C /EP
Requires __VA_OPT__ preprocessor support (MSVC cl /Zc:preprocessor)
lack of __VA_OPT__ is auto-detected via a static_assert error message.
(other useful cpp flags are -nostdinc -Wno-c++20-compat)
Namespace id 'ltl' and class template id 'tupl' are configurable via
NAMESPACE_ID and TUPL_ID defines. The arity is also configurable.
E.g. to generate ns::tuple add -DNAMESPACE_ID=ns -DTUPL_ID=tuple,
or to generate with no namespace -DNAMESPACE_ID=
Depends on lml c_array_support project for generic support of array
member comparison and assignment, alongside other regular types.
*/

#include "array_compare.hpp"
Expand All @@ -59,11 +44,13 @@ concept same_ish = std::same_as<U, std::remove_cvref_t<T>>;
#define UNREACHABLE()
#endif

#if __has_include("tupl_impl.hpp")
#include "tupl_impl.hpp" // Do not edit generated file "tupl_impl.hpp"
// The header "tupl_impl.hpp" as provided is limited to 'arity' 16.
// If tupl_dev/tupl_impl.hpp exists then is included instead.
//
#if __has_include("tupl_dev/tupl_impl.hpp")
#include "tupl_dev/tupl_impl.hpp"
#else
#include "tupl_impl_pre.hpp" // If you edit "tupl_impl_pre.hpp" then
// remember to regenerate "tupl_impl.hpp"
#include "tupl_impl.hpp"
#endif

#undef UNREACHABLE
Expand Down
Loading

0 comments on commit 0c258f2

Please sign in to comment.