Skip to content
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

CMake: SQLITE_OMIT_LOAD_EXTENSION not properly set #495

Open
brt-v opened this issue Dec 9, 2024 · 2 comments
Open

CMake: SQLITE_OMIT_LOAD_EXTENSION not properly set #495

brt-v opened this issue Dec 9, 2024 · 2 comments

Comments

@brt-v
Copy link

brt-v commented Dec 9, 2024

I'm fairly new to this project, so apologies if I'm overlooking something.

The main CMakeList.txt offers a SQLITE_OMIT_LOAD_EXTENSION options and sets it for the SQLiteCpp project (here). However, it does not set it for [sqlite3](https://github.com/SRombauts/SQLiteCpp/tree/master/sqlite3)

So I think that in the sqlite3 CMakeLists.txt this should be added:

if (SQLITE_OMIT_LOAD_EXTENSION)
    target_compile_definitions(sqlite3 PUBLIC SQLITE_OMIT_LOAD_EXTENSION)
    message(STATUS "Compile sqlite3 with SQLITE_OMIT_LOAD_EXTENSION")
endif (SQLITE_OMIT_LOAD_EXTENSION)

Also, a related question: the sqlite documentation lists some Recommended Compile-time Options. Can (some of) these be set in conjunction with SQLiteCpp? What's the best way to do this with CMake?

Thanks!

@UnixY2K
Copy link
Contributor

UnixY2K commented Dec 9, 2024

I think for the first you can submit a PR to get it merged, however you need to check if the found sqlite is the current bundled.

for the second option the same applies if using the bundled sqlite + having an option to change the value (default would be true)

@brt-v
Copy link
Author

brt-v commented Dec 14, 2024

Thanks, I just submitted a PR.

however you need to check if the found sqlite is the current bundled.

the new option is only applied to the bundled sqlite3, so I don't think there's an issue for the case that it isn't bundled.

for the second option the same applies if using the bundled sqlite + having an option to change the value (default would be true)

This makes sense if an sqlite compile option affects SQliteCpp, but if it's doesn't it's quite cumbersome to add an option for every available SQlite setting.

But luckily there's a simpler solution: I can just call target_compile_definitions(sqlite3 PUBLIC ...) directly from my own CMakeLists.txt. I just gave it a quick try with example1 and the following CMakeLists.txt. This works for me (Windows/VS2022):

cmake_minimum_required(VERSION 3.12)

project(SQLiteCpp_ex1)

set(SQLITE_OMIT_LOAD_EXTENSION ON)
add_subdirectory(../../ SQLiteCpp)

add_executable(SQLiteCpp_ex1 main.cpp)

target_compile_definitions(sqlite3 PUBLIC 
    SQLITE_DQS=0
    SQLITE_THREADSAFE=0
    SQLITE_DEFAULT_MEMSTATUS=0
    SQLITE_DEFAULT_WAL_SYNCHRONOUS=1
    SQLITE_LIKE_DOESNT_MATCH_BLOBS
    SQLITE_MAX_EXPR_DEPTH=0
    SQLITE_OMIT_DEPRECATED
    SQLITE_OMIT_PROGRESS_CALLBACK
    SQLITE_OMIT_SHARED_CACHE
    SQLITE_USE_ALLOCA
    SQLITE_STRICT_SUBTYPE=1
    )

target_link_libraries(SQLiteCpp_ex1 PUBLIC SQLiteCpp)

Of SQlite's recommended compile time options, I had to remove a couple:

  • SQLITE_OMIT_DECLTYPE: conflicts with the default SQLITE_ENABLE_COLUMN_METADATA. I quickly tried disabling SQLITE_ENABLE_COLUMN_METADATA but this caused compiler/linker errors.
  • SQLITE_OMIT_AUTOINIT caused a runtime error

But that's fine by me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants