From 76d2f8610863d4edced62b6340a0850b84feff40 Mon Sep 17 00:00:00 2001 From: Roberto Rossini <71787608+robomics@users.noreply.github.com> Date: Tue, 12 Dec 2023 11:58:27 +0100 Subject: [PATCH 1/6] Initial support for PCH --- CMakeLists.txt | 1 + src/hictk/CMakeLists.txt | 5 +++ .../include/hictk/tools/internal/pch.hpp | 39 +++++++++++++++++ test/CMakeLists.txt | 3 ++ test/units/CMakeLists.txt | 2 + test/units/balancing/CMakeLists.txt | 4 ++ test/units/bin_table/CMakeLists.txt | 18 ++++---- test/units/cooler/CMakeLists.txt | 4 ++ test/units/file/CMakeLists.txt | 4 ++ test/units/hic/CMakeLists.txt | 4 ++ test/units/pch/CMakeLists.txt | 12 ++++++ test/units/pch/lib.cpp | 3 ++ test/units/pch/pch.hpp | 42 +++++++++++++++++++ test/units/pixel/CMakeLists.txt | 4 ++ test/units/reference/CMakeLists.txt | 4 ++ test/units/transformers/CMakeLists.txt | 4 ++ test/units/variant/CMakeLists.txt | 4 ++ 17 files changed, 150 insertions(+), 7 deletions(-) create mode 100644 src/hictk/include/hictk/tools/internal/pch.hpp create mode 100644 test/units/pch/CMakeLists.txt create mode 100644 test/units/pch/lib.cpp create mode 100644 test/units/pch/pch.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index a725f897..f3a9d1d7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -136,6 +136,7 @@ option(HICTK_BUILD_EXAMPLES "Build examples" OFF) option(HICTK_BUILD_BENCHMARKS "Build benchmarks" OFF) option(HICTK_WITH_EIGEN "Build with Eigen3 support" ON) option(HICTK_BUILD_TOOLS "Build cli tools" ON) +option(HICTK_USE_PCH "Build hictk using PCH" OFF) if(HICTK_WITH_EIGEN) target_compile_definitions(hictk_project_options INTERFACE HICTK_WITH_EIGEN) diff --git a/src/hictk/CMakeLists.txt b/src/hictk/CMakeLists.txt index ea4e57f9..650f4d09 100644 --- a/src/hictk/CMakeLists.txt +++ b/src/hictk/CMakeLists.txt @@ -36,6 +36,11 @@ target_sources( ${CMAKE_CURRENT_SOURCE_DIR}/zoomify/zoomify.cpp) target_include_directories(hictk PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/include") + +if(HICTK_USE_PCH) + target_precompile_headers(hictk PRIVATE [["hictk/tools/internal/pch.hpp"]]) +endif() + target_link_libraries(hictk PRIVATE hictk_project_options hictk_project_warnings hictk::libhictk) target_link_system_libraries( diff --git a/src/hictk/include/hictk/tools/internal/pch.hpp b/src/hictk/include/hictk/tools/internal/pch.hpp new file mode 100644 index 00000000..51e22f12 --- /dev/null +++ b/src/hictk/include/hictk/tools/internal/pch.hpp @@ -0,0 +1,39 @@ +// Copyright (C) 2023 Roberto Rossini +// +// SPDX-License-Identifier: MIT + +#pragma once + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "hictk/balancing/methods.hpp" +#include "hictk/bin_table.hpp" +#include "hictk/chromosome.hpp" +#include "hictk/common.hpp" +#include "hictk/cooler/cooler.hpp" +#include "hictk/cooler/dataset.hpp" +#include "hictk/cooler/group.hpp" +#include "hictk/hic/common.hpp" +#include "hictk/pixel.hpp" +#include "hictk/reference.hpp" +#include "hictk/suppress_warnings.hpp" +#include "hictk/type_traits.hpp" diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 61053e1c..54338b35 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -23,3 +23,6 @@ if(HICTK_DOWNLOAD_TEST_DATASET) message(STATUS "Downloading test dataset...") include(${PROJECT_SOURCE_DIR}/cmake/FetchTestDataset.cmake) endif() + +add_executable(test123 units/devel/test.cpp) +target_link_libraries(test123 PUBLIC hictk::libhictk) diff --git a/test/units/CMakeLists.txt b/test/units/CMakeLists.txt index e99d132e..3bac0422 100644 --- a/test/units/CMakeLists.txt +++ b/test/units/CMakeLists.txt @@ -4,6 +4,8 @@ include_directories(include) +add_subdirectory(pch) + add_subdirectory(balancing) add_subdirectory(bin_table) add_subdirectory(chromosome) diff --git a/test/units/balancing/CMakeLists.txt b/test/units/balancing/CMakeLists.txt index 4d9f96c7..375da6f1 100644 --- a/test/units/balancing/CMakeLists.txt +++ b/test/units/balancing/CMakeLists.txt @@ -11,6 +11,10 @@ add_executable(hictk_balancing_tests) target_sources(hictk_balancing_tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/balancing_test.cpp) +if(HICTK_USE_PCH) + target_precompile_headers(hictk_balancing_tests REUSE_FROM hictk_test_pch) +endif() + target_link_libraries( hictk_balancing_tests PRIVATE hictk_project_warnings hictk_project_options diff --git a/test/units/bin_table/CMakeLists.txt b/test/units/bin_table/CMakeLists.txt index afc87653..67a83cdb 100644 --- a/test/units/bin_table/CMakeLists.txt +++ b/test/units/bin_table/CMakeLists.txt @@ -7,17 +7,21 @@ find_package(Filesystem REQUIRED) include(CTest) include(Catch) -add_executable(bin_table_tests) +add_executable(hictk_bin_table_tests) -target_sources(bin_table_tests PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/bin_table_test.cpp") +target_sources(hictk_bin_table_tests PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/bin_table_test.cpp") + +if(HICTK_USE_PCH) + target_precompile_headers(hictk_bin_table_tests REUSE_FROM hictk_test_pch) +endif() target_link_libraries( - bin_table_tests + hictk_bin_table_tests PRIVATE hictk_project_warnings hictk_project_options PUBLIC hictk::bin_table hictk::format) target_link_system_libraries( - bin_table_tests + hictk_bin_table_tests PUBLIC Catch2::Catch2WithMain std::filesystem) @@ -27,7 +31,7 @@ file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/Testing/") # automatically discover tests that are defined in catch based test files you can modify the unittests. TEST_PREFIX to # whatever you want, or use different for different binaries catch_discover_tests( - bin_table_tests + hictk_bin_table_tests TEST_SPEC "[short]" TEST_SUFFIX @@ -41,7 +45,7 @@ catch_discover_tests( --skip-benchmarks) catch_discover_tests( - bin_table_tests + hictk_bin_table_tests TEST_SPEC "[medium]" TEST_SUFFIX @@ -53,7 +57,7 @@ catch_discover_tests( --skip-benchmarks) catch_discover_tests( - bin_table_tests + hictk_bin_table_tests TEST_SPEC "[long]" TEST_SUFFIX diff --git a/test/units/cooler/CMakeLists.txt b/test/units/cooler/CMakeLists.txt index 0e7fb90e..f2c6c13d 100644 --- a/test/units/cooler/CMakeLists.txt +++ b/test/units/cooler/CMakeLists.txt @@ -39,6 +39,10 @@ target_sources( "${CMAKE_CURRENT_SOURCE_DIR}/utils_merge_test.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/utils_validation_test.cpp") +if(HICTK_USE_PCH) + target_precompile_headers(hictk_cooler_tests REUSE_FROM hictk_test_pch) +endif() + target_link_libraries( hictk_cooler_tests PRIVATE hictk_project_warnings hictk_project_options diff --git a/test/units/file/CMakeLists.txt b/test/units/file/CMakeLists.txt index ffe5d443..3cbc34b8 100644 --- a/test/units/file/CMakeLists.txt +++ b/test/units/file/CMakeLists.txt @@ -11,6 +11,10 @@ add_executable(hictk_file_tests) target_sources(hictk_file_tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/file_test.cpp) +if(HICTK_USE_PCH) + target_precompile_headers(hictk_file_tests REUSE_FROM hictk_test_pch) +endif() + target_link_libraries( hictk_file_tests PRIVATE hictk_project_warnings hictk_project_options diff --git a/test/units/hic/CMakeLists.txt b/test/units/hic/CMakeLists.txt index 26f2d4b3..048253e8 100644 --- a/test/units/hic/CMakeLists.txt +++ b/test/units/hic/CMakeLists.txt @@ -16,6 +16,10 @@ target_sources( "${CMAKE_CURRENT_SOURCE_DIR}/hic_file_test.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/pixel_selector_test.cpp") +if(HICTK_USE_PCH) + target_precompile_headers(hictk_hic_tests REUSE_FROM hictk_test_pch) +endif() + target_link_libraries( hictk_hic_tests PRIVATE hictk_project_warnings hictk_project_options diff --git a/test/units/pch/CMakeLists.txt b/test/units/pch/CMakeLists.txt new file mode 100644 index 00000000..4b326dee --- /dev/null +++ b/test/units/pch/CMakeLists.txt @@ -0,0 +1,12 @@ +# Copyright (C) 2022 Roberto Rossini +# +# SPDX-License-Identifier: MIT + +find_package(Catch2 REQUIRED) + +if(HICTK_USE_PCH) + add_library(hictk_test_pch) + target_sources(hictk_test_pch PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/lib.cpp") + target_precompile_headers(hictk_test_pch PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/pch.hpp") + target_link_libraries(hictk_test_pch PRIVATE hictk_project_options PUBLIC hictk::libhictk Catch2::Catch2WithMain) +endif() diff --git a/test/units/pch/lib.cpp b/test/units/pch/lib.cpp new file mode 100644 index 00000000..e0b18d8f --- /dev/null +++ b/test/units/pch/lib.cpp @@ -0,0 +1,3 @@ +// Copyright (C) 2023 Roberto Rossini +// +// SPDX-License-Identifier: MIT diff --git a/test/units/pch/pch.hpp b/test/units/pch/pch.hpp new file mode 100644 index 00000000..183ea900 --- /dev/null +++ b/test/units/pch/pch.hpp @@ -0,0 +1,42 @@ +// Copyright (C) 2023 Roberto Rossini +// +// SPDX-License-Identifier: MIT + +#pragma once + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "hictk/balancing/methods.hpp" +#include "hictk/bin_table.hpp" +#include "hictk/chromosome.hpp" +#include "hictk/common.hpp" +#include "hictk/cooler/cooler.hpp" +#include "hictk/cooler/dataset.hpp" +#include "hictk/cooler/group.hpp" +#include "hictk/hic/common.hpp" +#include "hictk/pixel.hpp" +#include "hictk/reference.hpp" +#include "hictk/suppress_warnings.hpp" +#include "hictk/type_traits.hpp" diff --git a/test/units/pixel/CMakeLists.txt b/test/units/pixel/CMakeLists.txt index 5d7cae12..b092e876 100644 --- a/test/units/pixel/CMakeLists.txt +++ b/test/units/pixel/CMakeLists.txt @@ -11,6 +11,10 @@ add_executable(hictk_pixel_tests) target_sources(hictk_pixel_tests PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/pixel_test.cpp") +if(HICTK_USE_PCH) + target_precompile_headers(hictk_pixel_tests REUSE_FROM hictk_test_pch) +endif() + target_link_libraries( hictk_pixel_tests PRIVATE hictk_project_warnings hictk_project_options diff --git a/test/units/reference/CMakeLists.txt b/test/units/reference/CMakeLists.txt index a0e798d9..075f92c7 100644 --- a/test/units/reference/CMakeLists.txt +++ b/test/units/reference/CMakeLists.txt @@ -11,6 +11,10 @@ add_executable(hictk_reference_tests) target_sources(hictk_reference_tests PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/reference_test.cpp") +if(HICTK_USE_PCH) + target_precompile_headers(hictk_reference_tests REUSE_FROM hictk_test_pch) +endif() + target_link_libraries( hictk_reference_tests PRIVATE hictk_project_warnings hictk_project_options diff --git a/test/units/transformers/CMakeLists.txt b/test/units/transformers/CMakeLists.txt index abc60290..43cc93ec 100644 --- a/test/units/transformers/CMakeLists.txt +++ b/test/units/transformers/CMakeLists.txt @@ -11,6 +11,10 @@ add_executable(hictk_transformers_tests) target_sources(hictk_transformers_tests PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/transformers_test.cpp") +if(HICTK_USE_PCH) + target_precompile_headers(hictk_transformers_tests REUSE_FROM hictk_test_pch) +endif() + target_link_libraries( hictk_transformers_tests PRIVATE hictk_project_warnings hictk_project_options diff --git a/test/units/variant/CMakeLists.txt b/test/units/variant/CMakeLists.txt index 497d4d91..7bea068e 100644 --- a/test/units/variant/CMakeLists.txt +++ b/test/units/variant/CMakeLists.txt @@ -11,6 +11,10 @@ add_executable(hictk_variant_tests) target_sources(hictk_variant_tests PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/variant_test.cpp") +if(HICTK_USE_PCH) + target_precompile_headers(hictk_variant_tests REUSE_FROM hictk_test_pch) +endif() + target_link_libraries( hictk_variant_tests PRIVATE hictk_project_warnings hictk_project_options From 914e0bf62d1689b15b30e69adf270d9a8ee36457 Mon Sep 17 00:00:00 2001 From: Roberto Rossini <71787608+robomics@users.noreply.github.com> Date: Tue, 12 Dec 2023 12:00:38 +0100 Subject: [PATCH 2/6] Enable PCH in CI --- .github/workflows/codecov.yml | 1 + .github/workflows/macos-ci.yml | 1 + .github/workflows/run-clang-tidy.yml | 1 + .github/workflows/ubuntu-ci.yml | 1 + .github/workflows/windows-ci.yml | 1 + 5 files changed, 5 insertions(+) diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml index c26008cf..01d80fa7 100644 --- a/.github/workflows/codecov.yml +++ b/.github/workflows/codecov.yml @@ -131,6 +131,7 @@ jobs: -DHICTK_ENABLE_TESTING=ON \ -DHICTK_DOWNLOAD_TEST_DATASET=OFF \ -DHICTK_ENABLE_GIT_VERSION_TRACKING=OFF \ + -DHICTK_USE_PCH=ON \ -S . \ -B build diff --git a/.github/workflows/macos-ci.yml b/.github/workflows/macos-ci.yml index f3c951c6..524114d1 100644 --- a/.github/workflows/macos-ci.yml +++ b/.github/workflows/macos-ci.yml @@ -193,6 +193,7 @@ jobs: -DOPT_ENABLE_CPPCHECK=OFF \ -DHICTK_DOWNLOAD_TEST_DATASET=OFF \ -DHICTK_ENABLE_GIT_VERSION_TRACKING=OFF \ + -DHICTK_USE_PCH=ON \ -DCMAKE_INSTALL_PREFIX=dest \ -S "${{ github.workspace }}" \ -B "${{ github.workspace }}/build" diff --git a/.github/workflows/run-clang-tidy.yml b/.github/workflows/run-clang-tidy.yml index 42bde0eb..9064739d 100644 --- a/.github/workflows/run-clang-tidy.yml +++ b/.github/workflows/run-clang-tidy.yml @@ -127,6 +127,7 @@ jobs: -DHICTK_ENABLE_TESTING=ON \ -DHICTK_DOWNLOAD_TEST_DATASET=OFF \ -DHICTK_ENABLE_GIT_VERSION_TRACKING=OFF \ + -DHICTK_USE_PCH=ON \ -S . \ -B build diff --git a/.github/workflows/ubuntu-ci.yml b/.github/workflows/ubuntu-ci.yml index 279cb429..8579f4e0 100644 --- a/.github/workflows/ubuntu-ci.yml +++ b/.github/workflows/ubuntu-ci.yml @@ -256,6 +256,7 @@ jobs: -DHICTK_DOWNLOAD_TEST_DATASET=OFF \ -DHICTK_ENABLE_GIT_VERSION_TRACKING=OFF \ -DCMAKE_INSTALL_PREFIX=dest \ + -DHICTK_USE_PCH=ON \ -S . \ -B build diff --git a/.github/workflows/windows-ci.yml b/.github/workflows/windows-ci.yml index 521e8ecf..53516d86 100644 --- a/.github/workflows/windows-ci.yml +++ b/.github/workflows/windows-ci.yml @@ -172,6 +172,7 @@ jobs: -DHICTK_ENABLE_GIT_VERSION_TRACKING=OFF \ -DOPT_ENABLE_CLANG_TIDY=OFF \ -DOPT_ENABLE_CPPCHECK=OFF \ + -DHICTK_USE_PCH=ON \ -S . \ -B build From e129d3f6b6ede849f12e02bfb91d2c7cdb113d2c Mon Sep 17 00:00:00 2001 From: Roberto Rossini <71787608+robomics@users.noreply.github.com> Date: Tue, 12 Dec 2023 12:04:04 +0100 Subject: [PATCH 3/6] Bugfix --- test/units/pch/CMakeLists.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/units/pch/CMakeLists.txt b/test/units/pch/CMakeLists.txt index 4b326dee..143472f2 100644 --- a/test/units/pch/CMakeLists.txt +++ b/test/units/pch/CMakeLists.txt @@ -2,8 +2,6 @@ # # SPDX-License-Identifier: MIT -find_package(Catch2 REQUIRED) - if(HICTK_USE_PCH) add_library(hictk_test_pch) target_sources(hictk_test_pch PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/lib.cpp") From 6184903f54f74e52cac24ad3477168fb3985f9b8 Mon Sep 17 00:00:00 2001 From: Roberto Rossini <71787608+robomics@users.noreply.github.com> Date: Tue, 12 Dec 2023 12:07:53 +0100 Subject: [PATCH 4/6] Remove devel code --- test/CMakeLists.txt | 3 --- 1 file changed, 3 deletions(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 54338b35..61053e1c 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -23,6 +23,3 @@ if(HICTK_DOWNLOAD_TEST_DATASET) message(STATUS "Downloading test dataset...") include(${PROJECT_SOURCE_DIR}/cmake/FetchTestDataset.cmake) endif() - -add_executable(test123 units/devel/test.cpp) -target_link_libraries(test123 PUBLIC hictk::libhictk) From 2dbd5faa87ef4516d82a5f96054eaa11eb2791d5 Mon Sep 17 00:00:00 2001 From: Roberto Rossini <71787608+robomics@users.noreply.github.com> Date: Tue, 12 Dec 2023 12:41:28 +0100 Subject: [PATCH 5/6] Bugfix --- .github/workflows/windows-ci.yml | 2 +- test/units/pch/CMakeLists.txt | 9 ++++++++- test/units/pch/pch.hpp | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/.github/workflows/windows-ci.yml b/.github/workflows/windows-ci.yml index 53516d86..7f346132 100644 --- a/.github/workflows/windows-ci.yml +++ b/.github/workflows/windows-ci.yml @@ -172,7 +172,7 @@ jobs: -DHICTK_ENABLE_GIT_VERSION_TRACKING=OFF \ -DOPT_ENABLE_CLANG_TIDY=OFF \ -DOPT_ENABLE_CPPCHECK=OFF \ - -DHICTK_USE_PCH=ON \ + -DHICTK_USE_PCH=OFF \ -S . \ -B build diff --git a/test/units/pch/CMakeLists.txt b/test/units/pch/CMakeLists.txt index 143472f2..8a6b0fbe 100644 --- a/test/units/pch/CMakeLists.txt +++ b/test/units/pch/CMakeLists.txt @@ -2,9 +2,16 @@ # # SPDX-License-Identifier: MIT +find_package(fmt REQUIRED) + if(HICTK_USE_PCH) add_library(hictk_test_pch) target_sources(hictk_test_pch PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/lib.cpp") target_precompile_headers(hictk_test_pch PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/pch.hpp") - target_link_libraries(hictk_test_pch PRIVATE hictk_project_options PUBLIC hictk::libhictk Catch2::Catch2WithMain) + target_link_libraries( + hictk_test_pch + PRIVATE hictk_project_options hictk_project_warnings + PUBLIC hictk::libhictk + Catch2::Catch2WithMain + fmt::fmt-header-only) endif() diff --git a/test/units/pch/pch.hpp b/test/units/pch/pch.hpp index 183ea900..c6ef74a7 100644 --- a/test/units/pch/pch.hpp +++ b/test/units/pch/pch.hpp @@ -16,7 +16,7 @@ #include #include #include -#include +// #include #include #include #include From 8846dcc149ec11bbca26889775bef6fbbc42268e Mon Sep 17 00:00:00 2001 From: Roberto Rossini <71787608+robomics@users.noreply.github.com> Date: Tue, 12 Dec 2023 21:07:50 +0100 Subject: [PATCH 6/6] Bugfix --- CMakeLists.txt | 2 ++ src/libhictk/balancing/CMakeLists.txt | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f3a9d1d7..bf6ecc08 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -117,6 +117,8 @@ target_compile_features(hictk_project_options INTERFACE "cxx_std_${CMAKE_CXX_STA # Tweak fmt target_compile_definitions(hictk_project_options INTERFACE FMT_HEADER_ONLY FMT_ENFORCE_COMPILE_STRING) +# Tweak spanlite +target_compile_definitions(hictk_project_options INTERFACE span_FEATURE_MAKE_SPAN=1) # Tweak spdlog target_compile_definitions(hictk_project_options INTERFACE SPDLOG_FMT_EXTERNAL) #Tweak xxHash diff --git a/src/libhictk/balancing/CMakeLists.txt b/src/libhictk/balancing/CMakeLists.txt index e6325e44..c94cee29 100644 --- a/src/libhictk/balancing/CMakeLists.txt +++ b/src/libhictk/balancing/CMakeLists.txt @@ -30,5 +30,3 @@ target_link_system_libraries( phmap xxHash::xxhash "zstd::libzstd_$,shared,static>") - -target_compile_definitions(balancing INTERFACE span_FEATURE_MAKE_SPAN=1)