Skip to content

Commit e7aa4f4

Browse files
committed
Added options in the root CMakeList.txt to inactivate any optional targets & move back to a single CMakeList.txt
1 parent d6f5029 commit e7aa4f4

File tree

6 files changed

+4890
-65
lines changed

6 files changed

+4890
-65
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
Debug
22
Release
33
build
4+
example1
5+
*.a
46

57
/SQLiteCpp.sln
68
*.ncb

CMakeLists.txt

Lines changed: 95 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,114 @@
1-
# Main CMake file compiling the library itself, examples and tests.
1+
# Main CMake file for compiling the library itself, examples and tests.
22
#
3-
# Copyright (c) 2012-2013 Sebastien Rombauts (sebastien.rombauts@gmail.com)
3+
# Copyright (c) 2012-2014 Sebastien Rombauts (sebastien.rombauts@gmail.com)
44
#
55
# Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt
66
# or copy at http://opensource.org/licenses/MIT)
77

8-
cmake_minimum_required (VERSION 2.6)
9-
project (SQLiteCpp)
8+
cmake_minimum_required(VERSION 2.6)
9+
project(SQLiteCpp)
1010

1111
# Enable the use of SQLite column metadata and Column::getName() method,
12-
# Require that the sqlite3 library is also compiled with this flag.
13-
option (SQLITE_ENABLE_COLUMN_METADATA
14-
"Enable Column::getName(). Require support from sqlite3 library." OFF)
12+
# Require that the sqlite3 library is also compiled with this flag (default under Debian/Ubuntu).
13+
option(SQLITE_ENABLE_COLUMN_METADATA "Enable Column::getName(). Require support from sqlite3 library." ON)
1514
if (SQLITE_ENABLE_COLUMN_METADATA)
16-
add_definitions(-DSQLITE_ENABLE_COLUMN_METADATA)
17-
endif()
15+
add_definitions(-DSQLITE_ENABLE_COLUMN_METADATA)
16+
endif ()
1817

19-
# Enable the user defintion of a assertion_failed() handler.
20-
add_definitions(-DSQLITECPP_ENABLE_ASSERT_HANDLER)
18+
option(SQLITE_ENABLE_ASSERT_HANDLER "Enable the user defintion of a assertion_failed() handler." ON)
19+
if (SQLITE_ENABLE_ASSERT_HANDLER)
20+
# Enable the user defintion of a assertion_failed() handler.
21+
add_definitions(-DSQLITECPP_ENABLE_ASSERT_HANDLER)
22+
endif ()
2123

