Skip to content

Commit 0c9bb82

Browse files
committed
fix: dev: cleanup googletest bits for consistent paths to gtest libs
* use includes from source dir when using VENDOR_GTEST * be sure and link against both gtest libs with either option Signed-off-by: Stephen L Arnold <sarnold@vctlabs.com>
1 parent 4eb365c commit 0c9bb82

File tree

6 files changed

+22
-23
lines changed

6 files changed

+22
-23
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ jobs:
5555
os: ubuntu-22.04
5656
compiler: clang
5757
version: "14"
58-
toxcmd: base
58+
toxcmd: clang
5959

6060
- name: macOS-13-gcc
6161
os: macOS-13
@@ -115,7 +115,7 @@ jobs:
115115
tox -e ${{ matrix.toxcmd }}
116116
117117
- uses: actions/upload-artifact@v4
118-
if: matrix.name == 'ubuntu-20.04-clang'
118+
if: matrix.name == 'ubuntu-22.04-clang-14'
119119
with:
120120
name: src_coverage_data
121121
path: |

.github/workflows/conda-dev.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,19 @@ jobs:
2222
- os: 'ubuntu-22.04'
2323
generator: 'Ninja'
2424
build_type: 'Release'
25+
extra_args: '-DBUILD_SHARED_LIBS=ON -DABC_USE_SONAME=ON'
2526
- os: 'ubuntu-24.04'
2627
generator: 'Ninja'
2728
build_type: 'RelWithDebInfo'
29+
extra_args: '-DBUILD_SHARED_LIBS=ON -DABC_USE_SONAME=ON'
2830
- os: 'macOS-14'
2931
generator: 'Ninja'
3032
build_type: 'Debug'
33+
extra_args: '-DBUILD_SHARED_LIBS=ON -DABC_USE_SONAME=ON'
3134
- os: 'windows-2019'
3235
generator: 'Ninja'
33-
build_type: 'Release'
34-
extra_args: '-DABC_USE_NO_PTHREADS=ON -DABC_USE_NO_READLINE=ON'
36+
build_type: 'Debug'
37+
extra_args: '-DBUILD_SHARED_LIBS=OFF -DABC_USE_NO_READLINE=ON'
3538
env:
3639
OS: ${{ matrix.os }}
3740
PY_VER: ${{ matrix.python-version }}
@@ -87,7 +90,7 @@ jobs:
8790
--build-generator "${{ matrix.generator }}" \
8891
--build-and-test . build \
8992
--build-options ${CMAKE_ARGS} ${{ matrix.extra_args }} \
90-
-DBUILD_SHARED_LIBS=ON -DABC_USE_SONAME=ON -DCMAKE_PREFIX_PATH="$CONDA_PREFIX" \
93+
-DCMAKE_PREFIX_PATH="$CONDA_PREFIX" \
9194
--test-command ctest -V \
9295
--build-config "${{ matrix.build_type }}" \
9396
--rerun-failed --output-on-failure

CMakeLists.txt

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ set(LIBRARY_SOVERSION 1)
1717

1818
project(
1919
abc
20-
LANGUAGES C CXX
20+
LANGUAGES CXX C
2121
VERSION ${SCM_VERSION_INFO}
2222
)
2323

@@ -432,10 +432,8 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
432432
endif()
433433
endif()
434434

435-
436435
if(VENDOR_GTEST)
437436
include(FetchContent)
438-
option(BUILD_GMOCK OFF)
439437
option(INSTALL_GTEST OFF)
440438
FetchContent_Declare(
441439
googletest
@@ -444,21 +442,22 @@ if(VENDOR_GTEST)
444442
#GIT_REPOSITORY https://github.com/google/googletest.git
445443
#GIT_TAG v1.14.0
446444
)
447-
set(gtest_force_shared_crt
448-
ON
449-
CACHE BOOL "" FORCE
450-
)
445+
set(gtest_force_shared_crt ON CACHE BOOL "Always use msvcrt.dll" FORCE)
446+
FetchContent_MakeAvailable(googletest)
447+
include_directories(${gtest_SOURCE_DIR}/include)
448+
set(GTEST_LINK_LIBRARIES GTest::gtest GTest::gtest_main)
451449
endif()
452450

