Skip to content

Commit 593095f

Browse files
committed
In CMake, prefer CMake's config headers.
Fixes #178. Sometimes people experienced strange build problems when building with CMake, where libpqxx seemed to be compiled for a different C++ version than the one for which it was configured. This seems to happen in out-of-tree builds when the source tree has the configuration headers (`include/pqxx/config-*-*.h`), generated by the native autoconf-based build. The CMake build would generate similar config headers in the build tree, but when actually compiling, the build preferred the autoconf-generated config headers over the CMake-generated ones. This fixes that by reordering the include directories as they are added.
1 parent e1f3c61 commit 593095f

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
6.4.4
22
- Use pkg-config if pg-config is not available.
3+
- In CMake build, prefer CMake's config headers over any found in source tree.
34
6.4.3
45
- Updated copyright strings.
56
- Added missing "stream" headers to autotools-based install.

src/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,15 @@ if(NOT PostgreSQL_INCLUDE_DIRS)
1515
find_package(PostgreSQL REQUIRED)
1616
endif()
1717

18+
# When setting up the include paths, mention the binary tree's include
19+
# directory *before* the source tree's include directory. If the source tree
20+
# happens to contain autoconf-generated config headers, we should still prefer
21+
# the ones in the binary tree.
1822
macro(library_target_setup tgt)
1923
target_include_directories(${tgt}
2024
PUBLIC
21-
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
2225
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include>
26+
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
2327
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
2428
PRIVATE
2529
${PostgreSQL_INCLUDE_DIRS}

src/CMakeLists.txt.template

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@ if(NOT PostgreSQL_INCLUDE_DIRS)
22
find_package(PostgreSQL REQUIRED)
33
endif()
44

5+
# When setting up the include paths, mention the binary tree's include
6+
# directory *before* the source tree's include directory. If the source tree
7+
# happens to contain autoconf-generated config headers, we should still prefer
8+
# the ones in the binary tree.
59
macro(library_target_setup tgt)
610
target_include_directories(${tgt}
711
PUBLIC
8-
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
912
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include>
13+
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
1014
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
1115
PRIVATE
1216
${PostgreSQL_INCLUDE_DIRS}

0 commit comments

Comments
 (0)