diff --git a/.github/workflows/non_vendored.yml b/.github/workflows/non_vendored.yml index 10040462ac..6ee14f06c6 100644 --- a/.github/workflows/non_vendored.yml +++ b/.github/workflows/non_vendored.yml @@ -53,7 +53,12 @@ jobs: cmake -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_STANDARD=17 -DCMAKE_POSITION_INDEPENDENT_CODE=ON . && cmake --build build && sudo cmake --install build popd - git clone --depth 1 https://github.com/chipsalliance/UHDM.git + git clone --depth 1 --branch v3.11.2 https://github.com/nlohmann/json.git + pushd json + cmake -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_STANDARD=17 -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DJSON_BuildTests=OFF . && cmake --build build && sudo cmake --install build + popd + + git clone --depth 1 --branch v1.74 https://github.com/chipsalliance/UHDM.git pushd UHDM cmake -B build -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DUHDM_USE_HOST_GTEST=ON -DUHDM_USE_HOST_CAPNP=ON . && cmake --build build && sudo cmake --install build popd @@ -80,7 +85,7 @@ jobs: # for any run checks, such as those in the `TestInstall` project export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH - cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_INSTALL_PREFIX=$INSTALL_DIR -DBUILD_SHARED_LIBS=ON -DSURELOG_USE_HOST_ANTLR=ON -DSURELOG_USE_HOST_UHDM=ON -DSURELOG_USE_HOST_GTEST=ON -DSURELOG_WITH_TCMALLOC=OFF -DCMAKE_MODULE_PATH="/usr/share/CMake/Modules;/usr/local/lib/cmake" -S . -B build + cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_INSTALL_PREFIX=$INSTALL_DIR -DBUILD_SHARED_LIBS=ON -DSURELOG_USE_HOST_ALL=ON -DSURELOG_WITH_TCMALLOC=OFF -DCMAKE_MODULE_PATH="/usr/share/CMake/Modules;/usr/local/lib/cmake" -S . -B build cmake --build build -j $(nproc) cmake --install build @@ -92,7 +97,7 @@ jobs: # this shouldnt be necessary, and can't be reproduced outside CI export CMAKE_PREFIX_PATH=$INSTALL_DIR - cmake -DCMAKE_BUILD_TYPE=Release -DINSTALL_DIR=$INSTALL_DIR -DCMAKE_INSTALL_PREFIX=$INSTALL_DIR -DBUILD_SHARED_LIBS=ON -DSURELOG_USE_HOST_ANTLR=ON -DSURELOG_USE_HOST_UHDM=ON -DSURELOG_USE_HOST_GTEST=ON -S tests/TestInstall -B tests/TestInstall/build + cmake -DCMAKE_BUILD_TYPE=Release -DINSTALL_DIR=$INSTALL_DIR -DCMAKE_INSTALL_PREFIX=$INSTALL_DIR -DBUILD_SHARED_LIBS=ON -DSURELOG_USE_HOST=ON -S tests/TestInstall -B tests/TestInstall/build cmake --build tests/TestInstall/build -j $(nproc) echo "-- pkg-config content --" diff --git a/.gitmodules b/.gitmodules index 96eca7d8aa..f620d5a527 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,9 +1,13 @@ +# NOTE: Do not expliclty rely on a third party module, +# as this is not acceptable for several registries +# and distribution systems. If you add to this file, +# ensure that you add the requisite optionality to both +# CMakeLists.txt and .github/workflows/non_vendored.yml + [submodule "third_party/UHDM"] path = third_party/UHDM url = https://github.com/chipsalliance/UHDM.git -[submodule "third_party/googletest"] - path = third_party/googletest - url = https://github.com/google/googletest.git + branch = v1.74 [submodule "third_party/antlr4"] path = third_party/antlr4 url = https://github.com/antlr/antlr4.git @@ -11,3 +15,7 @@ [submodule "third_party/json"] path = third_party/json url = https://github.com/nlohmann/json.git + branch = v3.11.2 +[submodule "third_party/googletest"] + path = third_party/googletest + url = https://github.com/google/googletest.git diff --git a/CMakeLists.txt b/CMakeLists.txt index be4aa2f5a2..7bb1b6c92c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,18 +26,23 @@ option( "If buildling with clang++ and libc++(in Linux). To enable with: -DWITH_LIBCXX=On" OFF) +option( + SURELOG_USE_HOST_ALL + "Default to using libraries from host instead of third_party" OFF) option( SURELOG_USE_HOST_ANTLR - "Use Antlr library from host instead of third_party" OFF) + "Use Antlr library from host instead of third_party" ${SURELOG_USE_HOST_ALL}) option( SURELOG_USE_HOST_UHDM - "Use UHDM library from host instead of third_party" OFF) + "Use UHDM library from host instead of third_party" ${SURELOG_USE_HOST_ALL}) +option(SURELOG_USE_HOST_JSON + "Use nlohmann json from host instead of third_party" ${SURELOG_USE_HOST_ALL}) option(SURELOG_USE_HOST_CAPNP "Use capnproto from host system, not UHDM (if OFF, requires SURELOG_USE_HOST_UHDM=OFF)" OFF) option( SURELOG_USE_HOST_GTEST - "Use googletest library from host instead of third_party" OFF) + "Use googletest library from host instead of third_party" ${SURELOG_USE_HOST_ALL}) option( SURELOG_WITH_TCMALLOC "Use tcmalloc if installed" ON) @@ -125,7 +130,28 @@ else() # Requires SURELOG_USE_HOST_UHDM=Off endif() -add_subdirectory(third_party/json) +if (SURELOG_USE_HOST_JSON) + find_package(nlohmann_json) + get_target_property(JSON_INCLUDE_DIR nlohmann_json::nlohmann_json INTERFACE_INCLUDE_DIRECTORIES) +else() + # https://json.nlohmann.me/integration/cmake/#supporting-both + set(JSON_BuildTests OFF CACHE INTERNAL "") + add_subdirectory(third_party/json) + set(JSON_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/third_party/json/single_include) +endif() + +# _ _ ____ _______ ______ +# | \ | |/ __ \__ __| ____| +# | \| | | | | | | | |__ +# | . ` | | | | | | | __| +# | |\ | |__| | | | | |____ +# |_| \_|\____/ |_| |______| +# Do not expliclty rely on a third party module, +# e.g. add_subdirectory(third_party/...) +# as this is not acceptable for several registries +# and distribution systems. Instead, follow the pattern +# above to have optionality, which can be tested +# in .github/workflows/non_vendored.yml # NOTE: Set the global output directories after the subprojects have had their go at it set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib) @@ -524,7 +550,7 @@ target_include_directories(surelog PUBLIC $ $) target_include_directories(surelog PUBLIC - $ + $ $) if (SURELOG_WITH_PYTHON) diff --git a/tests/TestInstall/CMakeLists.txt b/tests/TestInstall/CMakeLists.txt index c096a72d5e..70fad4a21c 100644 --- a/tests/TestInstall/CMakeLists.txt +++ b/tests/TestInstall/CMakeLists.txt @@ -34,27 +34,22 @@ set(CMAKE_THREAD_PREFER_PTHREAD TRUE) set(THREADS_PREFER_PTHREAD_FLAG TRUE) find_package(Threads REQUIRED) -if(SURELOG_USE_HOST_ANTLR) +if(SURELOG_USE_HOST) find_package(ANTLR REQUIRED) -else() - set(ANTLR_LIBRARY antlr4-runtime$<$:-static>) -endif() - -if(SURELOG_USE_HOST_UHDM) find_package(UHDM REQUIRED) find_package(CapnProto) set(UHDM_LIBRARY uhdm::uhdm) set(CAPNPROTO_LIBRARY CapnProto::capnp) + find_package(GTest REQUIRED) + find_package(nlohmann_json) + get_target_property(JSON_INCLUDE_DIR nlohmann_json INTERFACE_INCLUDE_DIRECTORIES) else() + set(ANTLR_LIBRARY antlr4-runtime$<$:-static>) set(UHDM_LIBRARY uhdm) set(UHDM_LIB_DIR "${INSTALL_DIR}/lib/uhdm" "${INSTALL_DIR}/lib64/uhdm") set(CAPNPROTO_LIBRARY capnp kj) endif() -if(SURELOG_USE_HOST_GTEST) - find_package(GTest REQUIRED) -endif() - # Python if (SURELOG_WITH_PYTHON) find_package(Python3 3.3 REQUIRED COMPONENTS Interpreter Development)