1

My library is organised like so :

lib/
├── src/
│   ├── code..
├── tests/
│   ├── code..
│   └── CMakeLists.txt
│
└─ CMakeLists.txt

The outer cmakelists file calls the inner CMakeLists through add_subdirectory(./tests)

cmake_minimum_required(VERSION 3.16.0)
project(aoi_server VERSION 0.1.0)
set(CMAKE_CXX_STANDARD 17)

enable_testing()

# Download and unpack googletest at configure time
configure_file(CMakeLists.txt.in googletest-download/CMakeLists.txt)
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
  RESULT_VARIABLE result
  WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download )
if(result)
  message(FATAL_ERROR "CMake step for googletest failed: ${result}")
endif()
execute_process(COMMAND ${CMAKE_COMMAND} --build .
  RESULT_VARIABLE result
  WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download )
if(result)
  message(FATAL_ERROR "Build step for googletest failed: ${result}")
endif()

# Prevent overriding the parent project's compiler/linker
# settings on Windows
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)

# Add googletest directly to our build. This defines
# the gtest and gtest_main targets.
add_subdirectory(${CMAKE_CURRENT_BINARY_DIR}/googletest-src
                 ${CMAKE_CURRENT_BINARY_DIR}/googletest-build
                 EXCLUDE_FROM_ALL)

set(LIBRARY_OUTPUT_PATH "${CMAKE_BINARY_DIR}")
set(EXECUTABLE_OUTPUT_PATH "${CMAKE_BINARY_DIR}")

find_package(ZeroMQ CONFIG REQUIRED)
find_package(nlohmann_json CONFIG REQUIRED)
find_package(nanodbc CONFIG REQUIRED)
find_package(OpenCV REQUIRED)
find_package(Boost REQUIRED COMPONENTS thread)
include_directories( ${OpenCV_INCLUDE_DIRS} )
add_library(aoi_server SHARED src/core.cpp
                              src/backend.cpp
                              src/backend_sl_hb_listener.cpp
                              src/backend_message_handlers.cpp  
                              src/handlers/event_dispatcher.cpp
                              src/slaves/slave.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE libzmq libzmq-static)
target_link_libraries(${PROJECT_NAME} PRIVATE nlohmann_json 
                            nlohmann_json::nlohmann_json)
target_link_libraries(${PROJECT_NAME} PRIVATE nanodbc)
target_link_libraries(${PROJECT_NAME} PUBLIC ${OpenCV_LIBRARIES})
target_link_directories(${PROJECT_NAME} PRIVATE ${Boost_LIBRARY_DIRS})
target_link_libraries(${PROJECT_NAME} PRIVATE ${Boost_LIBRARIES})
target_compile_definitions(${PROJECT_NAME} PRIVATE SERVER_LIB_EXPORT)

# set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /DEBUG:FULL")
message("DEBUG FLAGS : ${CMAKE_CXX_FLAGS_DEBUG}")
message("RELEASE FLAGS : ${CMAKE_CXX_FLAGS_RELEASE}")

# Defining default includes
target_precompile_headers(${PROJECT_NAME}
    PRIVATE
    <string>
    <set>
    <memory>
    <iostream>
    <future>
    <thread>
    <chrono>
    <cassert>
    <ctime>
    <filesystem>
    <variant>
    <map>
    <ctime>
)

set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)

message("=== Tests ===")
# Adding tests
add_subdirectory(./tests)

The inner cmake lists :

cmake_minimum_required(VERSION 3.8)

include(GoogleTest)
set(This tests)

set(Sources basic_tests.cpp
            test_arrival.cpp)

add_executable(${This} ${Sources})
target_precompile_headers(${This} REUSE_FROM aoi_server)
target_link_libraries(${This} PRIVATE 
        gtest_main
        libzmq libzmq-static
        nlohmann_json nlohmann_json::nlohmann_json
        aoi_server)

gtest_discover_tests(${This})

My issue was that I couldn't debug my tests, because the debugger couldn't load symbols for my dll. Did a bit of digging, and discovered Chkmatch, which told me that my dll and pdb had two different signatures. Did more digging, found out that when I comment add_subdirectory(./tests) out, I get matched pdbs, and when I add_subdirectory(), I don't.

Without add_subdirectory() :

