Skip to content

Commit

Permalink
WIP working on followup to #3182 to allow for removal of vendored lib…
Browse files Browse the repository at this point in the history
…raries and relying instead on system-installed deps for better packaging

Tweaking include directories, leads to CMake error

fix flatbuffers install on ubuntu

fix antlr4 apt package name, shouldve just used my ubuntu machine from the start..

prune build matrix to exclude no-vendoring on most strategies

fix typo in action, add uhdm include path back

fix cmake additional flags export syntax in github action

clean up includes a bit when vendoring UHDM

tweaks find uhdm, fixes for include paths and library links

tweak find paths for antlr jar

see where antlr assets end up

tweak jar path as well

install antlr manually

Fix typo in capnproto library name

fix missing install dir inclusion in cmake file

update test install to work with external deps

more tweaks for tests
  • Loading branch information
timkpaine committed Mar 10, 2023
1 parent efd45b9 commit c3cc298
Show file tree
Hide file tree
Showing 6 changed files with 444 additions and 74 deletions.
66 changes: 61 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:

# Linux build, test, and publish
linux-install:
name: "Linux | Install | ${{ matrix.compiler }} | ${{ matrix.config }}"
name: "Linux | Install | ${{ matrix.compiler }} | ${{ matrix.config }} | ${{ matrix.vendored_dependencies }}"
runs-on: ubuntu-20.04
strategy:
fail-fast: false
Expand All @@ -23,6 +23,14 @@ jobs:
config:
- debug
- release
vendored_dependencies: [true, false]
exclude:
# Unnecessary to test no-vendoring across every strategy
- compiler: clang
vendored_dependencies: false
- config: debug
vendored_dependencies: false

env:
artifact-name: sl-${{ github.run_number }}-linux-${{ matrix.compiler }}-${{ matrix.config }}

Expand All @@ -32,12 +40,47 @@ jobs:
with:
submodules: recursive
fetch-depth: 0
if: ${{ matrix.vendored_dependencies }}

- name: Checkout code
uses: actions/checkout@v3
if: ${{ !matrix.vendored_dependencies }}

- uses: ./.github/linux-setup
with:
compiler: ${{ matrix.compiler }}
ccache-key: linux-install-${{ matrix.compiler }}-${{ matrix.config }}

- name: Install vendored dependencies
run: |
git clone https://github.com/google/flatbuffers.git
pushd flatbuffers
cmake -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_STANDARD=17 . && cmake --build build && sudo cmake --install build
popd
git clone https://github.com/google/googletest.git
pushd googletest
cmake -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_STANDARD=17 . && cmake --build build && sudo cmake --install build
popd
git clone https://github.com/capnproto/capnproto.git
pushd capnproto
cmake -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_STANDARD=17 . && cmake --build build && sudo cmake --install build
popd
git clone https://github.com/chipsalliance/UHDM.git
pushd UHDM
cmake -B build -DCMAKE_BUILD_TYPE=Release -DUHDM_USE_HOST_GTEST=ON -DUHDM_USE_HOST_CAPNP=ON . && cmake --build build && sudo cmake --install build
popd
sudo mkdir -p /usr/share/java
sudo wget https://www.antlr.org/download/antlr-4.12.0-complete.jar -P /usr/share/java
wget https://www.antlr.org/download/antlr4-cpp-runtime-4.12.0-source.zip && mkdir antlr4
pushd antlr4
unzip ../antlr4-cpp-runtime-4.12.0-source.zip && cmake -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_STANDARD=17 . && cmake --build build && sudo cmake --install build
popd
if: ${{ !matrix.vendored_dependencies }}

- name: Build, install & test
run: |
if [ "${{ matrix.config }}" == "debug" ]; then
Expand All @@ -47,31 +90,44 @@ jobs:
export BUILD_TYPE=Release
export CMAKE_ADDITIONAL_ARGS=
fi
export INSTALL_DIR=`pwd`/install

cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_INSTALL_PREFIX=$INSTALL_DIR $CMAKE_ADDITIONAL_ARGS -S . -B build
if [ "${{ matrix.vendored_dependencies }}" == "false" ]; then
cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_INSTALL_PREFIX=$INSTALL_DIR -DSURELOG_USE_HOST_FLATBUFFERS=ON -DSURELOG_USE_HOST_ANTLR=ON -DSURELOG_USE_HOST_UHDM=ON -DSURELOG_USE_HOST_GTEST=ON -S . -B build
else
cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_INSTALL_PREFIX=$INSTALL_DIR $CMAKE_ADDITIONAL_ARGS -S . -B build
fi

cmake --build build -j $(nproc)
cmake --install build

cmake --build build --target UnitTests -j $(nproc)
pushd build && ctest --output-on-failure && popd

rm -rf build # make sure we only see installation artifacts
cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DINSTALL_DIR=$INSTALL_DIR -S tests/TestInstall -B tests/TestInstall/build

if [ "${{ matrix.vendored_dependencies }}" == "false" ]; then
cmake -DCMAKE_BUILD_TYPE=Release -DINSTALL_DIR=$INSTALL_DIR -DCMAKE_INSTALL_PREFIX=/home/timkpaine/Developer/programs/dau/third/Surelog/install -DSURELOG_USE_HOST_FLATBUFFERS=ON -DSURELOG_USE_HOST_ANTLR=ON -DSURELOG_USE_HOST_UHDM=ON -DSURELOG_USE_HOST_GTEST=ON -S tests/TestInstall -B tests/TestInstall/build
else
cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DINSTALL_DIR=$INSTALL_DIR -S tests/TestInstall -B tests/TestInstall/build
fi

cmake --build tests/TestInstall/build -j $(nproc)

- name: Prepare build artifacts
run: |
mkdir artifacts
mv install ${{ env.artifact-name }}
tar czfp artifacts/${{ env.artifact-name }}.tar.gz ${{ env.artifact-name }}
if: ${{ matrix.vendored_dependencies }}

- name: Upload build artifacts
uses: actions/upload-artifact@v3
with:
name: ${{ env.artifact-name }}
path: artifacts/${{ env.artifact-name }}.tar.gz
if: ${{ matrix.vendored_dependencies }}


# Linux regression
Expand Down Expand Up @@ -957,7 +1013,7 @@ jobs:
python3 scripts/regression.py run \
--uhdm-dump-filepath bin/uhdm-dump \
--jobs $(nproc) \
--jobs $(sysctl -n hw.physicalcpu) \
--show-diffs \
--num_shards=${{ matrix.num_shards }} \
--shard=${{ matrix.shard }}
Expand Down
147 changes: 99 additions & 48 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- mode:cmake -*-
cmake_minimum_required(VERSION 3.15 FATAL_ERROR)
cmake_minimum_required(VERSION 3.20 FATAL_ERROR)

# Detect build type, fallback to release and throw a warning if use didn't
# specify any
Expand All @@ -13,6 +13,8 @@ if(NOT CMAKE_BUILD_TYPE)
FORCE)
endif(NOT CMAKE_BUILD_TYPE)

set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules" ${CMAKE_MODULE_PATH})

option(
WITH_LIBCXX
"If buildling with clang++ and libc++(in Linux). To enable with: -DWITH_LIBCXX=On"
Expand All @@ -21,14 +23,17 @@ option(
option(
SURELOG_USE_HOST_FLATBUFFERS
"Use flatbuffers library from host instead of third_party" OFF)

option(SURELOG_BUILD_TESTS "Enable testing." ON)

# TODO SURELOG_USE_HOST_CAPNP
# TODO SURELOG_USE_HOST_ANTLR
# TODO SURELOG_USE_HOST_UHDM
option(
SURELOG_USE_HOST_ANTLR
"Use Antlr library from host instead of third_party" OFF)
option(
SURELOG_USE_HOST_UHDM
"Use UHDM library from host instead of third_party" OFF)
option(
SURELOG_USE_HOST_GTEST
"Use googletest library from host instead of third_party" OFF)

include(FindPkgConfig)
option(SURELOG_BUILD_TESTS "Enable testing." ON)

project(SURELOG)

Expand All @@ -47,19 +52,44 @@ endif()

set(FLATBUFFERS_FLATC_EXECUTABLE "flatc")
if(SURELOG_USE_HOST_FLATBUFFERS)
pkg_check_modules(FLATBUFFERS IMPORTED_TARGET REQUIRED flatbuffers>=2.0.7)
find_package(Flatbuffers REQUIRED)
set(FLATBUFFERS_LIBRARY flatbuffers::flatbuffers)
else()
set(FLATBUFFERS_BUILD_TESTS OFF CACHE BOOL "Skip flatbuffers' tests")
add_subdirectory(third_party/flatbuffers EXCLUDE_FROM_ALL)
set(FLATBUFFERS_LIBRARY flatbuffers)
endif()

set(WITH_STATIC_CRT ON CACHE BOOL "Use Static CRT")
set(ANTLR_BUILD_CPP_TESTS OFF CACHE BOOL "Skip ANTLR tests")
add_subdirectory(third_party/antlr4/runtime/Cpp EXCLUDE_FROM_ALL)

if(SURELOG_USE_HOST_ANTLR)
find_package(ANTLR REQUIRED)
else()
add_subdirectory(third_party/antlr4/runtime/Cpp EXCLUDE_FROM_ALL)
set(ANTLR_JAR_LOCATION ${PROJECT_SOURCE_DIR}/third_party/antlr4_bin/antlr-4.12.0-complete.jar)
set(ANTLR_LIBRARY antlr4_static)
set(ANTLR_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/third_party/antlr4/runtime/Cpp/runtime/src)
endif()

set(UHDM_BUILD_TESTS OFF CACHE BOOL "Skip UHDM tests")
add_subdirectory(third_party/UHDM)
add_subdirectory(third_party/googletest EXCLUDE_FROM_ALL)
if(SURELOG_USE_HOST_UHDM)
find_package(UHDM REQUIRED)
find_package(CapnProto)
set(CAPNPROTO_LIBRARY CapnProto::capnp)
else()
add_subdirectory(third_party/UHDM)
set(UHDM_LIBRARY uhdm)
get_target_property(UHDM_INCLUDE_DIRS uhdm INCLUDE_DIRECTORIES)
set(CAPNPROTO_LIBRARY capnp)
endif()

if(SURELOG_USE_HOST_GTEST)
find_package(GTest REQUIRED)
else()
add_subdirectory(third_party/googletest EXCLUDE_FROM_ALL)
set(GTEST_INCLUDE_DIRS third_party/googletest/googletest/include third_party/googletest/googlemock/include)
endif()

# 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 @@ -162,8 +192,6 @@ add_custom_command(
# Java
find_package(Java 11 REQUIRED COMPONENTS Runtime)
message(STATUS "Java_JAVA_EXECUTABLE = ${Java_JAVA_EXECUTABLE}")
set(ANTLR_JAR_LOCATION
${PROJECT_SOURCE_DIR}/third_party/antlr4_bin/antlr-4.12.0-complete.jar)

add_custom_target(GenerateParser DEPENDS
${GENDIR}/src/parser/generated-parsers.tstamp
Expand Down Expand Up @@ -426,14 +454,25 @@ foreach(gen_src ${surelog_generated_SRC})
set_source_files_properties(${gen_src} PROPERTIES GENERATED TRUE)
endforeach()

add_library(surelog STATIC ${surelog_SRC} ${surelog_generated_SRC})
add_library(surelog ${surelog_SRC} ${surelog_generated_SRC})
set_target_properties(surelog PROPERTIES PUBLIC_HEADER include/Surelog/surelog.h)

if(BUILD_SHARED_LIBS)
set_property(TARGET surelog PROPERTY POSITION_INDEPENDENT_CODE 1)
endif()

target_include_directories(surelog PUBLIC
$<BUILD_INTERFACE:${GENDIR}/include>
$<BUILD_INTERFACE:${GENDIR}/src>)
target_include_directories(surelog PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)
target_include_directories(surelog PUBLIC
$<BUILD_INTERFACE:${ANTLR_INCLUDE_DIR}>
$<INSTALL_INTERFACE:include>)
target_include_directories(surelog PUBLIC
$<BUILD_INTERFACE:${UHDM_INCLUDE_DIRS}>
$<INSTALL_INTERFACE:include>)

if (SURELOG_WITH_PYTHON)
target_include_directories(surelog PUBLIC ${Python3_INCLUDE_DIRS}) # Keep this at the end
Expand Down Expand Up @@ -478,20 +517,28 @@ if(MSVC OR WIN32)
endif()

target_link_libraries(surelog-bin PUBLIC surelog)
target_link_libraries(surelog PUBLIC antlr4_static)
target_link_libraries(surelog PUBLIC ${ANTLR_LIBRARY})
target_include_directories(surelog PUBLIC ${FLATBUFFERS_INCLUDE_DIRS})

if(SURELOG_USE_HOST_FLATBUFFERS)
target_link_libraries(surelog PRIVATE PkgConfig::FLATBUFFERS)
target_include_directories(surelog PUBLIC ${FLATBUFFERS_INCLUDE_DIRS})
else()
target_link_libraries(surelog PUBLIC flatbuffers)
target_link_libraries(surelog PRIVATE ${FLATBUFFERS_LIBRARY})
if(NOT SURELOG_USE_HOST_FLATBUFFERS)
add_dependencies(surelog flatc)
endif()

target_link_libraries(surelog PUBLIC uhdm)
target_link_libraries(surelog PUBLIC ${UHDM_LIBRARY})
target_link_libraries(surelog PRIVATE ${CAPNPROTO_LIBRARY})

if(NOT SURELOG_USE_HOST_UHDM)
add_dependencies(GenerateSerializer ${UHDM_LIBRARY})
target_include_directories(surelog PUBLIC
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/third_party/UHDM/generated>
$<INSTALL_INTERFACE:include>)
endif()

if(NOT SURELOG_USE_HOST_ANTLR)
add_dependencies(GenerateParser ${ANTLR_LIBRARY})
endif()

add_dependencies(GenerateSerializer uhdm)
add_dependencies(GenerateParser antlr4_static)
add_dependencies(surelog GenerateParser)
add_dependencies(surelog GenerateSerializer)

Expand All @@ -515,7 +562,9 @@ if (UNIX)
endif()

if (CMAKE_SYSTEM_NAME MATCHES "Linux")
target_link_libraries(uhdm PRIVATE stdc++fs)
if(NOT SURELOG_USE_HOST_UHDM)
target_link_libraries(uhdm PRIVATE stdc++fs)
endif()
target_link_libraries(surelog PRIVATE stdc++fs)
target_link_libraries(surelog PRIVATE rt)
endif()
Expand Down Expand Up @@ -556,7 +605,7 @@ if (SURELOG_BUILD_TESTS)
# For simplicity, we link the test with libsurelog, but there is of
# course a lot unnecessary churn if headers are modified.
# Often it is sufficient to just have a few depeendencies.
target_link_libraries(${test_bin} surelog gtest gmock gtest_main)
target_link_libraries(${test_bin} surelog GTest::gtest GTest::gmock GTest::gtest_main)
gtest_discover_tests(${test_bin}
TEST_PREFIX "${test_prefix}/"
DISCOVERY_TIMEOUT 60)
Expand Down Expand Up @@ -658,6 +707,8 @@ add_dependencies(hellosureworld PrecompileOVM)
add_dependencies(hellosureworld PrecompileUVM)
endif()

include(GNUInstallDirs)

# Installation target
if (QUICK_COMP)
install(
Expand All @@ -676,14 +727,13 @@ install(
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}/surelog
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/Surelog)

# TODO: SURELOG_USE_HOST_ANTLR
install(
TARGETS antlr4_static
EXPORT Surelog
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}/surelog
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/Surelog)
target_include_directories(surelog PRIVATE
third_party/antlr4/runtime/Cpp/runtime/src)
if(NOT SURELOG_USE_HOST_ANTLR)
install(
TARGETS antlr4_static
EXPORT Surelog
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}/surelog
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/Surelog)
endif()

if(NOT SURELOG_USE_HOST_FLATBUFFERS)
# TODO: should we even install these from third_party ? If it is
Expand All @@ -696,28 +746,27 @@ if(NOT SURELOG_USE_HOST_FLATBUFFERS)
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/Surelog)
endif()