24+
# Define useful variables to handle OS/Compiler differences
2225
if (MSVC)
23-
# build the SQLite3 C library for Windows (for ease of use)
24-
add_subdirectory (sqlite3)
25-
include_directories ("${PROJECT_SOURCE_DIR}/sqlite3")
26-
# disable Visual Studio warnings for fopen() used in the example
27-
add_definitions (/D_CRT_SECURE_NO_WARNINGS)
26+
set(CPPLINT_ARG_OUTPUT "--output=vs7")
27+
set(CPPCHECK_ARG_TEMPLATE "--template=vs")
28+
set(DEV_NULL "NUL")
29+
# build the SQLite3 C library for Windows (for ease of use)
30+
add_subdirectory(sqlite3)
31+
include_directories("${PROJECT_SOURCE_DIR}/sqlite3")
32+
# disable Visual Studio warnings for fopen() used in the example
33+
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
2834
elseif (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
29-
# GCC flags
30-
add_definitions (-rdynamic -fstack-protector-all -Wall -Wextra -pedantic -Weffc++ -Wformat-security -Winit-self -Wswitch-default -Wswitch-enum -Wfloat-equal -Wundef -Wshadow -Wcast-qual -Wconversion -Wlogical-op -Winline -Wsuggest-attribute=pure -Wsuggest-attribute=const)
35+
set(CPPLINT_ARG_OUTPUT "--output=eclipse")
36+
set(CPPCHECK_ARG_TEMPLATE "--template=gcc")
37+
set(DEV_NULL "/dev/null")
38+
# GCC flags
39+
add_definitions(-rdynamic -fstack-protector-all -Wall -Wextra -pedantic -Weffc++ -Wformat-security -Winit-self -Wswitch-default -Wswitch-enum -Wfloat-equal -Wundef -Wshadow -Wcast-qual -Wconversion -Wlogical-op -Winline -Wsuggest-attribute=pure -Wsuggest-attribute=const)
3140
endif ()
41+
set(CPPLINT_ARG_VERBOSE "--verbose=3")
42+
set(CPPLINT_ARG_LINELENGTH "--linelength=120")
43+
3244

33-
# add a cppcheck target to the "all" target
34-
add_custom_target(cppcheck
35-
ALL
36-
COMMAND cppcheck -j 4 cppcheck --enable=style,portability,performance,information --quiet --template='{file}:{line}: warning: cppcheck: {message} [{severity}/{id}]' src
37-
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
45+
## Core source code ##
46+
47+
# adding a new file require explicittly modifing the CMakeLists.txt
48+
# so that CMake knows that it should rebuild the project (it is best practice)
49+
50+
# list of sources files of the library
51+
set(SQLITECPP_SRC
52+
src/SQLiteC++.h
53+
src/Assertion.h
54+
src/Column.cpp
55+
src/Column.h
56+
src/Database.cpp
57+
src/Database.h
58+
src/Exception.h
59+
src/Statement.cpp
60+
src/Statement.h
61+
src/Transaction.cpp
62+
src/Transaction.h
3863
)
64+
# add sources of the wrapper as a "SQLiteCpp" static library
65+
add_library (SQLiteCpp ${SQLITECPP_SRC})
66+
source_group(src FILES ${SQLITECPP_SRC})
3967

40-
################################################################################
41-
# add the subdirectory containing the CMakeLists.txt of the wrapper library
42-
add_subdirectory (src)
43-
include_directories ("${PROJECT_SOURCE_DIR}/src")
44-
################################################################################
68+
if(UNIX AND (CMAKE_COMPILER_IS_GNUCXX OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang"))
69+
set_target_properties(SQLiteCpp PROPERTIES COMPILE_FLAGS "-fPIC")
70+
endif(UNIX AND (CMAKE_COMPILER_IS_GNUCXX OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang"))
4571

46-
# add the example1 executable, linked with the wrapper library
47-
add_executable (example1 examples/example1/main.cpp)
48-
target_link_libraries (example1 SQLiteCpp sqlite3)
4972

50-
# add a "test" target:
51-
enable_testing ()
73+
# Optional additional targets:
74+
75+
option(SQLITECPP_RUN_CPPLINT "Run cpplint.py tool for Google C++ StyleGuide." OFF)
76+
if (SQLITECPP_RUN_CPPLINT)
77+
# add a cpplint target to the "all" target
78+
add_custom_target(SQLiteCpp_cpplint
79+
ALL
80+
COMMAND python cpplint.py ${CPPLINT_ARG_OUTPUT} ${CPPLINT_ARG_VERBOSE} ${CPPLINT_ARG_LINELENGTH} ${PROJECT_SOURCE_DIR}/${SQLITECPP_SRC}
81+
)
82+
endif()
5283

53-
# does the example1 runs successfully
54-
add_test (Example1Run example1)
84+
option(SQLITECPP_RUN_CPPCHECK "Run cppcheck C++ static analysis tool." ON)
85+
if (SQLITECPP_RUN_CPPCHECK)
86+
# add a cppcheck target to the "all" target
87+
add_custom_target(SQLiteCpp_cppcheck
88+
ALL
89+
COMMAND cppcheck -j 4 cppcheck --enable=style --quiet ${CPPCHECK_ARG_TEMPLATE} ${PROJECT_SOURCE_DIR}/src
90+
)
91+
endif()
92+
93+
option(SQLITECPP_RUN_DOXYGEN "Run Doxygen C++ documentation tool." ON)
94+
if (SQLITECPP_RUN_DOXYGEN)
95+
# add a Doxygen target to the "all" target
96+
add_custom_target(SQLiteCpp_doxygen
97+
ALL
98+
COMMAND doxygen Doxyfile > ${DEV_NULL}
99+
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
100+
)
101+
endif()
102+
103+
option(SQLITECPP_RUN_TESTS "Run test tools." ON)
104+
if (SQLITECPP_RUN_TESTS)
105+
# add the example1 executable, linked with the wrapper library
106+
add_executable(example1 examples/example1/main.cpp)
107+
target_link_libraries(example1 SQLiteCpp sqlite3)
108+
109+
# add a "test" target:
110+
enable_testing()
111+
112+
# does the example1 runs successfully?
113+
add_test(Example1Run example1)
114+
endif()

0 commit comments

Comments
 (0)