453451
if(BUILD_TESTING)
454452
if(NOT VENDOR_GTEST)
455-
find_package(GTest REQUIRED)
456-
else()
457-
FetchContent_MakeAvailable(googletest)
453+
find_package(GTest 1.14 REQUIRED)
454+
include_directories(${GTEST_INCLUDE_DIRS})
455+
set(GTEST_LINK_LIBRARIES ${GTEST_BOTH_LIBRARIES})
458456
endif()
457+
message(STATUS "GTest libraries: ${GTEST_LINK_LIBRARIES}")
458+
459459
message(STATUS "test discovery enabled")
460460
include(GoogleTest)
461-
set(GTEST_LIBS gtest_main gtest "${CMAKE_THREAD_LIBS_INIT}")
462461

463462
set(test_SRCS src/demo.c)
464463
if(ABC_USE_NAMESPACE)
@@ -467,7 +466,7 @@ if(BUILD_TESTING)
467466
add_executable(base_test ${test_SRCS})
468467
target_compile_options(base_test PUBLIC ${GTEST_CFLAGS})
469468
target_link_libraries(
470-
base_test PUBLIC libabc ${GTEST_LIBS}
469+
base_test PUBLIC libabc ${GTEST_LINK_LIBRARIES}
471470
)
472471

473472
enable_testing()

test/gia/CMakeLists.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,12 @@ endif()
44

55
add_executable(gia_test gia_test.cc)
66

7-
target_include_directories(gia_test PUBLIC ${GTEST_INCLUDE_DIRS})
87
target_compile_options(gia_test PUBLIC ${GTEST_CFLAGS})
98
target_link_libraries(gia_test PUBLIC
109
libabc
11-
${GTEST_LIBS}
10+
${GTEST_LINK_LIBRARIES}
1211
)
1312

1413
gtest_discover_tests(gia_test
15-
# the traling directory below is a workaround for generators that append
16-
# an extra directory name (build type) such as VS on windows
1714
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
1815
)

test/gia/gia_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "gtest/gtest.h"
1+
#include <gtest/gtest.h>
22

33
#include "aig/gia/gia.h"
44

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ commands =
8686
clang: lcov_cobertura {toxinidir}/build/coverage/lcov.info --base-dir {toxinidir}/src --output coverage.xml
8787
{base,libs}: cmake --build . --target install
8888
{base,libs}: bash -c 'find $PREFIX/ -type f -name \*abc\* -o -name demo | xargs ls -lh'
89-
ctest: ctest -j {env:CPUS} --build-generator {posargs:"Ninja"} --build-and-test . build --build-options -DABC_USE_NAMESPACE={env:ABC_USE_NAMESPACE} -DABC_SKIP_EXE=ON -DCMAKE_BUILD_TYPE={env:BUILD_TYPE} --test-command ctest --rerun-failed --output-on-failure -V
89+
ctest: ctest -j {env:CPUS} --build-generator {posargs:"Ninja"} --build-and-test . build --build-options -DABC_USE_NAMESPACE={env:ABC_USE_NAMESPACE} -DABC_SKIP_EXE=ON -DCMAKE_BUILD_TYPE={env:BUILD_TYPE} --test-command ctest -C {env:BUILD_TYPE} --rerun-failed --output-on-failure -V
9090
ctestwin: ctest --build-generator {posargs:"Visual Studio 16 2019"} --build-and-test . build --build-options -DVENDOR_GTEST=ON -DBUILD_SHARED_LIBS=ON -DABC_USE_NO_PTHREADS=ON -DABC_USE_NO_READLINE=ON -DCMAKE_BUILD_TYPE={env:BUILD_TYPE} --test-command ctest -C {env:BUILD_TYPE} --rerun-failed --output-on-failure -V
9191
ctest: bash -c 'ls -lh build/*abc* || true'
9292
lint: bash -c 'cpplint --output=gsed {toxinidir}/src/base/main/* {toxinidir}/lib/*'

0 commit comments

Comments
 (0)