Skip to content

Commit

Permalink
✨ Pivot to using ztd.idk and ztd.cmake rather than anything else
Browse files Browse the repository at this point in the history
  • Loading branch information
ThePhD committed Jul 16, 2022
1 parent e0586b6 commit 8cf075f
Show file tree
Hide file tree
Showing 52 changed files with 464 additions and 27,301 deletions.
115 changes: 75 additions & 40 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,63 +11,99 @@
# Primary CMake File

# # Mimum required
cmake_minimum_required(VERSION 3.12.0)
cmake_minimum_required(VERSION 3.20.0)

# # Project kickstart
# Includes a bunch of basic flags and utilities shared across projects
# See more at the github repository link below
include(FetchContent)
FetchContent_Declare(ztd.cmake
GIT_REPOSITORY https://github.com/soasis/cmake
GIT_TAG main)
FetchContent_MakeAvailable(ztd.cmake)
set(CMAKE_PROJECT_INCLUDE ${ZTD_CMAKE_PROJECT_PRELUDE})

# # Project declaration
# informs about the project, gives a description, version and MOST IMPORTANTLY
# the languages the project is going to use. Required.
project(itsy.bitsy VERSION 1.0.0 DESCRIPTION "Standard bit utilities to supplement the C and C++ standard libraries." LANGUAGES C CXX)
project(itsy.bitsy
VERSION 2.0.0
DESCRIPTION "Standard bit utilities to supplement the C and C++ standard libraries."
LANGUAGES C CXX)

# # Pre-dependencies
# this is for all the deps we may or may not need before-hand to make things right
include(CTest)
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)

# # Options
option(ITSY_BITSY_SINGLE "Enable build of tests" ON)
option(ITSY_BITSY_TESTS "Enable build of tests" ${BUILD_TESTING})
option(ITSY_BITSY_BENCHMARKS "Enable build of benchmarks" OFF)
option(ITSY_BITSY_EXAMPLES "Enable build of examples" OFF)
if(ITSY_BITSY_READTHEDOCS)
# ReadTheDocs seems unable to handle the include at the project level: something must be going wrong?
include(CheckCXXCompilerFlag)
include(CheckCCompilerFlag)
include(CheckIPOSupported)
include(CMakePackageConfigHelpers)
include(CMakeDependentOption)
include(CMakePrintHelpers)
include(GNUInstallDirs)
include(FeatureSummary)
include(FetchContent)
include(CTest)
endif()

# # Top Level Directories
# Check if this is the top-level project or not
if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
set(ITSY_BITSY_IS_TOP_LEVEL_PROJECT true)
set(ITSY_BITSY_IS_TOP_LEVEL_PROJECT ON)
else()
set(ITSY_BITSY_IS_TOP_LEVEL_PROJECT false)
set(ITSY_BITSY_IS_TOP_LEVEL_PROJECT OFF)
endif()

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

if (ITSY_BITSY_IS_TOP_LEVEL_PROJECT)
# Sane directories for easy top-level testing
if (CMAKE_SIZEOF_VOID_P EQUAL 4)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/x86/${CFG_INT_DIR}/lib")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/x86/${CFG_INT_DIR}/bin")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/x86/${CFG_INT_DIR}/bin")
# Modify bad flags / change defaults if we are the top level
if(ITSY_BITSY_IS_TOP_LEVEL_PROJECT)
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/x86/${CMAKE_BUILD_TYPE}/lib")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/x86/${CMAKE_BUILD_TYPE}/bin")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/x86/${CMAKE_BUILD_TYPE}/bin")
else()
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/x64/${CFG_INT_DIR}/lib")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/x64/${CFG_INT_DIR}/bin")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/x64/${CFG_INT_DIR}/bin")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/x64/${CMAKE_BUILD_TYPE}/lib")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/x64/${CMAKE_BUILD_TYPE}/bin")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/x64/${CMAKE_BUILD_TYPE}/bin")
endif()
# Sane warning defaults
# done for us in very latest CMake (as of August 16)
# but not before, so.
if (MSVC)
string(REGEX REPLACE "/W[0-4]" "" CMAKE_C_FLAGS ${CMAKE_C_FLAGS})
string(REGEX REPLACE "/W[0-4]" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})