# TODO SURELOG_USE_HOST_CAPNP
install(
TARGETS capnp kj
EXPORT Surelog
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}/uhdm
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/uhdm)
if(NOT SURELOG_USE_HOST_UHDM)
install(
TARGETS capnp kj
EXPORT Surelog
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}/uhdm
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/uhdm)

# TODO: SURELOG_USE_HOST_UHDM
install(
TARGETS uhdm
EXPORT Surelog
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}/uhdm
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/uhdm)
install(
TARGETS uhdm
EXPORT Surelog
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}/uhdm
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/uhdm)
endif()

if (SURELOG_WITH_PYTHON)
install(
DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/python
DESTINATION ${CMAKE_INSTALL_LIBDIR}/surelog)
endif()

install(DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/pkg
DESTINATION ${CMAKE_INSTALL_BINDIR})
install(DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/pkg DESTINATION ${CMAKE_INSTALL_BINDIR})
install(
FILES ${PROJECT_SOURCE_DIR}/include/Surelog/CommandLine/CommandLineParser.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/Surelog/CommandLine)
Expand Down Expand Up @@ -850,6 +899,8 @@ install(
EXPORT Surelog
FILE Surelog.cmake
DESTINATION cmake)

# Generate cmake config files for reuse by downstream packages
include(CMakePackageConfigHelpers)

# generate the config file that is includes the exports
Expand Down
Loading

0 comments on commit c3cc298

Please sign in to comment.