Skip to content

Commit

Permalink
Merge pull request chipsalliance#3832 from timkpaine/tkp/vendorjson
Browse files Browse the repository at this point in the history
WIP - fix vendored workflows
  • Loading branch information
alaindargelas authored Sep 4, 2023
2 parents 1d14220 + 95bef10 commit 6166829
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 21 deletions.
11 changes: 8 additions & 3 deletions .github/workflows/non_vendored.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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 --"
Expand Down
14 changes: 11 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
# 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
branch = dev
[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
36 changes: 31 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -524,7 +550,7 @@ target_include_directories(surelog PUBLIC
$<BUILD_INTERFACE:${UHDM_INCLUDE_DIRS}>
$<INSTALL_INTERFACE:include>)
target_include_directories(surelog PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/third_party/json/single_include>
$<BUILD_INTERFACE:${JSON_INCLUDE_DIR}>
$<INSTALL_INTERFACE:include>)

if (SURELOG_WITH_PYTHON)
Expand Down
15 changes: 5 additions & 10 deletions tests/TestInstall/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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$<$<BOOL:${WIN32}>:-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$<$<BOOL:${WIN32}>:-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)
Expand Down

0 comments on commit 6166829

Please sign in to comment.