Skip to content

Commit

Permalink
enable building of shared libraries, export version information
Browse files Browse the repository at this point in the history
  • Loading branch information
timkpaine committed Mar 19, 2023
1 parent b7b36a3 commit 14a7bb4
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 9 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,29 +55,29 @@ jobs:
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
cmake -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_STANDARD=17 -DBUILD_SHARED_LIBS=ON . && 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
cmake -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_STANDARD=17 -DBUILD_SHARED_LIBS=ON . && 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
cmake -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_STANDARD=17 -DBUILD_SHARED_LIBS=ON . && 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
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
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
unzip ../antlr4-cpp-runtime-4.12.0-source.zip && cmake -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_STANDARD=17 -DBUILD_SHARED_LIBS=ON . && cmake --build build && sudo cmake --install build
popd
if: ${{ !matrix.vendored_dependencies }}

Expand All @@ -94,7 +94,7 @@ jobs:
export INSTALL_DIR=`pwd`/install
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
cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_INSTALL_PREFIX=$INSTALL_DIR -DBUILD_SHARED_LIBS=ON -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
Expand All @@ -108,7 +108,7 @@ jobs:
rm -rf build # make sure we only see installation artifacts
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
cmake -DCMAKE_BUILD_TYPE=Release -DINSTALL_DIR=$INSTALL_DIR -DCMAKE_INSTALL_PREFIX=/home/timkpaine/Developer/programs/dau/third/Surelog/install -DBUILD_SHARED_LIBS=ON -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
Expand Down
34 changes: 34 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,40 @@ foreach(gen_src ${surelog_generated_SRC})
set_source_files_properties(${gen_src} PROPERTIES GENERATED TRUE)
endforeach()

# Parse out version and configure header
if(NOT DEFINED ENV{SURELOG_VERSION_MAJOR})
# parse from working directory
# ensure `git` is installed
find_package (Git REQUIRED)

# get latest commit
execute_process(COMMAND git describe --tags --abbrev=0
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE LATEST_VERSION)

# parse out first number after "v"
string(REGEX REPLACE "^v([0-9]+)\\..*" "\\1" SURELOG_VERSION_MAJOR "${LATEST_VERSION}")
# parse out second number, e.g. after "v[0-9]."
string(REGEX REPLACE "^v[0-9]+\\.([0-9]+).*" "\\1" SURELOG_VERSION_MINOR "${LATEST_VERSION}")

# get latest commit
execute_process(COMMAND git rev-parse HEAD
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE SURELOG_VERSION_COMMIT_SHA)
# strip newline
string(REGEX REPLACE "\n$" "" SURELOG_VERSION_COMMIT_SHA "${SURELOG_VERSION_COMMIT_SHA}")
else()
# if set in env, assume some other deployment mechanism where
# not working from the git repo / where git not installed
set(SURELOG_VERSION_MAJOR ENV{SURELOG_VERSION_MAJOR})
set(SURELOG_VERSION_MINOR ENV{SURELOG_VERSION_MINOR})
set(SURELOG_VERSION_COMMIT_SHA ENV{SURELOG_VERSION_COMMIT_SHA})
endif()

set(SURELOG_BUILD_TYPE ${CMAKE_BUILD_TYPE})
message("Building version v${SURELOG_VERSION_MAJOR}.${SURELOG_VERSION_MINOR} [${SURELOG_VERSION_COMMIT_SHA}]")
configure_file(${CMAKE_SOURCE_DIR}/include/Surelog/surelog-version.h.in ${GENDIR}/include/Surelog/surelog-version.h)

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

Expand Down
6 changes: 6 additions & 0 deletions include/Surelog/surelog-version.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#define SURELOG_VERSION_MAJOR @SURELOG_VERSION_MAJOR@
#define SURELOG_VERSION_MINOR @SURELOG_VERSION_MINOR@
#define SURELOG_VERSION_COMMIT_SHA @SURELOG_VERSION_COMMIT_SHA@
#define SURELOG_VERSION (SURELOG_VERSION_MAJOR * 1000) + SURELOG_VERSION_MINOR

#define SURELOG_BUILD_TYPE @SURELOG_BUILD_TYPE@
2 changes: 1 addition & 1 deletion third_party/UHDM
2 changes: 1 addition & 1 deletion third_party/googletest
Submodule googletest updated 130 files

0 comments on commit 14a7bb4

Please sign in to comment.