@@ -3,43 +3,80 @@ project(Squirrel)
3
3
4
4
set (BUILD_SHARED_LIBS ON )
5
5
6
- # GoogleTest requires at least C++ 14
7
6
set (CMAKE_CXX_STANDARD 17)
8
7
9
8
set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -g -O2 -fsanitize=address" )
10
9
set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -O3" )
11
10
set (LINK_FLAGS "${LINK_FLAGS} -fsanitize=address" )
12
-
13
11
find_package (PkgConfig)
14
- pkg_check_modules(MySQL REQUIRED mysqlclient>=5.7)
15
12
16
- find_package (PostgreSQL REQUIRED)
13
+ option (ALL "Build all types of database" ON )
14
+ option (SQLITE "Build sqlite" OFF )
15
+ option (MYSQL "Build mysql" OFF )
16
+ option (POSTGRESQL "Build postgresql" OFF )
17
+
18
+ if (SQLITE
19
+ OR MYSQL
20
+ OR POSTGRESQL)
21
+ set (ALL OFF )
22
+ endif ()
23
+
24
+ if (ALL )
25
+ set (SQLITE ON )
26
+ set (MYSQL ON )
27
+ set (POSTGRESQL ON )
28
+ endif ()
29
+
30
+ if (SQLITE)
31
+ list (APPEND DBMS sqlite)
32
+ endif ()
33
+
34
+ if (MYSQL)
35
+ list (APPEND DBMS mysql)
36
+ pkg_check_modules(MySQL REQUIRED mysqlclient>=5.7)
37
+ add_library (mysql_client OBJECT srcs/internal /client/client_mysql.cc)
38
+ target_include_directories (mysql_client PUBLIC ${MySQL_INCLUDE_DIRS}
39
+ srcs/internal /client)
40
+ target_link_libraries (mysql_client PUBLIC ${MySQL_LIBRARIES}
41
+ ${YAML_CPP_LIBRARIES} )
42
+ target_compile_options (mysql_client PRIVATE -fPIC)
43
+ list (APPEND LINK_CLIENT mysql_client)
44
+ list (APPEND CLIENT_DEFINITION __SQUIRREL_MYSQL__)
45
+ endif ()
46
+
47
+ if (POSTGRESQL)
48
+ list (APPEND DBMS postgresql)
49
+ find_package (PostgreSQL REQUIRED)
50
+ add_library (postgresql_client OBJECT
51
+ srcs/internal /client/client_postgresql.cc)
52
+ target_include_directories (postgresql_client PUBLIC ${PostgreSQL_INCLUDE_DIRS}
53
+ srcs/internal /client)
54
+ target_link_libraries (
55
+ postgresql_client PUBLIC ${PostgreSQL_LIBRARIES} ${YAML_CPP_LIBRARIES}
56
+ absl::strings absl::str_format)
57
+ target_compile_options (postgresql_client PRIVATE -fPIC)
58
+ list (APPEND LINK_CLIENT postgresql_client)
59
+ list (APPEND CLIENT_DEFINITION __SQUIRREL_POSTGRESQL__)
60
+ endif ()
17
61
18
62
include (FetchContent)
19
- FetchContent_Declare(
20
- googletest
21
- URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip
22
- )
23
- # For Windows : Prevent overriding the parent project's compiler/linker settings
24
- set (gtest_force_shared_crt
25
- ON
26
- CACHE BOOL "" FORCE)
27
- FetchContent_MakeAvailable(googletest)
28
-
29
- FetchContent_Declare(
30
- yaml-cpp
31
- URL https://github.com/jbeder/yaml-cpp/archive/refs/tags/yaml-cpp-0.7.0.zip)
32
- FetchContent_MakeAvailable(yaml-cpp)
63
+ find_package (yaml-cpp REQUIRED)
64
+ # FetchContent_Declare( ${YAML_CPP_LIBRARIES} URL
65
+ # https://github.com/jbeder/${YAML_CPP_LIBRARIES}/archive/refs/tags/${YAML_CPP_LIBRARIES}-0.7.0.zip)
66
+ # FetchContent_MakeAvailable(${YAML_CPP_LIBRARIES})
67
+ include_directories (${YAML_INCLUDE_DIRS} )
68
+
69
+ # set_target_properties(${YAML_CPP_LIBRARIES} PROPERTIES COMPILE_FLAGS "-w")
33
70
71
+ set (ABSL_PROPAGATE_CXX_STD ON )
72
+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -w" )
34
73
add_subdirectory (third_party/abseil-cpp)
35
- enable_testing ( )
74
+ string (REPLACE " -w" "" CMAKE_CXX_FLAGS " ${CMAKE_CXX_FLAGS} " )
36
75
37
76
set (AFLPP_DIR ${CMAKE_CURRENT_SOURCE_DIR} /AFLplusplus/include )
38
77
39
78
include_directories (${AFLPP_DIR} )
40
79
41
- list (APPEND DBMS sqlite mysql postgresql)
42
-
43
80
foreach (dbms IN LISTS DBMS)
44
81
add_library (
45
82
${dbms} _impl OBJECT
@@ -53,43 +90,38 @@ foreach(dbms IN LISTS DBMS)
53
90
target_include_directories (${dbms} _impl PRIVATE srcs/internal /${dbms} /include
54
91
srcs)
55
92
target_compile_options (${dbms} _impl PRIVATE -fPIC)
56
- target_link_libraries (${dbms} _impl yaml-cpp)
93
+ target_link_libraries (${dbms} _impl ${YAML_CPP_LIBRARIES} absl::strings
94
+ absl::str_format)
57
95
58
96
string (TOUPPER ${dbms} UPPER_CASE_DBMS)
59
97
add_library (${dbms} _mutator SHARED srcs/custom_mutator.cc srcs/db_factory.cc)
60
- target_link_libraries (${dbms} _mutator ${dbms} _impl)
98
+ target_link_libraries (${dbms} _mutator ${dbms} _impl config_validator )
61
99
target_include_directories (${dbms} _mutator PRIVATE srcs/internal /${dbms} srcs)
62
- #target_compile_options(${dbms}_mutator PRIVATE -fPIC)
63
- target_compile_definitions (${dbms} _mutator PRIVATE __SQUIRREL_${UPPER_CASE_DBMS} __)
100
+ # target_compile_options(${dbms}_mutator PRIVATE -fPIC)
101
+ target_compile_definitions (${dbms} _mutator
102
+ PRIVATE __SQUIRREL_${UPPER_CASE_DBMS} __)
64
103
endforeach ()
65
104
66
- add_executable (db_driver srcs/db_driver.cc)
67
- target_link_libraries (db_driver yaml-cpp all_client absl::strings
68
- absl::str_format)
69
-
70
- add_executable (test_client srcs/internal /client/test_client.cc)
71
- target_link_libraries (test_client all_client)
72
- target_include_directories (test_client PUBLIC srcs/internal /client)
73
-
74
- add_library (all_client SHARED srcs/internal /client/client.cc)
75
- target_include_directories (all_client PUBLIC srcs/internal /client)
76
- target_link_libraries (all_client PUBLIC mysql_client postgresql_client)
77
-
78
- # MySQL client
79
- add_library (mysql_client OBJECT srcs/internal /client/client_mysql.cc)
80
- target_include_directories (mysql_client PUBLIC ${MySQL_INCLUDE_DIRS}
81
- srcs/internal /client)
82
- target_link_libraries (mysql_client PUBLIC ${MySQL_LIBRARIES} yaml-cpp)
83
- target_compile_options (mysql_client PRIVATE -fPIC)
84
-
85
- add_library (postgresql_client OBJECT srcs/internal /client/client_postgresql.cc)
86
- target_include_directories (postgresql_client PUBLIC ${PostgreSQL_INCLUDE_DIRS}
87
- srcs/internal /client)
88
- target_link_libraries (postgresql_client PUBLIC ${PostgreSQL_LIBRARIES} yaml-cpp
89
- absl::strings absl::str_format)
90
- target_compile_options (postgresql_client PRIVATE -fPIC)
105
+ if (MYSQL OR POSTGRESQL)
106
+ add_executable (db_driver srcs/db_driver.cc)
107
+ target_link_libraries (db_driver ${YAML_CPP_LIBRARIES} all_client
108
+ absl::strings absl::str_format)
91
109
92
- include (GoogleTest)
93
- # gtest_discover_tests(variable_check_test)
110
+ add_executable (test_client srcs/internal /client/test_client.cc)
111
+ target_link_libraries (test_client all_client ${YAML_CPP_LIBRARIES} )
112
+ target_include_directories (test_client PUBLIC srcs/internal /client)
113
+
114
+ add_library (all_client SHARED srcs/internal /client/client.cc)
115
+ target_include_directories (all_client PUBLIC srcs/internal /client)
116
+ target_link_libraries (all_client PUBLIC ${LINK_CLIENT} )
117
+ target_compile_definitions (all_client PRIVATE ${CLIENT_DEFINITION} )
118
+ endif ()
119
+
120
+ add_library (config_validator OBJECT srcs/utils/config_validate.cc)
121
+ target_link_libraries (config_validator PRIVATE ${YAML_CPP_LIBRARIES}
122
+ absl::strings absl::str_format)
123
+ target_include_directories (config_validator PUBLIC srcs/utils)
124
+ target_compile_options (config_validator PRIVATE -fPIC)
94
125
95
- include (clang-format.cmake)
126
+ include (lint.cmake)
127
+ add_subdirectory (tests)
0 commit comments