-
Notifications
You must be signed in to change notification settings - Fork 477
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
soci
not found when adding as subproject
#762
Comments
I'm sorry but I can't help you. I almost never use dependencies/projects via ExternalProject_Add |
Thanks @mloskot . |
@msis For your information. Although it is a little complicated, it is important to understand that CMake operations are roughly divided into two steps: configuration and build.
At this point, soci is not built by CMake (soci is a library that needs to be built), because the configure step only downloads the source. NOTE: That's because To build SOCI with CMake alone and use it in your project, you need to build the SOCI with CMake configure step and define its CMake target. In the googletest sample below, Since spdlog is a header-only-library, it seems to be working. |
Thanks @tt4g. I will try what you suggested right away. However, I added a static library that worked too. PS: So far it seems that all other libraries build a package with |
@tt4g , I followed the steps for
|
soci's CMake target name is Try replacing the dependency name |
We're making progress! But it seems like there's another issue with the include directories: #include "soci.h" Error:
And it seems like the header files are further down, this will error differently: #include "soci/soci.h" Error:
|
Try adding the soci include directory to the project include directory: include_directories — CMake 3.16.0-rc2 Documentation example cmake_minimum_required(VERSION 3.11)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
include(cmake/spdlog.cmake)
include(cmake/soci.cmake)
+ include_directories("${PATH_TO_SOCI_INCLUDE_DIR}")
add_subdirectory(test_app) |
But isn't the purpose of adding the dependency to avoid that? PS: I'm trying to avoid such an include as it is not recommended anymore... |
I suggested Of course you can use |
I understand, but it didn't solve the issue neither. set(PATH_TO_SOCI_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../build/_deps/soci-src/include)
message(STATUS ${PATH_TO_SOCI_INCLUDE_DIR})
target_include_directories(test_app
PRIVATE
${PATH_TO_SOCI_INCLUDE_DIR}
) And I still get the same error... |
Is the following error message? #762 (comment):
If so, the file generated by the soci project's CMAKELists.txt may not exist. Lines 152 to 155 in dbf9397
Does |
@msis I created a small project to build soci. The problem of missing |
So that file isn't there. It's in Is it possible the include files are not copied correctly? |
@tt4g, I resolved the issue by changing the following in the diff --git a/CMakeLists.txt b/CMakeLists.txt
index 004dd07..2125bd1 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -149,7 +149,7 @@ set(INCLUDEDIR "include" CACHE PATH "The directory to install includes into.")
###############################################################################
# Configuration files
###############################################################################
-set(CONFIG_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/include)
+set(CONFIG_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)
install(DIRECTORY ${CONFIG_INCLUDE_DIR}/soci DESTINATION ${INCLUDEDIR})
set(CONFIG_FILE_IN "include/soci/soci-config.h.in")
set(CONFIG_FILE_OUT "${CONFIG_INCLUDE_DIR}/soci/soci-config.h")
I have this as a patch during the cmake_minimum_required(VERSION 3.11)
message(STATUS "Extern: SOCI pre4.0+git_blksail")
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
include(FetchContent)
FetchContent_Declare( soci
GIT_REPOSITORY https://github.com/SOCI/soci
GIT_TAG master
GIT_SHALLOW ON
PATCH_COMMAND git apply "${CMAKE_SOURCE_DIR}/src/patches/soci.patch"
)
FetchContent_GetProperties(soci)
if(NOT soci_POPULATED)
set(SOCI_STATIC ON)
set(SOCI_SHARED ON)
set(SOCI_TESTS OFF)
# set(SOCI_ASAN OFF)
set(SOCI_CXX11 ON)
set(SOCI_LIBDIR lib)
set(WITH_SQLITE3 ON)
set(WITH_POSTGRESQL ON)
set(WITH_BOOST OFF)
set(WITH_DB2 OFF)
set(WITH_ODBC OFF)
set(WITH_ORACLE OFF)
set(WITH_MYSQL OFF)
set(SOCI_EMPTY OFF)
FetchContent_Populate(soci)
add_subdirectory(
${soci_SOURCE_DIR}
${soci_BINARY_DIR}
EXCLUDE_FROM_ALL)
endif() |
While this solution is a hack, it let's users import soci as dependency. I will leave it to the maintainers to close it if they see fit. PS: before |
@msis Probably the difference between CMake in-souce builds and out-of-source builds. Since SOCI outputs a header file at build time, I think that Your project can now be built because you changed PS: It's very difficult to build external third party projects together in your own project like this one. |
@tt4g Which one do you recommend? |
@msis Sorry for letting you expect. |
It would, but it is not going to happen, unless someone does the job (not much time left!). If anyone is interested in the task, I have started CMake modernisation here https://github.com/SOCI/soci/tree/wip/ml/modern-cmake
I have been well aware of all those for quite some time, including this https://crascit.com/professional-cmake/ which is single best one. |
Thanks @mloskot . What's the minimum CMake version you're ready to have? |
Personally, I'm always on the latest release. For SOCI, not sure what would be suitable, certainly not older than 3.5 or 3.8. @vadz may want to comment. I'm not sure if it is feasible to get the CMake rewrite for SOCI 4.0.0 which I'm ready to start releasing any time soon (in fact, release candidate 1 could have happened even now). |
In case it's useful, here's a CMake function we use at work to bring in soci into our build (note the restrictions and assumptions as mentioned in the comments, etc.): # Download soci using dependency details from "soci" and adds
# it to the build via add_subdirectory(). It will be assumed
# that Boost should be enabled unless the NO_BOOST option
# is given.
#
# Arguments to the function should be the required backends
# to enable in the soci build (all lowercase). Eg:
#
# myCustomDependencyAddSoci(oracle postgresql)
#
function(myCustomDependencyAddSoci)
if(NOT UNIX)
message(FATAL_ERROR "Soci support only implemented for Unix")
endif()
include(FetchContent)
FetchContent_GetProperties(soci)
if(soci_POPULATED)
return()
endif()
FetchContent_Populate(soci)
# Set up for our customizations before bringing soci into the build
set(options "NO_BOOST")
set(singleVal "")
set(multiVal "")
cmake_parse_arguments(ARGS "${options}" "${singleVal}" "${multiVal}" ${ARGN})
if(ARGS_NO_BOOST)
set(WITH_BOOST OFF CACHE INTERNAL "")
else()
find_package(Boost QUIET)
if(Boost_FOUND)
set(WITH_BOOST ON CACHE INTERNAL "")
else()
set(WITH_BOOST OFF CACHE INTERNAL "")
endif()
endif()
set(requestedBackends ${ARGS_UNPARSED_ARGUMENTS})
set(supportedBackends
odbc
oracle
postgresql
sqlite3
db2
firebird
mysql
)
# Assumes you want C++11, no soci tests and build shared libs
set(SOCI_CXX_C11 ON CACHE INTERNAL "")
set(SOCI_TESTS OFF CACHE INTERNAL "")
set(SOCI_STATIC OFF CACHE INTERNAL "")
foreach(backend IN LISTS supportedBackends)
string(TOUPPER "${backend}" beUpper)
string(TOLOWER "${backend}" beLower)
if("${beLower}" IN_LIST requestedBackends)
set(WITH_${beUpper} ON CACHE INTERNAL "")
else()
set(WITH_${beUpper} OFF CACHE INTERNAL "")
endif()
endforeach()
# Take over where soci will install things and under what component name
include(GNUInstallDirs)
set(BINDIR ${CMAKE_INSTALL_BINDIR} CACHE INTERNAL "")
set(LIBDIR ${CMAKE_INSTALL_LIBDIR} CACHE INTERNAL "")
set(CMAKE_INSTALL_DEFAULT_COMPONENT_NAME soci)
# Because of manually defined SOCI_VERSION
set(CMAKE_POLICY_DEFAULT_CMP0048 NEW)
add_subdirectory(${soci_SOURCE_DIR} ${soci_BINARY_DIR})
# Ensure we have namespaced targets. These are what projects
# should reference directly, not the unnamespaced soci_* targets.
foreach(lib IN LISTS requestedBackends ITEMS core empty)
if(NOT TARGET SOCI::soci_${lib})
add_library(SOCI::soci_${lib} ALIAS soci_${lib})
endif()
endforeach()
# Fix missing information in some targets (haven't tested all backends)
set_property(TARGET soci_core APPEND PROPERTY
INTERFACE_INCLUDE_DIRECTORIES
$<BUILD_INTERFACE:${soci_BINARY_DIR}/include>
)
if(WITH_BOOST)
set_property(TARGET soci_core APPEND PROPERTY
INTERFACE_INCLUDE_DIRECTORIES
$<TARGET_PROPERTY:Boost::boost,INTERFACE_INCLUDE_DIRECTORIES>
)
set_property(TARGET soci_core APPEND PROPERTY
INTERFACE_COMPILE_DEFINITIONS SOCI_USE_BOOST
)
endif()
if("oracle" IN_LIST requestedBackends)
set_property(TARGET soci_oracle APPEND PROPERTY
INTERFACE_INCLUDE_DIRECTORIES $<BUILD_INTERFACE:${ORACLE_HOME}/sdk/include>
)
endif()
# Work around build warning that gets turned into an error when building
# for release with more recent compilers. The warning seems questionable
# for the specific case that gets triggered in vector-into-type.cpp.
if(WITH_ORACLE AND CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU")
target_compile_options(soci_oracle PRIVATE -Wno-maybe-uninitialized)
endif()
endfunction() It assumes you've declared the details you want before calling the function. Use it something like the following: FetchContent_Declare(soci
GIT_REPOSITORY https://github.com/SOCI/soci
GIT_TAG 125753ff2fa8457b980fc4186606b9b08b2612b5
)
myCustomDependencySoci(oracle postgresql) |
- Issue `soci` not found when adding as subproject SOCI#762
I can't seem to be able to add
soci
as a subproject.I have tried with
ExternalProject_Add
, andFetchContent
but I can't figure out why I keep getting:Project description
My project structure is the following:
src/CMakeLists.txt
src/test_app/CMakeLists.txt
spdlog.cmake
soci.cmake
The text was updated successfully, but these errors were encountered: