Skip to content

Commit

Permalink
Re-introduce explicit build artefact directories
Browse files Browse the repository at this point in the history
It turned out that on Windows this is actually necessary in order for
DLLs to be usable.

In contrast to what has been removed in
a2faea6, this commit adds a guard that
will ensure that when CMAKE_RUNTIME_DIRECTORY (which is the crucial one
in order for DLLs to work) is already set, we don't overwrite it. This
means that we should stick to whatever has already been configured,
avoiding any inconsistencies.
Additionally, we now emit a warning if SOCI is embedded by a project
that doesn't set these variables as that can also lead to
inconsistencies as then the order of when exactly SOCI is embedded into
the top-level project matters.

Relates to #1159
  • Loading branch information
Krzmbrzl committed Sep 1, 2024
1 parent 6a106e7 commit f4e01a4
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,23 @@ if (SOCI_LD)
add_link_options("${USE_LD_FLAG}")
endif()

if (NOT DEFINED CMAKE_RUNTIME_OUTPUT_DIRECTORY)
# Ensure that build artifacts are easy to find. And on Windows this
# guarantees that the built DLLs end up next to applications
# linking to them as otherwise they won't be found.
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

if (NOT PROJECT_IS_TOP_LEVEL)
# If the embedding project does not define these variables, this can lead to
# inconsistencies which can cause issues on Windows when e.g. the embedding
# project has an executable that links to a SOCI DLL which will be put into
# a different directory which will lead to the exe not finding the DLL.
message(WARNING "Setting CMAKE_{LIBRARY, ARCHIVE, RUNTIME}_DIRECTORY variables which should have done by the embedding cmake project")
endif()
endif()

if (SOCI_SHARED)
set(SOCI_LIB_TYPE "SHARED")
else()
Expand Down

0 comments on commit f4e01a4

Please sign in to comment.