if(NOT DEFINED CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 17)
endif()
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" AND "x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC")
set(ITSY_BITSY_CLANG_CL ON)
else()
set(ITSY_BITSY_CLANG_CL OFF)

if(NOT DEFINED CMAKE_C_STANDARD)
set(CMAKE_C_STANDARD 23)
endif()
if (ITSY_BITSY_TESTS)
enable_testing()

if(ZTD_CUNEICODE_BENCHMARKS OR ZTD_CUNEICODE_EXAMPLES OR ZTD_CUNEICODE_TESTS OR ZTD_CUNEICODE_SCRATCH)
# normal flags
check_compiler_flag(disable-permissive MSVC /permissive- GCC -pedantic)

# Warning flags
check_compiler_flag(warn-pedantic MSVC /permissive- GCC -pedantic)
check_compiler_flag(warn-all MSVC /W4 GCC -Wall)
check_compiler_flag(warn-errors MSVC /WX GCC -Werror)
check_compiler_flag(warn-extra GCC -Wextra Clang -Wextra)
check_compiler_flag(utf8-literal-encoding MSVC /execution-charset:utf-8 GCC -fexec-charset=utf-8)
check_compiler_flag(utf8-source-encoding MSVC /source-charset:utf-8 GCC -finput-charset=utf-8)
check_compiler_flag(extra-constexpr-depth MSVC /constexpr:depth2147483647 GCC -fconstexpr-depth=2147483647 Clang -fconstexpr-depth=2147483647)
check_compiler_flag(extra-constexpr-steps MSVC /constexpr:steps2147483647 GCC -fconstexpr-ops-limit=2147483647 Clang -fconstexpr-steps=2147483647)
check_compiler_flag(template-debugging-mode GCC -ftemplate-backtrace-limit=0)
endif()
endif()

# # Options
option(ITSY_BITSY_SINGLE "Enable build of tests" ON)
option(ITSY_BITSY_TESTS "Enable build of tests" ${BUILD_TESTING})
option(ITSY_BITSY_BENCHMARKS "Enable build of benchmarks" OFF)
option(ITSY_BITSY_EXAMPLES "Enable build of examples" OFF)

# # Dependencies
# ztd.idk
FetchContent_Declare(ztd.idk
GIT_REPOSITORY https://github.com/soasis/idk.git
GIT_TAG main)
FetchContent_MakeAvailable(ztd.idk)

# # itsy.bitsy Target
# Build Target
Expand All @@ -77,6 +113,9 @@ file(GLOB_RECURSE itsy-bitsy-sources

add_library(itsy.bitsy INTERFACE)
add_library(itsy::bitsy ALIAS itsy.bitsy)
target_link_libraries(itsy.bitsy
INTERFACE
ztd::idk)
target_include_directories(itsy.bitsy INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
Expand All @@ -98,10 +137,6 @@ export(TARGETS itsy.bitsy FILE "${CMAKE_CURRENT_BINARY_DIR}/cmake/itsy.bitsy-tar
install(TARGETS itsy.bitsy
EXPORT itsy.bitsy)

install(EXPORT itsy.bitsy
FILE itsy.bitsy-targets.cmake
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/itsy.bitsy")

install(DIRECTORY include/itsy
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")

Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ For `bit_view`, the optional second `Bounds` template parameter can be used to s
int main () {
std::array<std::uint32_t, 2> storage{
// 0xFBFF;
// (MSB) 0b‭1111101111111111‬ (LSB)
// (MSB) 0b1111101111111111 (LSB)
0x0000FBFF,
0xFFFFFFFF
};
Expand All @@ -213,7 +213,7 @@ int main () {
);

assert(view_specific_bits.size() == 12);
// 0th bit of biew is 10th bit,
// 0th bit of view is 10th bit,
// 10th bit of 0xFBFF is false
assert(view_specific_bits[0] == bitsy::bit0);

Expand Down Expand Up @@ -444,7 +444,7 @@ noop 0.325 ns 0.328 ns 1000000000
There are quite a lot of optimizations, additional underlying data structures, general improvements, and other things to do here.


## Better non-constexpr bit intrinsic calculations
## Better non-`constexpr` bit intrinsic calculations

MSVC has issues with `constexpr` and their intrinsics, and they do not yet have `std::is_constant_evaluated`. As such, the `bitsy::first(l/r)_(zero/one)`, `bitsy::count(l/r)_(zero/one)` and `bitsy::popcount` intrinsic functions -- while `constexpr` -- are also implemented in some of the most braindead and plain manners possible. It would be nice to add `if constexpr()` blocks for implementations in the `__basic_X` version of these functions that use smarter bit twiddling tricks. This is done for one of the intrinsics, but should be extended to the others.

Expand Down
58 changes: 27 additions & 31 deletions benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,23 @@ cmake_minimum_required(VERSION 3.11)
# # project declaration
project(itsy.bitsy.benchmarks VERSION 1.0.0 LANGUAGES C CXX DESCRIPTION "A project to benchmark typical operations on dynamic bitsets in the standard library.")

# # Dependencies
# Vendor Dependencies
# Benchmark variables, internal setup
set(BENCHMARK_ENABLE_EXCEPTIONS ON CACHE INTERNAL "Enable the use of exceptions in the benchmark library." FORCE)
set(BENCHMARK_ENABLE_TESTING OFF CACHE INTERNAL "Enable testing of the benchmark library." FORCE)
set(BENCHMARK_ENABLE_LTO OFF CACHE INTERNAL "Enable link time optimisation of the benchmark library." FORCE)
set(BENCHMARK_USE_LIBCXX OFF CACHE INTERNAL "Build and test using libc++ as the standard library." FORCE)
set(BENCHMARK_BUILD_32_BITS OFF CACHE INTERNAL "Build a 32 bit version of the library." FORCE)
set(BENCHMARK_ENABLE_INSTALL OFF CACHE INTERNAL "Enable installation of benchmark. (Projects embedding benchmark may want to turn this OFF.)" FORCE)
set(BENCHMARK_DOWNLOAD_DEPENDENCIES OFF CACHE INTERNAL "Allow the downloading and in-tree building of unmet dependencies" FORCE)
set(BENCHMARK_ENABLE_GTEST_TESTS OFF CACHE INTERNAL "Enable building the unit tests which depend on gtest" FORCE)
add_subdirectory(../vendor/benchmark "benchmark")
# # Fetch dependencies
# Google Benchmark
FetchContent_Declare(
googlebenchmark
GIT_REPOSITORY https://github.com/google/benchmark.git
)
FetchContent_GetProperties(googlebenchmark)

if(NOT googlebenchmark_POPULATED)
FetchContent_Populate(googlebenchmark)
set(BENCHMARK_ENABLE_INSTALL OFF CACHE INTERNAL "")
set(BENCHMARK_ENABLE_TESTING OFF CACHE INTERNAL "")
set(BENCHMARK_ENABLE_GTEST_TESTS OFF CACHE INTERNAL "")
set(BENCHMARK_ENABLE_WERROR OFF CACHE INTERNAL "")
set(BENCHMARK_FORCE_WERROR OFF CACHE INTERNAL "")
add_subdirectory(${googlebenchmark_SOURCE_DIR} ${googlebenchmark_BINARY_DIR})
endif()

# # Benchmark Executable
file(GLOB_RECURSE itsy.bitsy.benchmarks.sources CONFIGURE_DEPENDS source/**)
Expand All @@ -24,29 +29,20 @@ add_executable(itsy.bitsy.benchmarks ${itsy.bitsy.benchmarks.sources})
target_include_directories(itsy.bitsy.benchmarks PRIVATE
include
)
target_include_directories(itsy.bitsy.benchmarks SYSTEM PRIVATE
../vendor/span-lite/include
)
target_link_libraries(itsy.bitsy.benchmarks PRIVATE
itsy::bitsy
benchmark
${CMAKE_DL_LIBS}
)
if (MSVC)
target_compile_options(itsy.bitsy.benchmarks PRIVATE
/std:c++17
/EHsc
/utf-8
/permissive-
/W4
)
else()
target_compile_options(itsy.bitsy.benchmarks PRIVATE
-std=c++17
-Wno-unknown-warning -Wno-unknown-warning-option
-Wall -Werror -Wextra -Wpedantic -pedantic -pedantic-errors
)
endif()
target_compile_options(itsy.bitsy.benchmarks PRIVATE
${--utf8-literal-encoding}
${--utf8-source-encoding}
${--disable-permissive}
${--warn-pedantic}
${--warn-all}
${--warn-extra}
${--warn-errors}
)

# # Benchmark Tools
add_subdirectory(tools)
# add_subdirectory(tools)
3 changes: 1 addition & 2 deletions benchmarks/tools/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# # itsy_bitsy benchmarking tools

# minimum required version information
cmake_minimum_required(VERSION 3.12.0)
cmake_minimum_required(VERSION 3.20.0)


# project declaration
Expand Down Expand Up @@ -51,4 +51,3 @@ if (Python3_Interpreter_FOUND)
COMMENT "Graphing '${ITSY_BITSY_BENCHMARKS_RESULTS_OUTFILE}' data to '${ITSY_BITSY_BENCHMARKS_RESULTS_OUTDIR}'"
)
endif()

50 changes: 2 additions & 48 deletions docs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,51 +1,5 @@
# itsy.bitsy
#
# Copyright ⓒ 2019-present ThePhD.
#
# Distributed under the Boost Software License, Version 1.0. (See
# accompanying file LICENSE or copy at
# http://www.boost.org/LICENSE_1_0.txt)
#
# See https://github.com/ThePhD/itsy_bitsy#using-the-library for documentation.

# # Mimum required
cmake_minimum_required(VERSION 3.12.0)

# # Project declaration
# informs about the project, gives a description, version and MOST IMPORTANTLY
# the languages the project is going to use. Required.
project(itsy.bitsy.docs VERSION 1.0.0 DESCRIPTION "Standard bit utilities to supplement the C and C++ standard libraries.")

# # Summer of Code, with Google Proposals / Writeups
find_program (LATEXMK_EXECUTABLE NAMES latexmk latexmk.exe DOC "pdflatex executable for converting documentation from latex to pdf")

if (ITSY_BITSY_DOCS_GSOC)
set(itsy.bitsy.docs.gsoc.proposal.sources.dir "${CMAKE_CURRENT_SOURCE_DIR}/gsoc/proposal/source")
set(itsy.bitsy.docs.gsoc.proposal.sources
"${itsy.bitsy.docs.gsoc.proposal.sources.dir}/thephd-gsoc-2019.tex"
"${itsy.bitsy.docs.gsoc.proposal.sources.dir}/thephd-gsoc-2019.bib"
"${itsy.bitsy.docs.gsoc.proposal.sources.dir}/wg21.cls"
)

set(itsy.bitsy.docs.gsoc.proposal.input "${CMAKE_CURRENT_SOURCE_DIR}/gsoc/proposal/source/thephd-gsoc-2019.tex")
set(itsy.bitsy.docs.gsoc.proposal.intermediate.dir "${CMAKE_CURRENT_BINARY_DIR}/gsoc/proposal")
set(itsy.bitsy.docs.gsoc.proposal.intermediate "${itsy.bitsy.docs.gsoc.proposal.intermediate.dir}/thephd-gsoc-2019.pdf")
set(itsy.bitsy.docs.gsoc.proposal.output.dir "${CMAKE_CURRENT_SOURCE_DIR}/gsoc/proposal")
set(itsy.bitsy.docs.gsoc.proposal.output "${itsy.bitsy.docs.gsoc.proposal.output.dir}/2019.08.17 - ThePhD - Summer of Code Proposal - bit.pdf")
set(itsy.bitsy.docs.gsoc.proposal.latex_command COMMAND ${LATEXMK_EXECUTABLE} -aux-directory=${itsy.bitsy.docs.gsoc.proposal.intermediate.dir} -output-directory=${itsy.bitsy.docs.gsoc.proposal.intermediate.dir} -bibtex -pdf -latexoption="-interaction=nonstopmode" -latexoption="-shell-escape" ${itsy.bitsy.docs.gsoc.proposal.input})
add_custom_command(OUTPUT ${itsy.bitsy.docs.gsoc.proposal.output}
COMMAND echo %PATH%
COMMAND ${itsy.bitsy.docs.gsoc.proposal.latex_command}
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${itsy.bitsy.docs.gsoc.proposal.intermediate} ${itsy.bitsy.docs.gsoc.proposal.output}
MAIN_DEPENDENCY ${itsy.bitsy.sources.main_dependency}
DEPENDS ${itsy.bitsy.docs.gsoc.proposal.sources}
WORKING_DIRECTORY ${itsy.bitsy.docs.gsoc.proposal.sources.dir}
USES_TERMINAL VERBATIM
)
add_custom_target(itsy.bitsy.docs.gsoc.proposal
DEPENDS ${itsy.bitsy.docs.gsoc.proposal.output}
SOURCES ${itsy.bitsy.docs.gsoc.proposal.sources}
)
if (ITSY_BITSY_GSOC_2019)
add_subdirectory(gsoc-2019)
endif()


49 changes: 49 additions & 0 deletions docs/gsoc-2019/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# itsy.bitsy
#
# Copyright ⓒ 2019-present ThePhD.
#
# Distributed under the Boost Software License, Version 1.0. (See
# accompanying file LICENSE or copy at
# http://www.boost.org/LICENSE_1_0.txt)
#
# See https://github.com/ThePhD/itsy_bitsy#using-the-library for documentation.

# # Mimum required
cmake_minimum_required(VERSION 3.20.0)

# # Project declaration
# informs about the project, gives a description, version and MOST IMPORTANTLY
# the languages the project is going to use. Required.
project(itsy.bitsy.docs.gsoc-2019 VERSION 1.0.0 DESCRIPTION "Standard bit utilities to supplement the C and C++ standard libraries.")

# # Summer of Code, with Google Proposals / Writeups
find_program (LATEXMK_EXECUTABLE NAMES latexmk latexmk.exe DOC "pdflatex executable for converting documentation from latex to pdf")

if (ITSY_BITSY_DOCS_GSOC)
set(itsy.bitsy.docs.gsoc.proposal.sources.dir "${CMAKE_CURRENT_SOURCE_DIR}/gsoc/proposal/source")
set(itsy.bitsy.docs.gsoc.proposal.sources
"${itsy.bitsy.docs.gsoc.proposal.sources.dir}/thephd-gsoc-2019.tex"
"${itsy.bitsy.docs.gsoc.proposal.sources.dir}/thephd-gsoc-2019.bib"
"${itsy.bitsy.docs.gsoc.proposal.sources.dir}/wg21.cls"
)

set(itsy.bitsy.docs.gsoc.proposal.input "${CMAKE_CURRENT_SOURCE_DIR}/gsoc/proposal/source/thephd-gsoc-2019.tex")
set(itsy.bitsy.docs.gsoc.proposal.intermediate.dir "${CMAKE_CURRENT_BINARY_DIR}/gsoc/proposal")
set(itsy.bitsy.docs.gsoc.proposal.intermediate "${itsy.bitsy.docs.gsoc.proposal.intermediate.dir}/thephd-gsoc-2019.pdf")
set(itsy.bitsy.docs.gsoc.proposal.output.dir "${CMAKE_CURRENT_SOURCE_DIR}/gsoc/proposal")
set(itsy.bitsy.docs.gsoc.proposal.output "${itsy.bitsy.docs.gsoc.proposal.output.dir}/2019.08.17 - ThePhD - Summer of Code Proposal - bit.pdf")
set(itsy.bitsy.docs.gsoc.proposal.latex_command COMMAND ${LATEXMK_EXECUTABLE} -aux-directory=${itsy.bitsy.docs.gsoc.proposal.intermediate.dir} -output-directory=${itsy.bitsy.docs.gsoc.proposal.intermediate.dir} -bibtex -pdf -latexoption="-interaction=nonstopmode" -latexoption="-shell-escape" ${itsy.bitsy.docs.gsoc.proposal.input})
add_custom_command(OUTPUT ${itsy.bitsy.docs.gsoc.proposal.output}
COMMAND echo %PATH%
COMMAND ${itsy.bitsy.docs.gsoc.proposal.latex_command}
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${itsy.bitsy.docs.gsoc.proposal.intermediate} ${itsy.bitsy.docs.gsoc.proposal.output}
MAIN_DEPENDENCY ${itsy.bitsy.sources.main_dependency}
DEPENDS ${itsy.bitsy.docs.gsoc.proposal.sources}
WORKING_DIRECTORY ${itsy.bitsy.docs.gsoc.proposal.sources.dir}
USES_TERMINAL VERBATIM
)
add_custom_target(itsy.bitsy.docs.gsoc.proposal
DEPENDS ${itsy.bitsy.docs.gsoc.proposal.output}
SOURCES ${itsy.bitsy.docs.gsoc.proposal.sources}
)
endif()
File renamed without changes.
Loading

0 comments on commit 8cf075f

Please sign in to comment.