mirror of
https://github.com/silverqx/TinyORM.git
synced 2026-02-05 01:39:39 -06:00
cmake added STRICT_MODE option
It propagate strict compiler/linker options and Qt definitions using the TinyOrm::CommonConfig interface library to the user code (highly recommended; can also be set with the TINYORM_STRICT_MODE environment variable). - updated vcpkg ports - updated docs
This commit is contained in:
@@ -105,6 +105,13 @@ a Debug configuration (-MTd, -MDd)" ON
|
||||
"MSVC;NOT DEFINED CMAKE_MSVC_RUNTIME_LIBRARY" MSVC_RUNTIME_DYNAMIC-NOTFOUND
|
||||
)
|
||||
|
||||
feature_option_environment(STRICT_MODE
|
||||
"Propagate strict compiler/linker options and Qt definitions using \
|
||||
the ${TinyOrm_ns}::${CommonConfig_target} interface library to the user code \
|
||||
(highly recommended; can also be set with the TINYORM_STRICT_MODE environment variable)"
|
||||
TINYORM_STRICT_MODE OFF
|
||||
)
|
||||
|
||||
feature_option(VERBOSE_CONFIGURE
|
||||
"Show information about PACKAGES_FOUND and PACKAGES_NOT_FOUND in the configure \
|
||||
output" OFF
|
||||
@@ -367,10 +374,19 @@ target_link_libraries(${TinyOrm_target}
|
||||
Qt${QT_VERSION_MAJOR}::Core
|
||||
Qt${QT_VERSION_MAJOR}::Sql
|
||||
range-v3::range-v3
|
||||
${TinyOrm_ns}::${CommonConfig_target}
|
||||
)
|
||||
|
||||
# Conditional dependencies
|
||||
if(STRICT_MODE)
|
||||
target_link_libraries(${TinyOrm_target}
|
||||
PUBLIC ${TinyOrm_ns}::${CommonConfig_target}
|
||||
)
|
||||
else()
|
||||
target_link_libraries(${TinyOrm_target}
|
||||
PRIVATE ${TinyOrm_ns}::${CommonConfig_target}
|
||||
)
|
||||
endif()
|
||||
|
||||
if(MYSQL_PING)
|
||||
tiny_find_package(MySQL REQUIRED)
|
||||
target_link_libraries(${TinyOrm_target} PRIVATE MySQL::MySQL)
|
||||
|
||||
@@ -9,6 +9,28 @@ function(feature_option name description default)
|
||||
|
||||
endfunction()
|
||||
|
||||
# Helper function for coupling option() and add_feature_info() and use the default value
|
||||
# from the given environment variable if defined, otherwise, use a value from the given
|
||||
# default CMake variable
|
||||
function(feature_option_environment name description environment_variable_name default)
|
||||
|
||||
# If an environment variable is defined, then use its value
|
||||
if(DEFINED ENV{${environment_variable_name}})
|
||||
if("$ENV{${environment_variable_name}}")
|
||||
set(defaultValue ON)
|
||||
else()
|
||||
set(defaultValue OFF)
|
||||
endif()
|
||||
|
||||
# Otherwise, use a value from the default CMake variable
|
||||
else()
|
||||
set(defaultValue "${default}")
|
||||
endif()
|
||||
|
||||
feature_option(${name} "${description}" "${defaultValue}")
|
||||
|
||||
endfunction()
|
||||
|
||||
include(CMakeDependentOption)
|
||||
# Helper function for coupling cmake_dependent_option() and add_feature_info()
|
||||
macro(feature_option_dependent name description default depends force)
|
||||
|
||||
@@ -82,6 +82,10 @@ ${TINY_UNPARSED_ARGUMENTS}")
|
||||
)
|
||||
endif()
|
||||
|
||||
if(NOT STRICT_MODE)
|
||||
target_link_libraries(${name} PRIVATE ${TinyOrm_ns}::${CommonConfig_target})
|
||||
endif()
|
||||
|
||||
target_link_libraries(${name}
|
||||
PRIVATE
|
||||
Qt${QT_VERSION_MAJOR}::Test
|
||||
|
||||
@@ -14,6 +14,7 @@ vcpkg_check_features(
|
||||
inline-constants INLINE_CONSTANTS
|
||||
mysql-ping MYSQL_PING
|
||||
orm ORM
|
||||
strict-mode STRICT_MODE
|
||||
tom TOM
|
||||
tom-example TOM_EXAMPLE
|
||||
)
|
||||
|
||||
@@ -58,6 +58,9 @@
|
||||
"orm": {
|
||||
"description": "Enable ORM-related source code (without it only the query builder is compiled)"
|
||||
},
|
||||
"strict-mode": {
|
||||
"description": "Propagate strict compiler/linker options and Qt definitions"
|
||||
},
|
||||
"tom": {
|
||||
"description": "Enable Tom-related source code (command-line interface)"
|
||||
},
|
||||
|
||||
@@ -14,6 +14,7 @@ vcpkg_check_features(
|
||||
inline-constants INLINE_CONSTANTS
|
||||
mysql-ping MYSQL_PING
|
||||
orm ORM
|
||||
strict-mode STRICT_MODE
|
||||
tom TOM
|
||||
tom-example TOM_EXAMPLE
|
||||
)
|
||||
|
||||
@@ -76,6 +76,9 @@
|
||||
"orm": {
|
||||
"description": "Enable ORM-related source code (without it only the query builder is compiled)"
|
||||
},
|
||||
"strict-mode": {
|
||||
"description": "Propagate strict compiler/linker options and Qt definitions"
|
||||
},
|
||||
"tom": {
|
||||
"description": "Enable Tom-related source code (command-line interface)"
|
||||
},
|
||||
|
||||
@@ -396,6 +396,10 @@ And build.
|
||||
cmake --build . --target all
|
||||
```
|
||||
|
||||
:::tip
|
||||
Enable the [`TINYORM_STRICT_MODE`](tinyorm.mdx#cmake-strict_mode-option) environment variable to produce better code and to follow good code practices.
|
||||
:::
|
||||
|
||||
### Execute Hello world {#execute-hello-world-cmake}
|
||||
|
||||
Do not forget to add `TinyOrm0d.dll` on the path on Windows and on the `LD_LIBRARY_PATH` on Linux, so `HelloWorld` application can find it during execution, as is described [here](building/tinyorm.mdx#tinyorm-on-path-cmake).
|
||||
|
||||
@@ -440,6 +440,24 @@ cd TinyORM-builds-cmake/build-debug
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
|
||||
##### CMake `STRICT_MODE` option
|
||||
|
||||
The `STRICT_MODE` `CMake` configuration option was added in `TinyORM` `v0.35.0`. This option was added to avoid the propagation of aggressive strict warning compiler/linker options and Qt definitions from the `TinyORM` library to user code through the [`TinyOrm::CommonConfig`](https://github.com/silverqx/TinyORM/blob/main/cmake/CommonModules/TinyCommon.cmake) interface library.
|
||||
|
||||
`TinyORM` uses the strictest warning level options, virtually anything that can be enabled is enabled to produce a better code. I highly recommend enabling this option to produce better code and to follow good practices. It also helps to follow the `ISOCPP` [C++ Core Guidelines](https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines) standards.
|
||||
|
||||
If you want to enable these strict warning options in your code, you can enable the `STRICT_MODE` `CMake` configuration option and they will be propagated to your code. You can also enabled it globally using the `TINYORM_STRICT_MODE` environment variable, and the value of this environment variable will be picked up during initial CMake configuration as the default value for the `STRICT_MODE` `CMake` configuration option.
|
||||
|
||||
You can achieve the same result by manually linking against the `TinyOrm::CommonConfig` interface library when the `STRICT_MODE` is set to `OFF`.
|
||||
|
||||
```cmake
|
||||
target_link_libraries(<target> PRIVATE TinyOrm::CommonConfig)
|
||||
```
|
||||
|
||||
:::info
|
||||
The recommended way is to set the `TINYORM_STRICT_MODE` environment variable to `1`.
|
||||
:::
|
||||
|
||||
#### Build TinyORM
|
||||
|
||||
And build. You don't have to install it, you can use the build tree directly if you want.
|
||||
@@ -472,6 +490,7 @@ CMake multi-config generators like `Ninja Multi-Config` or `Visual Studio 16 201
|
||||
| `MSVC_RUNTIME_DYNAMIC` | `ON` | Use MSVC dynamic runtime library (`-MD`) instead of static (`-MT`), also considers a Debug configuration (`-MTd`, `-MDd`).<br/><small>Available when: `MSVC AND NOT DEFINED CMAKE_MSVC_RUNTIME_LIBRARY`</small> |
|
||||
| `MYSQL_PING` | `OFF` | Enable `Orm::MySqlConnection::pingDatabase()` method. |
|
||||
| `ORM` | `ON` | Controls the compilation of all `ORM-related` source code, when this option is `disabled`, then only the `query builder` without `ORM` is compiled. Also excludes `ORM-related` unit tests. |
|
||||
| `STRICT_MODE` | `OFF` | Controls propagation of strict compiler/linker options and Qt definitions using the `TinyOrm::CommonConfig` interface library to the user code.<br/><small>(highly recommended; can also be set with the `TINYORM_STRICT_MODE` environment variable; described [here](#cmake-strict_mode-option))</small>. |
|
||||
| `TOM` | `ON` | Controls the compilation of all `Tom-related` source code, when this option is `disabled`, then it also excludes `Tom-related` unit tests. |
|
||||
| `TOM_EXAMPLE` | `OFF` | Build the <abbr title='TinyORM Migrations'>`tom`</abbr> console application example. |
|
||||
| `TOM_MIGRATIONS_DIR` | `-` | Default migrations path for the `make:migration` command, can be an absolute or relative path (to the <abbr title='Current working directory'>pwd</abbr>).<br/><small>Default value: `database/migrations` <small>(relative to the pwd)</small></small> |
|
||||
|
||||
@@ -80,5 +80,10 @@ tiny_resource_and_manifest(${TomExample_target}
|
||||
# Resolve and link dependencies
|
||||
# ---
|
||||
|
||||
# Unconditional dependencies
|
||||
if(NOT STRICT_MODE)
|
||||
target_link_libraries(${TomExample_target}
|
||||
PRIVATE ${TinyOrm_ns}::${CommonConfig_target}
|
||||
)
|
||||
endif()
|
||||
|
||||
target_link_libraries(${TomExample_target} PRIVATE ${TinyOrm_ns}::${TinyOrm_target})
|
||||
|
||||
@@ -101,6 +101,12 @@ tiny_resource_and_manifest(${TinyUtils_target}
|
||||
# Resolve and link dependencies
|
||||
# ---
|
||||
|
||||
if(NOT STRICT_MODE)
|
||||
target_link_libraries(${TinyUtils_target}
|
||||
PRIVATE ${TinyOrm_ns}::${CommonConfig_target}
|
||||
)
|
||||
endif()
|
||||
|
||||
target_link_libraries(${TinyUtils_target}
|
||||
PUBLIC
|
||||
${TinyOrm_ns}::${TinyOrm_target}
|
||||
|
||||
@@ -82,5 +82,10 @@ tiny_resource_and_manifest(${TomTestData_target}
|
||||
# Resolve and link dependencies
|
||||
# ---
|
||||
|
||||
# Unconditional dependencies
|
||||
if(NOT STRICT_MODE)
|
||||
target_link_libraries(${TomTestData_target}
|
||||
PRIVATE ${TinyOrm_ns}::${CommonConfig_target}
|
||||
)
|
||||
endif()
|
||||
|
||||
target_link_libraries(${TomTestData_target} PRIVATE ${TinyOrm_ns}::${TinyOrm_target})
|
||||
|
||||
Reference in New Issue
Block a user