> .\ChkMatch.exe -c D:\Projects\Server\NewServer\AOI_server\build\Debug\aoi_server.dll D:\Projects\Server\NewServer\AOI_server\build\Debug\aoi_server.pdb
ChkMatch - version 1.0
Copyright (C) 2004 Oleg Starodumov
http://www.debuginfo.com/


Executable: D:\Projects\Server\NewServer\AOI_server\build\Debug\aoi_server.dll
Debug info file: D:\Projects\Server\NewServer\AOI_server\build\Debug\aoi_server.pdb

Executable:
TimeDateStamp: 5f4c78eb
Debug info: 2 ( CodeView )
TimeStamp: 5f4c78eb  Characteristics: 0  MajorVer: 0  MinorVer: 0
Size: 91  RVA: 001468b0  FileOffset: 001458b0
CodeView format: RSDS
Signature: {8a94da71-3eae-47fd-a335-dc71367a63f8}  Age: 1
PdbFile: D:\Projects\Server\NewServer\AOI_server\build\Debug\aoi_server.pdb
Debug info: 12 ( Unknown )
TimeStamp: 5f4c78eb  Characteristics: 0  MajorVer: 0  MinorVer: 0
Size: 20  RVA: 0014690c  FileOffset: 0014590c

Debug information file:
Format: PDB 7.00
Signature: {8a94da71-3eae-47fd-a335-dc71367a63f8}  Age: 1

Result: Matched

And after adding in add_subdirectory():

ChkMatch - version 1.0
Copyright (C) 2004 Oleg Starodumov
http://www.debuginfo.com/


Executable: D:\Projects\Server\NewServer\AOI_server\build\Debug\aoi_server.dll
Debug info file: D:\Projects\Server\NewServer\AOI_server\build\Debug\aoi_server.pdb

Executable:
TimeDateStamp: 5f4c7894
Debug info: 2 ( CodeView )
TimeStamp: 5f4c7894  Characteristics: 0  MajorVer: 0  MinorVer: 0
Size: 91  RVA: 001468b0  FileOffset: 001458b0
CodeView format: RSDS
Signature: {323f027f-cea9-425d-a31d-0e073073d922}  Age: 1
PdbFile: D:\Projects\Server\NewServer\AOI_server\build\Debug\aoi_server.pdb
Debug info: 12 ( Unknown )
TimeStamp: 5f4c7894  Characteristics: 0  MajorVer: 0  MinorVer: 0
Size: 20  RVA: 0014690c  FileOffset: 0014590c

Debug information file:
Format: PDB 7.00
Signature: {92b2ec3f-c622-40e7-a24b-0620f8fd9f42}  Age: 9

Result: Unmatched (reason: Signature mismatch)

EDIT : With verbose build on:

Without add_subdirectory()

[main] Building folder: AOI_server clean
[build] Starting build
[proc] Executing command: "C:\Program Files\CMake\bin\cmake.EXE" --build d:/Projects/Server/NewServer/AOI_server/build --config Debug --target clean --
[build] Microsoft (R) Build Engine version 16.5.0+d4cbfca49 for .NET Framework
[build] Copyright (C) Microsoft Corporation. All rights reserved.
[build] 
[build] Build finished with exit code 0
[main] Building folder: AOI_server 
[build] Starting build
[proc] Executing command: "C:\Program Files\CMake\bin\cmake.EXE" --build d:/Projects/Server/NewServer/AOI_server/build --config Debug --target ALL_BUILD -- /maxcpucount:10
[build] Microsoft (R) Build Engine version 16.5.0+d4cbfca49 for .NET Framework
[build] Copyright (C) Microsoft Corporation. All rights reserved.
[build] 
[build]   Checking Build System
[build]   Building Custom Rule D:/Projects/Server/NewServer/AOI_server/CMakeLists.txt
[build]   Microsoft (R) C/C++ Optimizing Compiler Version 19.25.28614 for x64
[build]   cmake_pch.cxx
[build]   Copyright (C) Microsoft Corporation.  All rights reserved.
[build]   cl /c /I"D:\Libs\vcpkg\installed\x64-windows\include" /I"D:\Libs\vcpkg\installed\x64-windows\include\nanodbc" /Zi /W1 /WX- /diagnostics:column /Od /Ob0 /D WIN32 /D _WINDOWS /D SERVER_LIB_EXPORT /D "CMAKE_INTDIR=\"Debug\"" /D aoi_server_EXPORTS /D _WINDLL /D _MBCS /Gm- /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /GR /std:c++17 /Yc"D:/Projects/Server/NewServer/AOI_server/build/CMakeFiles/aoi_server.dir/cmake_pch.hxx" /Fp"D:/Projects/Server/NewServer/AOI_server/build/aoi_server.dir/Debug/cmake_pch.pch" /Fo"aoi_server.dir\Debug\\" /Fd"aoi_server.dir\Debug\vc142.pdb" /Gd /TP /FID:/Projects/Server/NewServer/AOI_server/build/CMakeFiles/aoi_server.dir/cmake_pch.hxx /errorReport:queue D:\Projects\Server\NewServer\AOI_server\build\CMakeFiles\aoi_server.dir\cmake_pch.cxx
[build]   Microsoft (R) C/C++ Optimizing Compiler Version 19.25.28614 for x64
[build]   core.cpp
[build]   Copyright (C) Microsoft Corporation.  All rights reserved.
[build]   cl /c /I"D:\Libs\vcpkg\installed\x64-windows\include" /I"D:\Libs\vcpkg\installed\x64-windows\include\nanodbc" /Zi /W1 /WX- /diagnostics:column /Od /Ob0 /D WIN32 /D _WINDOWS /D SERVER_LIB_EXPORT /D "CMAKE_INTDIR=\"Debug\"" /D aoi_server_EXPORTS /D _WINDLL /D _MBCS /Gm- /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /GR /std:c++17 /Yu"D:/Projects/Server/NewServer/AOI_server/build/CMakeFiles/aoi_server.dir/cmake_pch.hxx" /Fp"D:/Projects/Server/NewServer/AOI_server/build/aoi_server.dir/Debug/cmake_pch.pch" /Fo"aoi_server.dir\Debug\\" /Fd"aoi_server.dir\Debug\vc142.pdb" /Gd /TP /FID:/Projects/Server/NewServer/AOI_server/build/CMakeFiles/aoi_server.dir/cmake_pch.hxx /errorReport:queue D:\Projects\Server\NewServer\AOI_server\src\core.cpp D:\Projects\Server\NewServer\AOI_server\src\backend.cpp D:\Projects\Server\NewServer\AOI_server\src\backend_sl_hb_listener.cpp D:\Projects\Server\NewServer\AOI_server\src\backend_message_handlers.cpp D:\Projects\Server\NewServer\AOI_server\src\handlers\event_dispatcher.cpp D:\Projects\Server\NewServer\AOI_server\src\slaves\slave.cpp D:\Projects\Server\NewServer\AOI_server\src\network_management\network_manager.cpp
[build]   backend.cpp
[build] D:\Projects\Server\NewServer\AOI_server\src\backend.cpp(61,11): warning C4834: discarding return value of function with 'nodiscard' attribute [D:\Projects\Server\NewServer\AOI_server\build\aoi_server.vcxproj]
[build]   backend_sl_hb_listener.cpp
[build]   backend_message_handlers.cpp
[build]   event_dispatcher.cpp
[build] D:\Projects\Server\NewServer\AOI_server\src\handlers\heartbeat_handler.h(103,9): warning C4477: 'printf' : format string '%d' requires an argument of type 'int', but variadic argument 1 has type 'unsigned __int64' [D:\Projects\Server\NewServer\AOI_server\build\aoi_server.vcxproj]
[build] D:\Projects\Server\NewServer\AOI_server\src\handlers\heartbeat_handler.h(103,9): message : consider using '%zd' in the format string [D:\Projects\Server\NewServer\AOI_server\build\aoi_server.vcxproj]
[build]   slave.cpp
[build] D:\Projects\Server\NewServer\AOI_server\src\slaves\slave.cpp(46,11): warning C4473: 'printf' : not enough arguments passed for format string [D:\Projects\Server\NewServer\AOI_server\build\aoi_server.vcxproj]
[build] D:\Projects\Server\NewServer\AOI_server\src\slaves\slave.cpp(46,11): message : placeholders and their parameters expect 1 variadic arguments, but 0 were provided [D:\Projects\Server\NewServer\AOI_server\build\aoi_server.vcxproj]
[build] D:\Projects\Server\NewServer\AOI_server\src\slaves\slave.cpp(46,11): message : the missing variadic argument 1 is required by format string '%s' [D:\Projects\Server\NewServer\AOI_server\build\aoi_server.vcxproj]
[build]   network_manager.cpp
[build]   Generating Code...
[build]      Creating library D:/Projects/Server/NewServer/AOI_server/build/Debug/aoi_server.lib and object D:/Projects/Server/NewServer/AOI_server/build/Debug/aoi_server.exp
[build]   aoi_server.vcxproj -> D:\Projects\Server\NewServer\AOI_server\build\Debug\aoi_server.dll
[build]   Building Custom Rule D:/Projects/Server/NewServer/AOI_server/CMakeLists.txt
[build] Build finished with exit code 0

With add_subdirectory()

[main] Building folder: AOI_server clean
[build] Starting build
[proc] Executing command: "C:\Program Files\CMake\bin\cmake.EXE" --build d:/Projects/Server/NewServer/AOI_server/build --config Debug --target clean --
[build] Microsoft (R) Build Engine version 16.5.0+d4cbfca49 for .NET Framework
[build] Copyright (C) Microsoft Corporation. All rights reserved.
[build] 
[build] Build finished with exit code 0
[main] Building folder: AOI_server 
[build] Starting build
[proc] Executing command: "C:\Program Files\CMake\bin\cmake.EXE" --build d:/Projects/Server/NewServer/AOI_server/build --config Debug --target tests -- /maxcpucount:10
[build] Microsoft (R) Build Engine version 16.5.0+d4cbfca49 for .NET Framework
[build] Copyright (C) Microsoft Corporation. All rights reserved.
[build] 
[build]   Checking Build System
[build]   Building Custom Rule D:/Projects/Server/NewServer/AOI_server/CMakeLists.txt
[build]   Microsoft (R) C/C++ Optimizing Compiler Version 19.25.28614 for x64
[build]   cmake_pch.cxx
[build]   Copyright (C) Microsoft Corporation.  All rights reserved.
[build]   cl /c /I"D:\Libs\vcpkg\installed\x64-windows\include" /I"D:\Libs\vcpkg\installed\x64-windows\include\nanodbc" /Zi /W1 /WX- /diagnostics:column /Od /Ob0 /D WIN32 /D _WINDOWS /D SERVER_LIB_EXPORT /D "CMAKE_INTDIR=\"Debug\"" /D aoi_server_EXPORTS /D _WINDLL /D _MBCS /Gm- /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /GR /std:c++17 /Yc"D:/Projects/Server/NewServer/AOI_server/build/CMakeFiles/aoi_server.dir/cmake_pch.hxx" /Fp"D:/Projects/Server/NewServer/AOI_server/build/aoi_server.dir/Debug/cmake_pch.pch" /Fo"aoi_server.dir\Debug\\" /Fd"D:\Projects\Server\NewServer\AOI_server\build\aoi_server.dir\Debug\aoi_server.pdb" /Gd /TP /FID:/Projects/Server/NewServer/AOI_server/build/CMakeFiles/aoi_server.dir/cmake_pch.hxx /errorReport:queue D:\Projects\Server\NewServer\AOI_server\build\CMakeFiles\aoi_server.dir\cmake_pch.cxx
[build]   Building Custom Rule D:/Projects/Server/NewServer/AOI_server/build/googletest-src/googletest/CMakeLists.txt
[build]   gtest-all.cc
[build]   Microsoft (R) C/C++ Optimizing Compiler Version 19.25.28614 for x64
[build]   core.cpp
[build]   Copyright (C) Microsoft Corporation.  All rights reserved.
[build]   cl /c /I"D:\Libs\vcpkg\installed\x64-windows\include" /I"D:\Libs\vcpkg\installed\x64-windows\include\nanodbc" /Zi /W1 /WX- /diagnostics:column /Od /Ob0 /D WIN32 /D _WINDOWS /D SERVER_LIB_EXPORT /D "CMAKE_INTDIR=\"Debug\"" /D aoi_server_EXPORTS /D _WINDLL /D _MBCS /Gm- /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /GR /std:c++17 /Yu"D:/Projects/Server/NewServer/AOI_server/build/CMakeFiles/aoi_server.dir/cmake_pch.hxx" /Fp"D:/Projects/Server/NewServer/AOI_server/build/aoi_server.dir/Debug/cmake_pch.pch" /Fo"aoi_server.dir\Debug\\" /Fd"D:\Projects\Server\NewServer\AOI_server\build\aoi_server.dir\Debug\aoi_server.pdb" /Gd /TP /FID:/Projects/Server/NewServer/AOI_server/build/CMakeFiles/aoi_server.dir/cmake_pch.hxx /errorReport:queue D:\Projects\Server\NewServer\AOI_server\src\core.cpp D:\Projects\Server\NewServer\AOI_server\src\backend.cpp D:\Projects\Server\NewServer\AOI_server\src\backend_sl_hb_listener.cpp D:\Projects\Server\NewServer\AOI_server\src\backend_message_handlers.cpp D:\Projects\Server\NewServer\AOI_server\src\handlers\event_dispatcher.cpp D:\Projects\Server\NewServer\AOI_server\src\slaves\slave.cpp D:\Projects\Server\NewServer\AOI_server\src\network_management\network_manager.cpp
[build]   gtest.vcxproj -> D:\Projects\Server\NewServer\AOI_server\build\lib\Debug\gtestd.lib
[build]   Building Custom Rule D:/Projects/Server/NewServer/AOI_server/build/googletest-src/googletest/CMakeLists.txt
[build]   backend.cpp
[build]   gtest_main.cc
[build] D:\Projects\Server\NewServer\AOI_server\src\backend.cpp(61,11): warning C4834: discarding return value of function with 'nodiscard' attribute [D:\Projects\Server\NewServer\AOI_server\build\aoi_server.vcxproj]
[build]   gtest_main.vcxproj -> D:\Projects\Server\NewServer\AOI_server\build\lib\Debug\gtest_maind.lib
[build]   backend_sl_hb_listener.cpp
[build]   backend_message_handlers.cpp
[build]   event_dispatcher.cpp
[build] D:\Projects\Server\NewServer\AOI_server\src\handlers\heartbeat_handler.h(103,9): warning C4477: 'printf' : format string '%d' requires an argument of type 'int', but variadic argument 1 has type 'unsigned __int64' [D:\Projects\Server\NewServer\AOI_server\build\aoi_server.vcxproj]
[build] D:\Projects\Server\NewServer\AOI_server\src\handlers\heartbeat_handler.h(103,9): message : consider using '%zd' in the format string [D:\Projects\Server\NewServer\AOI_server\build\aoi_server.vcxproj]
[build]   slave.cpp
[build] D:\Projects\Server\NewServer\AOI_server\src\slaves\slave.cpp(46,11): warning C4473: 'printf' : not enough arguments passed for format string [D:\Projects\Server\NewServer\AOI_server\build\aoi_server.vcxproj]
[build] D:\Projects\Server\NewServer\AOI_server\src\slaves\slave.cpp(46,11): message : placeholders and their parameters expect 1 variadic arguments, but 0 were provided [D:\Projects\Server\NewServer\AOI_server\build\aoi_server.vcxproj]
[build] D:\Projects\Server\NewServer\AOI_server\src\slaves\slave.cpp(46,11): message : the missing variadic argument 1 is required by format string '%s' [D:\Projects\Server\NewServer\AOI_server\build\aoi_server.vcxproj]
[build]   network_manager.cpp
[build]   Generating Code...
[build]      Creating library D:/Projects/Server/NewServer/AOI_server/build/Debug/aoi_server.lib and object D:/Projects/Server/NewServer/AOI_server/build/Debug/aoi_server.exp
[build]   aoi_server.vcxproj -> D:\Projects\Server\NewServer\AOI_server\build\Debug\aoi_server.dll
[build]   Building Custom Rule D:/Projects/Server/NewServer/AOI_server/tests/CMakeLists.txt
[build]   Microsoft (R) C/C++ Optimizing Compiler Version 19.25.28614 for x64
[build]   basic_tests.cpp
[build]   Copyright (C) Microsoft Corporation.  All rights reserved.
[build]   cl /c /I"D:\Libs\vcpkg\installed\x64-windows\include" /I"D:\Projects\Server\NewServer\AOI_server\build\googletest-src\googletest\include" /I"D:\Projects\Server\NewServer\AOI_server\build\googletest-src\googletest" /Zi /W1 /WX- /diagnostics:column /Od /Ob0 /D WIN32 /D _WINDOWS /D "CMAKE_INTDIR=\"Debug\"" /D _MBCS /Gm- /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /GR /std:c++17 /Yu"D:/Projects/Server/NewServer/AOI_server/build/CMakeFiles/aoi_server.dir/cmake_pch.hxx" /Fp"D:/Projects/Server/NewServer/AOI_server/build/aoi_server.dir/Debug/cmake_pch.pch" /Fo"tests.dir\Debug\\" /Fd"D:\Projects\Server\NewServer\AOI_server\build\tests\tests.dir\Debug\aoi_server.pdb" /Gd /TP /FID:/Projects/Server/NewServer/AOI_server/build/CMakeFiles/aoi_server.dir/cmake_pch.hxx /errorReport:queue D:\Projects\Server\NewServer\AOI_server\tests\basic_tests.cpp D:\Projects\Server\NewServer\AOI_server\tests\test_arrival.cpp
[build] D:\Projects\Server\NewServer\AOI_server\tests\basic_tests.cpp : warning C4651: '/DSERVER_LIB_EXPORT' specified for precompiled header but not for current compile [D:\Projects\Server\NewServer\AOI_server\build\tests\tests.vcxproj]
[build] D:\Projects\Server\NewServer\AOI_server\tests\basic_tests.cpp : warning C4651: '/Daoi_server_EXPORTS' specified for precompiled header but not for current compile [D:\Projects\Server\NewServer\AOI_server\build\tests\tests.vcxproj]
[build] D:\Projects\Server\NewServer\AOI_server\tests\basic_tests.cpp : warning C4651: '/D_WINDLL' specified for precompiled header but not for current compile [D:\Projects\Server\NewServer\AOI_server\build\tests\tests.vcxproj]
[build]   test_arrival.cpp
[build] D:\Projects\Server\NewServer\AOI_server\tests\test_arrival.cpp : warning C4651: '/DSERVER_LIB_EXPORT' specified for precompiled header but not for current compile [D:\Projects\Server\NewServer\AOI_server\build\tests\tests.vcxproj]
[build] D:\Projects\Server\NewServer\AOI_server\tests\test_arrival.cpp : warning C4651: '/Daoi_server_EXPORTS' specified for precompiled header but not for current compile [D:\Projects\Server\NewServer\AOI_server\build\tests\tests.vcxproj]
[build] D:\Projects\Server\NewServer\AOI_server\tests\test_arrival.cpp : warning C4651: '/D_WINDLL' specified for precompiled header but not for current compile [D:\Projects\Server\NewServer\AOI_server\build\tests\tests.vcxproj]
[build] D:\Projects\Server\NewServer\AOI_server\tests\test_arrival.cpp(167,9): warning C4477: 'printf' : format string '%d' requires an argument of type 'int', but variadic argument 1 has type 'const size_t' [D:\Projects\Server\NewServer\AOI_server\build\tests\tests.vcxproj]
[build] D:\Projects\Server\NewServer\AOI_server\tests\test_arrival.cpp(167,9): message : consider using '%zd' in the format string [D:\Projects\Server\NewServer\AOI_server\build\tests\tests.vcxproj]
[build]   Generating Code...
[build]      Creating library D:/Projects/Server/NewServer/AOI_server/build/Debug/tests.lib and object D:/Projects/Server/NewServer/AOI_server/build/Debug/tests.exp
[build]   tests.vcxproj -> D:\Projects\Server\NewServer\AOI_server\build\Debug\tests.exe
[build] Build finished with exit code 
Roy2511
  • 938
  • 1
  • 5
  • 22
  • Rather hard to judge, but this thing `set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)` could possibly make some mess, you sure you know all consequences of using this flag? As per [this](https://stackoverflow.com/questions/12540970/how-to-make-gtest-build-mdd-instead-of-mtd-by-default-using-cmake) question, I believe it might affect the output binaries. – Marek Piotrowski Aug 31 '20 at 10:41
  • @MarekPiotrowski not sure, it is supposed to stop gtest from overriding my compiler settings (as mentioned in the comments). It's also there in the [sample CMakeList](https://github.com/google/googletest/blob/master/googletest/README.md#incorporating-into-an-existing-cmake-project) – Roy2511 Sep 01 '20 at 02:27
  • Yeah I thought it might. Could you possibly [enable verbose build](https://bytefreaks.net/programming-2/make-building-with-cmake-verbose/amp) so we can see the compiler's output with and without /tests? – Marek Piotrowski Sep 01 '20 at 04:25
  • Added to the question. – Roy2511 Sep 01 '20 at 04:42
  • 1
    Hmm...in build with test there's a following when compiling all translation units: `/Fd"D:\Projects\Server\NewServer\AOI_server\build\aoi_server.dir\Debug\aoi_server.pdb"` while without tests `/Fd"aoi_server.dir\Debug\vc142.pdb"`. You sure that `make` cleans the PDBs as well? – Marek Piotrowski Sep 01 '20 at 04:53
  • Isn't it normal? tests.exe should link with aoi_server.pdb (for dll symbols); And aoi_server.dll itself gets its symbols from vc142.pdb? I'll delete the build folder and retry .. but I think it does, because the signature does change everytime I run the build, so presumably the pdb is regenerated. – Roy2511 Sep 01 '20 at 05:04
  • But the line I mentioned is not about linking pdbs, but rather emitting them. So, when building tests, PDB is emitted there: `/Fd"D:\Projects\Server\NewServer\AOI_server\build\aoi_server.dir\Debug\aoi_server.pdb"`, but when building without tests, same PDB, corresponding to your translation units, is emitted there: `/Fd"aoi_server.dir\Debug\vc142.pdb"`. You sure you're comparing correct PDBs using ChkMatch? – Marek Piotrowski Sep 01 '20 at 05:14
  • Another thing - why when you add subdirectory you specifically build `--target tests`, but without /tests subdirectory you build `--target ALL_BUILD`. I know that it might not really make any difference, but for a reliable comparison I'd build same targets in both cases (ie ALL) – Marek Piotrowski Sep 01 '20 at 05:16
  • @MarekPiotrowski, yeah I misunderstood what /Fd does. This is very obviously incorrect `/Fd"aoi_server.dir\Debug\vc142.pdb"`; that path does not exist... I tried to set up the pdb path directly using [COMPILE_PDB_NAME](https://cmake.org/cmake/help/v3.1/prop_tgt/COMPILE_PDB_NAME.html#prop_tgt:COMPILE_PDB_NAME) and even this change the path from `...\vc142.pdb`. Pretty weird – Roy2511 Sep 02 '20 at 03:05
  • As for the second comment, it's working as intended. When I build with tests, I target tests so that I can build both the dll and the tests in 1 shot. But when I do not configure tests, I default back to ALL_BUILD; Just now I tried building just the dll, but it still emits vc142.pdb. – Roy2511 Sep 02 '20 at 03:11
  • Also, `tests.exe` matches with `tests.pdb`, but `aoi_server.dll` doesn't match with `aoi_server.pdb`. Maybe the tests executable overwrites the dll pdb with some more symbols? But why? – Roy2511 Sep 02 '20 at 03:49
  • As per [this](https://learn.microsoft.com/en-us/visualstudio/debugger/specify-symbol-dot-pdb-and-source-files-in-the-visual-studio-debugger?view=vs-2019#cc-options) `/Fd"aoi_server.dir\Debug\vc142.pdb"` seems to be default... – Marek Piotrowski Sep 02 '20 at 06:20
  • Okay, so it's kinda strange that there's no /debug [switch anywhere](https://learn.microsoft.com/en-US/cpp/build/reference/debug-generate-debug-info?view=vs-2019)...but linker output isn't verbose, apparently (we can't see how the dll is linked). Maybe do not generate pdbs at all - have you tried [other debug symbols generation method](https://learn.microsoft.com/en-us/cpp/build/reference/z7-zi-zi-debug-information-format?view=vs-2019). Probably it could be configured via cmake. – Marek Piotrowski Sep 02 '20 at 06:47

0 Answers0