Skip to content

Commit

Permalink
rework cmake configuration for auto discovery to match UHDM changes
Browse files Browse the repository at this point in the history
a few tweaks, use cmake test project to test surelog cmake installed config

Tweak modules path in test project

debug

cleanup
  • Loading branch information
timkpaine committed Apr 14, 2023
1 parent e1900c2 commit 9d9430e
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 34 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ jobs:
pushd build && ctest --output-on-failure && popd
rm -rf build # make sure we only see installation artifacts
# this shouldnt be necessary, and can't be reproduced outside CI
export CMAKE_PREFIX_PATH=$INSTALL_DIR
if [ "${{ matrix.vendored_dependencies }}" == "false" ]; then
cmake -DCMAKE_BUILD_TYPE=Release -DINSTALL_DIR=$INSTALL_DIR -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 tests/TestInstall -B tests/TestInstall/build
Expand Down Expand Up @@ -697,6 +700,7 @@ jobs:
set CC=cl
set CXX=cl
set PREFIX=%GITHUB_WORKSPACE%\install
set CMAKE_PREFIX_PATH=%GITHUB_WORKSPACE%\install
set CPU_CORES=%NUMBER_OF_PROCESSORS%
set MAKE_DIR=C:\make\bin
Expand Down Expand Up @@ -726,6 +730,7 @@ jobs:
set CC=clang
set CXX=clang++
set PREFIX=%GITHUB_WORKSPACE%\install
set CMAKE_PREFIX_PATH=%GITHUB_WORKSPACE%\install
set CPU_CORES=%NUMBER_OF_PROCESSORS%
set MAKE_DIR=C:\make\bin
Expand Down Expand Up @@ -930,7 +935,8 @@ jobs:
- name: Configure shell
run: |
echo "PATH=$(brew --prefix)/opt/ccache/libexec:$PATH" >> $GITHUB_ENV
echo 'PREFIX=${GITHUB_WORKSPACE}/install' >> $GITHUB_ENV
echo "PREFIX=${GITHUB_WORKSPACE}/install" >> $GITHUB_ENV
echo "CMAKE_PREFIX_PATH=${GITHUB_WORKSPACE}/install" >> $GITHUB_ENV
echo 'ADDITIONAL_CMAKE_OPTIONS=-DPython3_ROOT_DIR=${pythonLocation}' >> $GITHUB_ENV
- name: Show shell configuration
Expand Down
53 changes: 31 additions & 22 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ set(UHDM_BUILD_TESTS OFF CACHE BOOL "Skip UHDM tests")
if(SURELOG_USE_HOST_UHDM)
find_package(UHDM REQUIRED)
find_package(CapnProto)
set(UHDM_LIBRARY uhdm::uhdm)
set(CAPNPROTO_LIBRARY CapnProto::capnp)
else()
add_subdirectory(third_party/UHDM)
Expand Down Expand Up @@ -542,10 +543,10 @@ if (APPLE)
endif()

if (NOT QUICK_COMP)
add_executable(hellosureworld ${PROJECT_SOURCE_DIR}/src/hellosureworld.cpp)
add_executable(hellouhdm ${PROJECT_SOURCE_DIR}/src/hellouhdm.cpp)
add_executable(hellodesign ${PROJECT_SOURCE_DIR}/src/hellodesign.cpp)
add_executable(roundtrip ${PROJECT_SOURCE_DIR}/src/roundtrip.cpp)
add_executable(hellosureworld ${PROJECT_SOURCE_DIR}/src/hellosureworld.cpp)
add_executable(hellouhdm ${PROJECT_SOURCE_DIR}/src/hellouhdm.cpp)
add_executable(hellodesign ${PROJECT_SOURCE_DIR}/src/hellodesign.cpp)
add_executable(roundtrip ${PROJECT_SOURCE_DIR}/src/roundtrip.cpp)
endif()

if(MSVC OR WIN32)
Expand All @@ -554,10 +555,12 @@ if(MSVC OR WIN32)
# becaues of /IMPLIB option when linking the executable. Unfortunately, there is no documented
# way to disable the latter in CMake. So, moving the library to the bin directory (right next to the exe)
set_target_properties(surelog-bin PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin)
set_target_properties(hellouhdm PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin)
set_target_properties(hellodesign PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin)
set_target_properties(roundtrip PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin)
set_target_properties(hellosureworld PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin)
if (NOT QUICK_COMP)
set_target_properties(hellouhdm PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin)
set_target_properties(hellodesign PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin)
set_target_properties(roundtrip PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin)
set_target_properties(hellosureworld PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin)
endif()
endif()

target_link_libraries(surelog-bin PUBLIC surelog)
Expand Down Expand Up @@ -743,8 +746,8 @@ add_custom_command(
WORKING_DIRECTORY "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")

if (NOT QUICK_COMP)
add_dependencies(hellosureworld PrecompileOVM)
add_dependencies(hellosureworld PrecompileUVM)
add_dependencies(hellosureworld PrecompileOVM)
add_dependencies(hellosureworld PrecompileUVM)
endif()

include(GNUInstallDirs)
Expand All @@ -753,10 +756,12 @@ include(GNUInstallDirs)
if (QUICK_COMP)
install(
TARGETS surelog-bin
EXPORT Surelog
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
else()
install(
TARGETS surelog-bin roundtrip
EXPORT Surelog
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()

Expand Down Expand Up @@ -940,32 +945,36 @@ if (WIN32)
endif()
endif()

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
configure_package_config_file(
${CMAKE_CURRENT_SOURCE_DIR}/cmake/configs/Config.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/SurelogConfig.cmake"
${CMAKE_CURRENT_SOURCE_DIR}/cmake/configs/SurelogConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/SurelogConfig.cmake
INSTALL_DESTINATION cmake
NO_SET_AND_CHECK_MACRO
NO_CHECK_REQUIRED_COMPONENTS_MACRO)
)
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/SurelogConfigVersion.cmake
VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}"
COMPATIBILITY SameMajorVersion
)

configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/cmake/configs/Surelog.pc.in
"${CMAKE_CURRENT_BINARY_DIR}/Surelog.pc"
@ONLY)

# install the configuration file
install(EXPORT Surelog
FILE SurelogTargets.cmake
NAMESPACE surelog::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Surelog
)
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/SurelogConfig.cmake
DESTINATION lib/cmake)
FILES ${CMAKE_CURRENT_BINARY_DIR}/SurelogConfig.cmake ${CMAKE_CURRENT_BINARY_DIR}/SurelogConfigVersion.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Surelog
)

# install the configuration file
install(
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ install-shared: release-shared
cmake --install build

test_install:
cmake -DCMAKE_BUILD_TYPE=Release -DINSTALL_DIR=$(PREFIX) -S tests/TestInstall -B tests/TestInstall/build
cmake -DCMAKE_BUILD_TYPE=Release -DINSTALL_DIR=$(PREFIX) -DCMAKE_PREFIX_PATH=$(PREFIX) $(ADDITIONAL_CMAKE_OPTIONS) -S tests/TestInstall -B tests/TestInstall/build
cmake --build tests/TestInstall/build -j $(CPU_CORES)

# Using pkg-config. Its search-path might be set in different ways. Set both.
Expand Down
3 changes: 0 additions & 3 deletions cmake/configs/Config.cmake.in

This file was deleted.

12 changes: 12 additions & 0 deletions cmake/configs/SurelogConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
set(SURELOG_VERSION "@PROJECT_VERSION_MAJOR@.@PROJECT_VERSION_MINOR@")

@PACKAGE_INIT@

include(${CMAKE_CURRENT_LIST_DIR}/SurelogTargets.cmake)

set_and_check(SURELOG_BIN_DIR @CMAKE_INSTALL_FULL_BINDIR@)
set_and_check(SURELOG_INCLUDE_DIR @CMAKE_INSTALL_FULL_INCLUDEDIR@)
set_and_check(SURELOG_INCLUDE_DIRS @CMAKE_INSTALL_FULL_INCLUDEDIR@)
set_and_check(SURELOG_LIB_DIR @CMAKE_INSTALL_FULL_LIBDIR@/surelog)

check_required_components(Surelog)
26 changes: 19 additions & 7 deletions tests/TestInstall/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,25 @@ set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/../../cmake/modules" ${CMAKE_MODULE_PATH})
cmake_path(CONVERT "${INSTALL_DIR}" TO_CMAKE_PATH_LIST INSTALL_DIR)
list(APPEND CMAKE_MODULE_PATH "${INSTALL_DIR}/lib/cmake/")
list(APPEND CMAKE_MODULE_PATH "${INSTALL_DIR}/lib/cmake/UHDM")
list(APPEND CMAKE_MODULE_PATH "${INSTALL_DIR}/lib/cmake/Surelog")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/../../cmake/modules")

# Dependencies
find_package(Surelog REQUIRED)
if(SURELOG_USE_HOST_FLATBUFFERS)
find_package(Flatbuffers REQUIRED)
set(FLATBUFFERS_LIBRARY flatbuffers::flatbuffers)
else()
set(FLATBUFFERS_LIBRARY flatbuffers)
endif()

set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
find_package(Threads REQUIRED)

if(SURELOG_USE_HOST_ANTLR)
find_package(ANTLR REQUIRED)
else()
Expand All @@ -40,9 +49,11 @@ endif()
if(SURELOG_USE_HOST_UHDM)
find_package(UHDM REQUIRED)
find_package(CapnProto)
set(UHDM_LIBRARY uhdm::uhdm)
set(CAPNPROTO_LIBRARY CapnProto::capnp)
else()
set(UHDM_LIBRARY uhdm)
set(UHDM_LIB_DIR "${INSTALL_DIR}/lib/uhdm" "${INSTALL_DIR}/lib64/uhdm")
set(CAPNPROTO_LIBRARY capnp kj)
endif()

Expand Down Expand Up @@ -82,19 +93,20 @@ endif()

add_executable(test_hellosureworld ${PROJECT_SOURCE_DIR}/../../src/hellosureworld.cpp)
target_include_directories(test_hellosureworld PRIVATE
${INSTALL_DIR}/include/Surelog
${INSTALL_DIR}/include
${SURELOG_INCLUDE_DIRS}
${UHDM_INCLUDE_DIRS}
${Python3_INCLUDE_DIRS}
)

target_link_directories(test_hellosureworld
PRIVATE ${INSTALL_DIR}/lib
PRIVATE ${INSTALL_DIR}/lib/surelog
PRIVATE ${INSTALL_DIR}/lib/uhdm
PRIVATE ${SURELOG_LIB_DIR}
PRIVATE ${UHDM_LIB_DIR}
)

if (SURELOG_WITH_PYTHON)
target_link_libraries(test_hellosureworld
surelog
surelog::surelog
${ANTLR_LIBRARY}
${FLATBUFFERS_LIBRARY}
${UHDM_LIBRARY}
Expand All @@ -104,7 +116,7 @@ if (SURELOG_WITH_PYTHON)
)
else()
target_link_libraries(test_hellosureworld
surelog
surelog::surelog
${ANTLR_LIBRARY}
${FLATBUFFERS_LIBRARY}
${UHDM_LIBRARY}
Expand Down

0 comments on commit 9d9430e

Please sign in to comment.