mirror of
https://github.com/latentPrion/cppbessot.git
synced 2026-06-23 15:18:37 +00:00
Env: generate .env file in builddir for DB_TARGET and vars
This commit is contained in:
@@ -12,6 +12,7 @@ include("${CMAKE_CURRENT_LIST_DIR}/dbGenMigrations.cmake")
|
|||||||
include("${CMAKE_CURRENT_LIST_DIR}/dbActionCommon.cmake")
|
include("${CMAKE_CURRENT_LIST_DIR}/dbActionCommon.cmake")
|
||||||
include("${CMAKE_CURRENT_LIST_DIR}/dbActionCreateFrom.cmake")
|
include("${CMAKE_CURRENT_LIST_DIR}/dbActionCreateFrom.cmake")
|
||||||
include("${CMAKE_CURRENT_LIST_DIR}/dbActionMigrate.cmake")
|
include("${CMAKE_CURRENT_LIST_DIR}/dbActionMigrate.cmake")
|
||||||
|
include("${CMAKE_CURRENT_LIST_DIR}/dbRuntimeEnv.cmake")
|
||||||
|
|
||||||
if(NOT DEFINED CPPBESSOT_WORKDIR)
|
if(NOT DEFINED CPPBESSOT_WORKDIR)
|
||||||
set(CPPBESSOT_WORKDIR "db" CACHE STRING "CppBeSSOT schema root folder")
|
set(CPPBESSOT_WORKDIR "db" CACHE STRING "CppBeSSOT schema root folder")
|
||||||
@@ -87,6 +88,8 @@ set(CPPBESSOT_DB_SQLITE_CLONE_PROD_TO_PRODDEV_COMMAND "${CPPBESSOT_DB_SQLITE_CLO
|
|||||||
set(CPPBESSOT_DB_PGSQL_CLONE_PROD_TO_PRODDEV_COMMAND "${CPPBESSOT_DB_PGSQL_CLONE_PROD_TO_PRODDEV_COMMAND}" CACHE STRING
|
set(CPPBESSOT_DB_PGSQL_CLONE_PROD_TO_PRODDEV_COMMAND "${CPPBESSOT_DB_PGSQL_CLONE_PROD_TO_PRODDEV_COMMAND}" CACHE STRING
|
||||||
"Parent-supplied command string that clones the prod PostgreSQL DB into proddev")
|
"Parent-supplied command string that clones the prod PostgreSQL DB into proddev")
|
||||||
|
|
||||||
|
cppbessot_write_runtime_env_file("${CMAKE_BINARY_DIR}/cppbessot.env")
|
||||||
|
|
||||||
if(NOT DEFINED CPPBESSOT_AUTO_ENABLE)
|
if(NOT DEFINED CPPBESSOT_AUTO_ENABLE)
|
||||||
option(CPPBESSOT_AUTO_ENABLE "Auto-register CppBeSSOT targets when this file is included" ON)
|
option(CPPBESSOT_AUTO_ENABLE "Auto-register CppBeSSOT targets when this file is included" ON)
|
||||||
endif()
|
endif()
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
include_guard(GLOBAL)
|
||||||
|
|
||||||
|
function(_cppbessot_dotenv_escape output_var value)
|
||||||
|
set(escaped "${value}")
|
||||||
|
string(REPLACE "\\" "\\\\" escaped "${escaped}")
|
||||||
|
string(REPLACE "\"" "\\\"" escaped "${escaped}")
|
||||||
|
string(REPLACE "\n" "\\n" escaped "${escaped}")
|
||||||
|
string(REPLACE "\r" "\\r" escaped "${escaped}")
|
||||||
|
string(REPLACE "\t" "\\t" escaped "${escaped}")
|
||||||
|
set(${output_var} "${escaped}" PARENT_SCOPE)
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
function(_cppbessot_dotenv_append output_var name value)
|
||||||
|
_cppbessot_dotenv_escape(escaped_value "${value}")
|
||||||
|
set(line "${name}=\"${escaped_value}\"\n")
|
||||||
|
set(${output_var} "${${output_var}}${line}" PARENT_SCOPE)
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
function(cppbessot_write_runtime_env_file output_path)
|
||||||
|
set(env_contents
|
||||||
|
"# Generated by cppbessot during CMake configure. Do not edit.\n")
|
||||||
|
_cppbessot_dotenv_append(env_contents
|
||||||
|
"DB_TARGET" "${DB_TARGET}")
|
||||||
|
_cppbessot_dotenv_append(env_contents
|
||||||
|
"CPPBESSOT_DB_PGSQL_PROD_CONNSTR" "${CPPBESSOT_DB_PGSQL_PROD_CONNSTR}")
|
||||||
|
_cppbessot_dotenv_append(env_contents
|
||||||
|
"CPPBESSOT_DB_PGSQL_DEV_CONNSTR" "${CPPBESSOT_DB_PGSQL_DEV_CONNSTR}")
|
||||||
|
_cppbessot_dotenv_append(env_contents
|
||||||
|
"CPPBESSOT_DB_PGSQL_PRODDEV_CONNSTR" "${CPPBESSOT_DB_PGSQL_PRODDEV_CONNSTR}")
|
||||||
|
_cppbessot_dotenv_append(env_contents
|
||||||
|
"CPPBESSOT_DB_PGSQL_TESTS_CONNSTR" "${CPPBESSOT_DB_PGSQL_TESTS_CONNSTR}")
|
||||||
|
_cppbessot_dotenv_append(env_contents
|
||||||
|
"CPPBESSOT_DB_SQLITE_PROD_PATH" "${CPPBESSOT_DB_SQLITE_PROD_PATH}")
|
||||||
|
_cppbessot_dotenv_append(env_contents
|
||||||
|
"CPPBESSOT_DB_SQLITE_DEV_PATH" "${CPPBESSOT_DB_SQLITE_DEV_PATH}")
|
||||||
|
_cppbessot_dotenv_append(env_contents
|
||||||
|
"CPPBESSOT_DB_SQLITE_PRODDEV_PATH" "${CPPBESSOT_DB_SQLITE_PRODDEV_PATH}")
|
||||||
|
_cppbessot_dotenv_append(env_contents
|
||||||
|
"CPPBESSOT_DB_SQLITE_TESTS_PATH" "${CPPBESSOT_DB_SQLITE_TESTS_PATH}")
|
||||||
|
file(WRITE "${output_path}" "${env_contents}")
|
||||||
|
endfunction()
|
||||||
Reference in New Issue
Block a user