| # Licensed to the Apache Software Foundation (ASF) under one or more |
| # contributor license agreements. See the NOTICE file distributed with |
| # this work for additional information regarding copyright ownership. |
| # The ASF licenses this file to You under the Apache License, Version 2.0 |
| # (the "License"); you may not use this file except in compliance with |
| # the License. You may obtain a copy of the License at |
| # |
| # http://www.apache.org/licenses/LICENSE-2.0 |
| # |
| # Unless required by applicable law or agreed to in writing, software |
| # distributed under the License is distributed on an "AS IS" BASIS, |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| # See the License for the specific language governing permissions and |
| # limitations under the License. |
| #-------------------------------------------- |
| # SQLite build script for amalgamation |
| # |
| # default folder structure as follows |
| # <project root folder> |
| # src/ |
| # |
| #-------------------------------------------- |
| cmake_minimum_required(VERSION 2.8 FATAL_ERROR) |
| |
| set(PROJECT_NAME sqlite) |
| |
| # define project for C language |
| project(${PROJECT_NAME} C) |
| |
| message("Building on: ${CMAKE_SYSTEM_NAME}") |
| |
| option(SQLITE_BUILD_STATIC "Build SQLite static library" ON) |
| option(SQLITE_BUILD_SHARED "Build SQLite shared library" ON) |
| option(WITH_SQLITE_DEBUG "Build SQLite debug features" OFF) |
| option(WITH_SQLITE_MEMDEBUG "Build SQLite memory debug features" OFF) |
| option(WITH_SQLITE_RTREE "Build R*Tree index extension" OFF) |
| |
| set(INSTALL_BIN_DIR "${CMAKE_INSTALL_PREFIX}/bin" CACHE PATH "Installation directory for executables") |
| set(INSTALL_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib" CACHE PATH "Installation directory for libraries") |
| set(INSTALL_INC_DIR "${CMAKE_INSTALL_PREFIX}/include" CACHE PATH "Installation directory for headers") |
| |
| set(SQLITE_WIN_BUILD OFF) |
| if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") |
| set(SQLITE_WIN_BUILD ON) |
| endif() |
| |
| #TODO replace with common checks from root project for -m64, -mt, etc. |
| include(CheckCCompilerFlag) |
| |
| set(CMAKE_REQUIRED_LIBRARIES -m64) |
| check_c_compiler_flag(-m64 CFLAGS_M64_ALLOWED) |
| set(CMAKE_REQUIRED_LIBRARIES) |
| |
| check_c_compiler_flag(-mt CFLAGS_mt_ALLOWED) |
| |
| if (CFLAGS_M64_ALLOWED) |
| set(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS} -m64) |
| add_compile_options(-m64) |
| set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m64") |
| set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -m64") |
| set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -m64") |
| endif() |
| |
| if (CFLAGS_mt_ALLOWED) |
| set(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS} -mt) |
| add_compile_options(-mt) |
| endif() |
| #END TODO replace |
| |
| set(CMAKE_DEBUG_POSTFIX d) |
| |
| # --------------------- |
| # Version detection |
| # --------------------- |
| file(STRINGS "${PROJECT_SOURCE_DIR}/sqlite3.h" _sqlite_api_h_VER_STRING REGEX ".*#define[ ]+SQLITE_VERSION[ ]+") |
| |
| string(REGEX MATCH "[0-9\\.]+" SQLITE_VER_STRING ${_sqlite_api_h_VER_STRING}) |
| string(REGEX MATCHALL "[0-9]+" _sqlite_ver_LIST "${SQLITE_VER_STRING}") |
| list(LENGTH _sqlite_ver_LIST _sqlite_list_len) |
| list(GET _sqlite_ver_LIST 0 SQLITE_VER_MAJOR) |
| list(GET _sqlite_ver_LIST 1 SQLITE_VER_MINOR) |
| list(GET _sqlite_ver_LIST 2 SQLITE_VER_PATCH) |
| if(_sqlite_list_len EQUAL 4) |
| list(GET _sqlite_ver_LIST 3 SQLITE_VER_PATCHLEVEL) |
| message("Patch level: ${SQLITE_VER_PATCHLEVEL}") |
| endif() |
| |
| message("FOUND: SQLite version = ${SQLITE_VER_STRING}") |
| |
| set(SQLITE_DYN_NAME "${PROJECT_NAME}${SQLITE_VER_MAJOR}") |
| set(SQLITE_STATIC_NAME "${SQLITE_DYN_NAME}-static") |
| |
| find_package(Threads REQUIRED) |
| |
| # add include path for project |
| include_directories(${PROJECT_SOURCE_DIR}) |
| |
| set(SRC_LIB_FILE ${PROJECT_SOURCE_DIR}/sqlite${SQLITE_VER_MAJOR}.c) |
| set(SRC_SHELL_FILE ${PROJECT_SOURCE_DIR}/shell.c) |
| file(GLOB HDR_FILES ${PROJECT_SOURCE_DIR}/*.h) |
| |
| # adding compilation flags depending on options |
| if(WITH_SQLITE_DEBUG) |
| add_definitions(-DSQLITE_DEBUG) |
| endif() |
| if(WITH_SQLITE_MEMDEBUG) |
| add_definitions(-DSQLITE_MEMDEBUG) |
| endif() |
| if(WITH_SQLITE_RTREE) |
| add_definitions(-DSQLITE_ENABLE_RTREE) |
| endif() |
| |
| if (SQLITE_BUILD_STATIC) |
| # build static library |
| add_library(${SQLITE_STATIC_NAME} STATIC ${SRC_LIB_FILE}) |
| endif() |
| |
| if (SQLITE_BUILD_SHARED) |
| # build dynamic library |
| add_library(${SQLITE_DYN_NAME} SHARED ${SRC_LIB_FILE}) |
| if (SQLITE_WIN_BUILD) |
| #then we do dll library, so need to export api |
| set_target_properties(${SQLITE_DYN_NAME} PROPERTIES DEFINE_SYMBOL "SQLITE_API=__declspec(dllexport)") |
| endif() |
| endif() |
| |
| # build shell executable |
| add_executable(shell ${SRC_SHELL_FILE}) |
| |
| if (SQLITE_BUILD_SHARED) |
| # preferred is shared library |
| target_link_libraries(shell ${SQLITE_DYN_NAME} ${CMAKE_THREAD_LIBS_INIT} ${CMAKE_DL_LIBS}) |
| elseif(SQLITE_BUILD_STATIC) |
| target_link_libraries(shell ${SQLITE_STATIC_NAME} ${CMAKE_THREAD_LIBS_INIT} ${CMAKE_DL_LIBS}) |
| else() |
| # no static or dynamic option selected |
| message(FATAL_ERROR "either static or dynamic option should be selected") |
| endif() |
| |
| # installation |
| list(APPEND TO_INSTALL shell) |
| if(SQLITE_BUILD_SHARED) |
| list(APPEND TO_INSTALL ${SQLITE_DYN_NAME}) |
| endif() |
| if(SQLITE_BUILD_STATIC) |
| list(APPEND TO_INSTALL ${SQLITE_STATIC_NAME}) |
| endif() |
| |
| install(TARGETS ${TO_INSTALL} |
| RUNTIME DESTINATION "${INSTALL_BIN_DIR}" |
| ARCHIVE DESTINATION "${INSTALL_LIB_DIR}" |
| LIBRARY DESTINATION "${INSTALL_LIB_DIR}" ) |
| install(FILES ${HDR_FILES} DESTINATION "${INSTALL_INC_DIR}") |
| |
| |