Warning, /sdk/codevis/thirdparty/soci/docs/installation.md is written in an unsupported language. File is not indexed.
0001 # Installation
0002
0003 ## Requirements
0004
0005 Below is an overall list of SOCI core:
0006
0007 * C++ compiler: [GCC](http://gcc.gnu.org/), [Microsoft Visual C++](http://msdn.microsoft.com/en-us/visualc), [LLVM/clang](http://clang.llvm.org/)
0008 * [CMake](http://www.cmake.org) 2.8+ - in order to use build configuration for CMake
0009 * [Boost C++ Libraries](http://www.boost.org): DateTime, Fusion, Optional, Preprocessor, Tuple
0010
0011 and backend-specific dependencies:
0012
0013 * [DB2 Call Level Interface (CLI)](http://pic.dhe.ibm.com/infocenter/db2luw/v10r1/topic/com.ibm.swg.im.dbclient.install.doc/doc/c0023452.html)
0014 * [Firebird client library](http://www.firebirdsql.org/manual/ufb-cs-clientlib.html)
0015 * [mysqlclient](https://dev.mysql.com/doc/refman/5.6/en/c-api.html) - C API to MySQL
0016 * ODBC (Open Database Connectivity) implementation: [Microsoft ODBC](http://msdn.microsoft.com/en-us/library/windows/desktop/ms710252.aspx) [iODBC](http://www.iodbc.org/), [unixODBC](http://www.unixodbc.org/)
0017 * [Oracle Call Interface (OCI)](http://www.oracle.com/technetwork/database/features/oci/index.html)
0018 * [libpq](http://www.postgresql.org/docs/current/static/libpq.html) - C API to PostgreSQL
0019 * [SQLite 3](http://www.sqlite.org/) library
0020
0021 ## Downloads
0022
0023 Download package with latest release of the SOCI source code:
0024 [soci-X.Y.Z](https://sourceforge.net/projects/soci/),
0025 where X.Y.Z is the version number. Unpack the archive.
0026
0027 You can always clone SOCI from the Git repository:
0028
0029 ```console
0030 git clone git://github.com/SOCI/soci.git
0031 ```
0032
0033 ## Building with CMake
0034
0035 SOCI is configured to build using [CMake](http://cmake.org/) system in version 2.8+.
0036
0037 The build configuration allows to control various aspects of compilation and
0038 installation by setting common CMake variables that change behaviour, describe
0039 system or control build (see [CMake help](http://cmake.org/cmake/help/documentation.html))
0040 as well as SOCI-specific variables described below.
0041 All these variables are available regardless of platform or compilation toolset used.
0042
0043 Running CMake from the command line allows to set variables in the CMake cache
0044 with the following syntax: `-DVARIABLE:TYPE=VALUE`. If you are new to CMake,
0045 you may find the tutorial [Running CMake](http://cmake.org/cmake/help/runningcmake.html) helpful.
0046
0047 ### Running CMake on Unix
0048
0049 Steps outline using GNU Make `Makefile`-s:
0050
0051 ```console
0052 mkdir build
0053 cd build
0054 cmake -G "Unix Makefiles" -DWITH_BOOST=OFF -DWITH_ORACLE=OFF (...) /path/to/soci-X.Y.Z
0055 make
0056 make install
0057 ```
0058
0059 ### Running CMake on Windows
0060
0061 Steps outline using Visual Studio 2010 and MSBuild:
0062
0063 ```console
0064 mkdir build
0065 cd build
0066 cmake -G "Visual Studio 10" -DWITH_BOOST=OFF -DWITH_ORACLE=OFF (...) C:\path\to\soci-X.Y.Z
0067 msbuild.exe SOCI.sln
0068 ```
0069
0070 ### CMake configuration
0071
0072 By default, CMake will try to determine availability of all dependencies automatically.
0073 If you are lucky, you will not need to specify any of the CMake variables explained below.
0074 However, if CMake reports some of the core or backend-specific dependencies
0075 as missing, you will need specify relevant variables to tell CMake where to look
0076 for the required components.
0077
0078 CMake configures SOCI build performing sequence of steps.
0079 Each subsequent step is dependant on result of previous steps corresponding with particular feature.
0080 First, CMake checks system platform and compilation toolset.
0081 Next, CMake tries to find all external dependencies.
0082 Then, depending on the results of the dependency check, CMake determines SOCI backends which are possible to build.
0083 The SOCI-specific variables described below provide users with basic control of this behaviour.
0084
0085 The following sections provide summary of variables accepted by CMake scripts configuring SOCI build.
0086 The lists consist of common variables for SOCI core and all backends as well as variables specific to SOCI backends and their direct dependencies.
0087
0088 List of a few essential CMake variables:
0089
0090 * `CMAKE_BUILD_TYPE` - string - Specifies the build type for make based generators (see CMake [help](http://cmake.org/cmake/help/cmake-2-8-docs.html#variable:CMAKE_BUILD_TYPE)).
0091 * `CMAKE_INSTALL_PREFIX` - path - Install directory used by install command (see CMake [help](http://cmake.org/cmake/help/cmake-2-8-docs.html#variable:CMAKE_INSTALL_PREFIX)).
0092 * `CMAKE_VERBOSE_MAKEFILE` - boolean - If ON, create verbose makefile (see CMake [help](http://cmake.org/cmake/help/cmake-2-8-docs.html#variable:CMAKE_VERBOSE_MAKEFILE)).
0093
0094 List of variables to control common SOCI features and dependencies:
0095
0096 * `SOCI_SHARED` - boolean - Request to build shared libraries for SOCI core and all successfully configured backends. Default is `ON`.
0097 * `SOCI_STATIC` - boolean - Request to build static libraries for SOCI core and all successfully configured backends. Default is `ON`.
0098 * `SOCI_TESTS` - boolean - Request to build regression tests for SOCI core and all successfully configured backends.
0099 * `WITH_BOOST` - boolean - Should CMake try to detect [Boost C++ Libraries](http://www.boost.org/). If ON, CMake will try to find Boost headers and binaries of [Boost.Date_Time](http://www.boost.org/doc/libs/release/doc/html/date_time.html) library.
0100
0101 Some other build options:
0102
0103 * `SOCI_ASAN` - boolean - Build with address sanitizer (ASAN) support. Useful for finding problems when debugging, but shouldn't be used for the production builds due to extra overhead. Default is `OFF`.
0104 * `SOCI_LTO` - boolean - Build with link-time optimizations, if supported. This produces noticeably smaller libraries. Default is `OFF`, but turning it on is recommended for the production builds.
0105 * `SOCI_VISIBILITY` - boolean - Use hidden ELF visibility for private symbols if supported by the platform. This option produces smaller libraries by avoiding exporting internal function symbols. Default is `ON`.
0106
0107 #### Empty (sample backend)
0108
0109 * `SOCI_EMPTY` - boolean - Builds the [sample backend](backends/index.md) called Empty. Always ON by default.
0110 * `SOCI_EMPTY_TEST_CONNSTR` - string - Connection string used to run regression tests of the Empty backend. It is a dummy value. Example: `-DSOCI_EMPTY_TEST_CONNSTR="dummy connection"`
0111
0112 #### IBM DB2
0113
0114 * `WITH_DB2` - boolean - Should CMake try to detect IBM DB2 Call Level Interface (CLI) library.
0115 * `DB2_INCLUDE_DIR` - string - Path to DB2 CLI include directories where CMake should look for `sqlcli1.h` header.
0116 * `DB2_LIBRARIES` - string - Full paths to `db2` or `db2api` libraries to link SOCI against to enable the backend support.
0117 * `SOCI_DB2` - boolean - Requests to build [DB2](backends/db2.md) backend. Automatically switched on, if `WITH_DB2` is set to ON.
0118 * `SOCI_DB2_TEST_CONNSTR` - string - See [DB2 backend reference](backends/db2.md) for details. Example: `-DSOCI_DB2_TEST_CONNSTR:STRING="DSN=SAMPLE;Uid=db2inst1;Pwd=db2inst1;autocommit=off"`
0119
0120 #### Firebird
0121
0122 * `WITH_FIREBIRD` - boolean - Should CMake try to detect Firebird client library.
0123 * `FIREBIRD_INCLUDE_DIR` - string - Path to Firebird include directories where CMake should look for `ibase.h` header.
0124 * `FIREBIRD_LIBRARIES` - string - Full paths to Firebird `fbclient` or `fbclient_ms` libraries to link SOCI against to enable the backend support.
0125 * `SOCI_FIREBIRD` - boolean - Requests to build [Firebird](backends/firebird.md) backend. Automatically switched on, if `WITH_FIREBIRD` is set to ON.
0126 * `SOCI_FIREBIRD_TEST_CONNSTR` - string - See [Firebird backend reference](backends/firebird.md) for details. Example: `-DSOCI_FIREBIRD_TEST_CONNSTR:STRING="service=LOCALHOST:/tmp/soci_test.fdb user=SYSDBA password=masterkey"`
0127
0128 #### MySQL
0129
0130 * `WITH_MYSQL` - boolean - Should CMake try to detect [mysqlclient](https://dev.mysql.com/doc/refman/5.5/en/c-api.html) libraries providing MySQL C API. Note, currently the [mysql_config](https://dev.mysql.com/doc/refman/5.5/en/c-api-building-clients.html) program is not being used.
0131 * `MYSQL_DIR` - string - Path to MySQL installation root directory. CMake will scan subdirectories `MYSQL_DIR/include` and `MYSQL_DIR/lib` respectively for MySQL headers and libraries.
0132 * `MYSQL_INCLUDE_DIR` - string - Path to MySQL include directory where CMake should look for `mysql.h` header.
0133 * `MYSQL_LIBRARIES` - string - Full paths to libraries to link SOCI against to enable the backend support.
0134 * `SOCI_MYSQL` - boolean - Requests to build [MySQL](backends/mysql.md) backend. Automatically switched on, if `WITH_MYSQL` is set to ON.
0135 * `SOCI_MYSQL_TEST_CONNSTR` - string - Connection string to MySQL test database. Format of the string is explained [MySQL backend reference](backends/mysql.md). Example: `-DSOCI_MYSQL_TEST_CONNSTR:STRING="db=mydb user=mloskot password=secret"`
0136
0137 #### ODBC
0138
0139 * `WITH_ODBC` - boolean - Should CMake try to detect ODBC libraries. On Unix systems, CMake tries to find [unixODBC](http://www.unixodbc.org/) or [iODBC](http://www.iodbc.org/) implementations.
0140 * `ODBC_INCLUDE_DIR` - string - Path to ODBC implementation include directories where CMake should look for `sql.h` header.
0141 * `ODBC_LIBRARIES` - string - Full paths to libraries to link SOCI against to enable the backend support.
0142 * `SOCI_ODBC` - boolean - Requests to build [ODBC](backends/odbc.md) backend. Automatically switched on, if `WITH_ODBC` is set to ON.
0143 * `SOCI_ODBC_TEST_{database}_CONNSTR` - string - ODBC Data Source Name (DSN) or ODBC File Data Source Name (FILEDSN) to test database: Microsoft Access (.mdb), Microsoft SQL Server, MySQL, PostgreSQL or any other ODBC SQL data source. {database} is placeholder for name of database driver ACCESS, MYSQL, POSTGRESQL, etc. See [ODBC](backends/odbc.md) backend reference for details. Example: `-DSOCI_ODBC_TEST_POSTGRESQL_CONNSTR="FILEDSN=/home/mloskot/soci/build/test-postgresql.dsn"`
0144
0145 #### Oracle
0146
0147 * `WITH_ORACLE` - boolean - Should CMake try to detect [Oracle Call Interface (OCI)](http://en.wikipedia.org/wiki/Oracle_Call_Interface) libraries.
0148 * `ORACLE_INCLUDE_DIR` - string - Path to Oracle include directory where CMake should look for `oci.h` header.
0149 * `ORACLE_LIBRARIES` - string - Full paths to libraries to link SOCI against to enable the backend support.
0150 * `SOCI_ORACLE` - boolean - Requests to build [Oracle](backends/oracle.md) backend. Automatically switched on, if `WITH_ORACLE` is set to ON.
0151 * `SOCI_ORACLE_TEST_CONNSTR` - string - Connection string to Oracle test database. Format of the string is explained [Oracle backend reference](backends/oracle.md). Example: `-DSOCI_ORACLE_TEST_CONNSTR:STRING="service=orcl user=scott password=tiger"`
0152
0153 #### PostgreSQL
0154
0155 * `WITH_POSTGRESQL` - boolean - Should CMake try to detect PostgreSQL client interface libraries. SOCI relies on [libpq](http://www.postgresql.org/docs/current/static/libpq.html") C library.
0156 * `POSTGRESQL_INCLUDE_DIR` - string - Path to PostgreSQL include directory where CMake should look for `libpq-fe.h` header.
0157 * `POSTGRESQL_LIBRARY` - string - Full paths to libraries to link SOCI against to enable the backend support. The `POSTGRESQL_LIBRARIES` will be set with PostgreSQL libraries needed for linking.
0158 * `SOCI_POSTGRESQL` - boolean - Requests to build [PostgreSQL](backends/postgresql.md) backend. Automatically switched on, if `WITH_POSTGRESQL` is set to ON.
0159 * `SOCI_POSTGRESQL_TEST_CONNSTR` - string - Connection string to PostgreSQL test database. Format of the string is explained PostgreSQL backend reference. Example: `-DSOCI_POSTGRESQL_TEST_CONNSTR:STRING="dbname=mydb user=scott"`
0160
0161 #### SQLite 3
0162
0163 * `WITH_SQLITE3` - boolean - Should CMake try to detect SQLite C/C++ library. As bonus, the configuration tries OSGeo4W distribution if OSGEO4W_ROOT environment variable is set.
0164 * `SQLITE3_INCLUDE_DIR` - string - Path to SQLite 3 include directory where CMake should look for `sqlite3.h` header.
0165 * `SQLITE3_LIBRARY` - string - Full paths to libraries to link SOCI against to enable the backend support.
0166 * `SOCI_SQLITE3` - boolean - Requests to build [SQLite3](backends/sqlite3.md) backend. Automatically switched on, if `WITH_SQLITE3` is set to ON.
0167 * `SOCI_SQLITE3_TEST_CONNSTR` - string - Connection string is simply a file path where SQLite3 test database will be created (e.g. /home/john/soci_test.db). Check [SQLite3 backend reference](backends/sqlite3.md) for details. Example: `-DSOCI_SQLITE3_TEST_CONNSTR="my.db"` or `-DSOCI_SQLITE3_TEST_CONNSTR=":memory:"`.
0168
0169 ## Building with Makefiles on Unix
0170
0171 *NOTE: These (classic) Makefiles have not been maintained for long time.
0172 The officially maintained build configuration is CMake.
0173 If you still want to use these Makefiles, you've been warned that you may need to patch them.*
0174
0175 The classic set of Makefiles for Unix/Linux systems is provided for those users who need complete control over the whole processand who can benefit from the basic scaffolding that they can extend on their own.
0176 In this sense, the basic Makefiles are supposed to provide a minimal starting point for custom experimentation and are not intended to be a complete build/installation solution.
0177 At the same time, they are complete in the sense that they can compile the library with all test programs and for some users this level of support will be just fine.
0178
0179 The `core` directory of the library distribution contains the `Makefile.basic` that can be used to compile the core part of the library.
0180 Run `make -f Makefile.basic` or `make -f Makefile.basic shared` to get the static and shared versions, respectively.
0181 Similarly, the `backends/<i>name</i>` directory contains the backend part for each supported backend with the appropriate `Makefile.basic` and the `backends/<i>name</i>/test` directory contains the test program for the given backend.
0182
0183 For example, the simplest way to compile the static version of the library and the test program for PostgreSQL is:
0184
0185 ```console
0186 cd src/core
0187 make -f Makefile.basic
0188 cd ../backends/postgresql
0189 make -f Makefile.basic
0190 cd test
0191 make -f Makefile.basic
0192 ```
0193
0194 For each backend and its test program, the `Makefile.basic`s contain the variables that can have values specific to the given environment - they usually name the include and library paths.
0195 These variables are placed at the beginning of the `Makefile.basic`s.
0196 Please review their values in case of any compilation problems.
0197
0198 The Makefiles for test programs can be a good starting point to find out correct compiler and linker options.
0199
0200 ## Building with Conan
0201
0202 SOCI is available as a [Conan](https://docs.conan.io/en/latest/) package since
0203 February 2021 for the version [4.0.1](https://conan.io/center/soci) for the
0204 following backends: sqlite3, odbc, mysql, and postgresql.
0205
0206 This section lists the steps required to use SOCI in a CMake project with Conan:
0207
0208 ### Install Conan
0209
0210 Install Conan if it is not installed yet:
0211
0212 ```console
0213 pip3 install conan
0214 ```
0215
0216 ### Create `conanfile.txt`
0217
0218 Create a `conanfile.txt` in the same directory of the `CMakeLists.txt`, with a
0219 _reference to a recipe_ (which is a string with the library name and the
0220 version to use), the build options, and the CMake generator:
0221
0222 ```text
0223 # conanfile.txt
0224 [requires]
0225 soci/4.0.1
0226
0227 [options]
0228 soci:shared = True
0229 soci:with_sqlite3 = True
0230
0231 [generators]
0232 cmake
0233 ```
0234
0235 The option `soci:with_sqlite3 = True` indicates that the `sqlite3` backend will
0236 be downloaded and used.
0237
0238 ### Update `CMakeLists.txt`
0239
0240 Add the following Conan-specific lines to the `CMakeLists.txt` of your project:
0241
0242 ```cmake
0243 include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
0244 conan_basic_setup(TARGETS)
0245 conan_target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
0246 ```
0247
0248 The command `conan_target_link_libraries` replaces `target_link_libraries`.
0249
0250 ### Run Conan
0251
0252 Run `conan install` to install SOCI, and then build your project as usual:
0253
0254 ```bash
0255 mkdir build
0256 cd build
0257 conan install .. --build=soci
0258 cmake ..
0259 cmake . --build
0260 ```
0261
0262 ## Running tests
0263
0264 The process of running regression tests highly depends on user's environment and build configuration, so it may be quite involving process.
0265 The CMake configuration provides variables to allow users willing to run the tests to configure build and specify database connection parameters (see the lists above for variable names).
0266
0267 In order to run regression tests, configure and build desired SOCI backends and prepare working database instances for them.
0268
0269 While configuring build with CMake, specify `SOCI_TESTS=ON` to enable building regression tests.
0270 Also, specify `SOCI_{backend name}_TEST_CONNSTR` variables to tell the tests runner how to connect with your test databases.
0271
0272 Dedicated `make test` target can be used to execute regression tests on build completion:
0273
0274 ```console
0275 mkdir build
0276 cd build
0277 cmake -G "Unix Makefiles" \
0278 -DWITH_BOOST=OFF \
0279 -DSOCI_TESTS=ON \
0280 -DSOCI_EMPTY_TEST_CONNSTR="dummy connection" \
0281 -DSOCI_SQLITE3_TEST_CONNSTR="test.db" \
0282 (...)
0283 ../soci-X.Y.Z
0284 make
0285 make test
0286 make install
0287 ```
0288
0289 In the example above, regression tests for the sample Empty backend and SQLite 3 backend are configured for execution by `make test` target.
0290
0291 ## Using library
0292
0293 CMake build produces set of shared and static libraries for SOCI core and backends separately.
0294 On Unix, for example, `build/lib` directory will consist of the static libraries named like `libsoci_core.a`, `libsoci_sqlite3.a` and shared libraries with names like `libsoci_core.so.4.0.0`, `libsoci_sqlite3.so.4.0.0`, and so on.
0295
0296 If your project also uses CMake, you can simply use `find_package(Soci)` to check for SOCI availability and `target_link_libraries()` to link with the SOCI libraries available under the names `Soci::core` and `Soci::<backend>` (or `Soci::<backend>_static` if you prefer linking statically) and ensure that SOCI headers can be included (i.e. there is no need to use `target_include_directories()` explicitly). An example of a very simple CMake-based project using SOCI is provided in the `examples/connect` directory.
0297
0298 Alternatively, you can add SOCI as a subdirectory to your project and include it via `add_subdirectory()`. As before, `target_link_libraries()` is used to link with the SOCI libraries available under the same names `Soci::core` and `Soci::<backend>` as above. An example of this can be found in the directory `examples/subdir-include`.
0299
0300 If you don't use CMake but want to use SOCI in your program, you need to specify the paths to the SOCI headers and libraries in your build configuration and to
0301 tell the linker to link against the libraries you want to use in your program.