Skip to content

Commit f824df2

Browse files
committed
Fix build type, support offline builds
- Quote -DCMAKE_BUILD_TYPE arg in build script to fix PowerShell parameter parsing (was passing literal '\' instead of the resolved value, resulting in unoptimized 4MB .so on Linux) - Allow pre-installed Firebird headers via -DFIREBIRD_INCLUDE_DIR=path, skipping FetchContent download (enables air-gapped builds) - Use find_package(GTest) first, fall back to FetchContent only when not found (enables builds without internet access)
1 parent b1ec045 commit f824df2

File tree

3 files changed

+42
-17
lines changed

3 files changed

+42
-17
lines changed

cmake/FetchFirebirdHeaders.cmake

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,25 @@
88
# (ibase.h, iberror.h) and the firebird/ sub-tree with the modern API
99
# (Interface.h, IdlFbInterfaces.h, Message.h, impl/, …).
1010
#
11+
# To use pre-installed headers (e.g. on an air-gapped host), set
12+
# FIREBIRD_INCLUDE_DIR on the command line:
13+
# cmake -B build -DFIREBIRD_INCLUDE_DIR=/path/to/firebird/include
14+
#
1115
# Usage:
1216
# include(cmake/FetchFirebirdHeaders.cmake)
1317
# target_include_directories(MyTarget PRIVATE ${FIREBIRD_INCLUDE_DIR})
1418

19+
# If the caller already provided FIREBIRD_INCLUDE_DIR, validate and skip fetch.
20+
if(FIREBIRD_INCLUDE_DIR)
21+
if(NOT EXISTS "${FIREBIRD_INCLUDE_DIR}/ibase.h")
22+
message(FATAL_ERROR
23+
"FIREBIRD_INCLUDE_DIR is set to '${FIREBIRD_INCLUDE_DIR}' "
24+
"but ibase.h was not found there.")
25+
endif()
26+
message(STATUS "Firebird headers (pre-installed): ${FIREBIRD_INCLUDE_DIR}")
27+
return()
28+
endif()
29+
1530
include(FetchContent)
1631

1732
# Pin to Firebird 5.0.2 – bump when upgrading the target engine version.

firebird-odbc-driver.build.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ task clean {
4242

4343
# Synopsis: Build the driver and tests (default task).
4444
task build {
45-
exec { cmake -B $BuildDir -S $BuildRoot -DCMAKE_BUILD_TYPE=$Configuration -DBUILD_TESTING=ON }
45+
exec { cmake -B $BuildDir -S $BuildRoot "-DCMAKE_BUILD_TYPE=$Configuration" -DBUILD_TESTING=ON }
4646

4747
if ($IsWindowsOS) {
4848
exec { cmake --build $BuildDir --config $Configuration }

tests/CMakeLists.txt

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,28 @@ if(NOT CMAKE_PROJECT_NAME OR CMAKE_PROJECT_NAME STREQUAL "FirebirdOdbcTests")
1919
endif()
2020

2121
# ---------------------------------------------------------------------------
22-
# Google Test — prefer FetchContent (integrated build), fall back to find_package
22+
# Google Test — prefer find_package (pre-installed), fall back to FetchContent
2323
# ---------------------------------------------------------------------------
24-
include(FetchContent)
25-
FetchContent_Declare(
26-
googletest
27-
URL https://github.com/google/googletest/archive/refs/tags/v1.14.0.zip
28-
DOWNLOAD_EXTRACT_TIMESTAMP TRUE
29-
)
30-
# Prevent GTest from overriding parent project settings
31-
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
32-
set(INSTALL_GTEST OFF CACHE BOOL "" FORCE)
33-
# Build GTest as a static library (the test exe doesn't need a separate DLL)
34-
set(BUILD_SHARED_LIBS_SAVED ${BUILD_SHARED_LIBS})
35-
set(BUILD_SHARED_LIBS OFF)
36-
FetchContent_MakeAvailable(googletest)
37-
set(BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS_SAVED})
24+
find_package(GTest CONFIG QUIET)
25+
if(GTest_FOUND)
26+
message(STATUS "Google Test: using pre-installed (find_package)")
27+
else()
28+
message(STATUS "Google Test: not found locally, fetching via FetchContent")
29+
include(FetchContent)
30+
FetchContent_Declare(
31+
googletest
32+
URL https://github.com/google/googletest/archive/refs/tags/v1.14.0.zip
33+
DOWNLOAD_EXTRACT_TIMESTAMP TRUE
34+
)
35+
# Prevent GTest from overriding parent project settings
36+
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
37+
set(INSTALL_GTEST OFF CACHE BOOL "" FORCE)
38+
# Build GTest as a static library (the test exe doesn't need a separate DLL)
39+
set(BUILD_SHARED_LIBS_SAVED ${BUILD_SHARED_LIBS})
40+
set(BUILD_SHARED_LIBS OFF)
41+
FetchContent_MakeAvailable(googletest)
42+
set(BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS_SAVED})
43+
endif()
3844

3945
# ---------------------------------------------------------------------------
4046
# Find ODBC
@@ -98,7 +104,11 @@ add_executable(firebird_odbc_tests
98104
# ---------------------------------------------------------------------------
99105
# Link against Google Test and the ODBC Driver Manager
100106
# ---------------------------------------------------------------------------
101-
target_link_libraries(firebird_odbc_tests PRIVATE gtest ODBC::ODBC)
107+
if(GTest_FOUND)
108+
target_link_libraries(firebird_odbc_tests PRIVATE GTest::gtest ODBC::ODBC)
109+
else()
110+
target_link_libraries(firebird_odbc_tests PRIVATE gtest ODBC::ODBC)
111+
endif()
102112

103113
# ---------------------------------------------------------------------------
104114
# Discover tests for CTest

0 commit comments

Comments
 (0)