Switched to CMakeLists.txt per directory but most detecting is still done in
global one. Includes and libraries are properly propagated using PUBLIC/INTERFACE so we do not have to repeat dependencies.
This commit is contained in:
parent
7c4e8e95e8
commit
f32b7370dc
6 changed files with 216 additions and 138 deletions
|
|
@ -1,159 +1,62 @@
|
|||
cmake_minimum_required(VERSION 3.1.0)
|
||||
project(pglaball)
|
||||
cmake_minimum_required(VERSION 3.2 FATAL_ERROR)
|
||||
project(pglaball VERSION 0.1 LANGUAGES CXX)
|
||||
|
||||
set (CMAKE_PREFIX_PATH /usr/lib/x86_64-linux-gnu/qt5/mkspecs/features/data/cmake)
|
||||
set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
|
||||
|
||||
find_package(PkgConfig REQUIRED)
|
||||
|
||||
# include(CheckCXXCompilerFlag)
|
||||
#
|
||||
# # Check for standard to use
|
||||
# check_cxx_compiler_flag(-std=c++17 HAVE_FLAG_STD_CXX17)
|
||||
# if(HAVE_FLAG_STD_CXX17)
|
||||
# # Have -std=c++17, use it
|
||||
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
|
||||
# else()
|
||||
# check_cxx_compiler_flag(-std=c++1z HAVE_FLAG_STD_CXX1Z)
|
||||
# if(HAVE_FLAG_STD_CXX1Z)
|
||||
# # Have -std=c++1z, use it
|
||||
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1z")
|
||||
# else()
|
||||
# check_cxx_compiler_flag(-std=c++14 HAVE_FLAG_STD_CXX14)
|
||||
# if(HAVE_FLAG_STD_CXX14)
|
||||
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
|
||||
# endif()
|
||||
#
|
||||
# # And so on and on...
|
||||
# endif()
|
||||
# endif()
|
||||
# Must use GNUInstallDirs to install libraries into correct
|
||||
# locations on all platforms.
|
||||
include(GNUInstallDirs)
|
||||
|
||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||
set(CMAKE_CXX_STANDARD 14)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
add_compile_options( -Wall -fpic -march=native )
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Og")
|
||||
# set(CMAKE_CXX_STANDARD 14)
|
||||
# set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
# Find includes in corresponding build directories
|
||||
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||
# Instruct CMake to run moc automatically when needed.
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
set(CMAKE_AUTOUIC ON)
|
||||
set(CMAKE_AUTORCC ON)
|
||||
|
||||
pkg_check_modules(Botan REQUIRED botan-2)
|
||||
include_directories( ${Botan_INCLUDE_DIRS} )
|
||||
pkg_check_modules(Pq REQUIRED libpq)
|
||||
include_directories( ${Pq_INCLUDE_DIRS} )
|
||||
find_package(Botan REQUIRED)
|
||||
add_library(botan UNKNOWN IMPORTED)
|
||||
set_property(TARGET botan PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${BOTAN_INCLUDE_DIRS})
|
||||
set_property(TARGET botan PROPERTY IMPORTED_LOCATION ${BOTAN_LIBRARIES})
|
||||
|
||||
find_package(PostgreSQL REQUIRED)
|
||||
add_library(postgresql UNKNOWN IMPORTED)
|
||||
set_property(TARGET postgresql PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${PostgreSQL_INCLUDE_DIRS})
|
||||
set_property(TARGET postgresql PROPERTY IMPORTED_LOCATION ${PostgreSQL_LIBRARIES})
|
||||
|
||||
find_package(Qt5Widgets 5.7 REQUIRED)
|
||||
include_directories( ${Qt5Widgets_INCLUDE_DIRS} )
|
||||
add_library(Qt5Widgets INTERFACE IMPORTED)
|
||||
set_property(TARGET Qt5Widgets PROPERTY
|
||||
INTERFACE_INCLUDE_DIRECTORIES ${Qt5Widgets_INCLUDE_DIRS})
|
||||
|
||||
find_package(fmt 4.0 REQUIRED)
|
||||
include_directories( ${fmt_INCLUDE_DIRS} )
|
||||
|
||||
#find_package(Libevent 2.0 REQUIRED)
|
||||
#include_directories( ${Libevent_INCLUDE_DIRS} )
|
||||
find_package(Fmt 4.0 REQUIRED)
|
||||
add_library(fmt INTERFACE IMPORTED)
|
||||
set_property(TARGET fmt PROPERTY
|
||||
INTERFACE_INCLUDE_DIRECTORIES ${fmt_INCLUDE_DIRS})
|
||||
|
||||
find_package(Boost 1.63 COMPONENTS system REQUIRED )
|
||||
include_directories( ${Boost_INCLUDE_DIRS} )
|
||||
add_library(boost INTERFACE IMPORTED)
|
||||
set_property(TARGET boost PROPERTY
|
||||
INTERFACE_INCLUDE_DIRECTORIES ${Boost_INCLUDE_DIR})
|
||||
|
||||
add_library(boost-system SHARED IMPORTED)
|
||||
set_property(TARGET boost-system PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${Boost_INCLUDE_DIRS})
|
||||
set_property(TARGET boost-system PROPERTY IMPORTED_LOCATION ${Boost_SYSTEM_LIBRARY})
|
||||
|
||||
find_package(GTest REQUIRED)
|
||||
add_library(gtest UNKNOWN IMPORTED)
|
||||
set_property(TARGET gtest PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${GTEST_INCLUDE_DIRS})
|
||||
set_property(TARGET gtest PROPERTY IMPORTED_LOCATION ${GTEST_LIBRARIES})
|
||||
|
||||
|
||||
add_library(core STATIC
|
||||
core/BackupFormatModel.cpp
|
||||
core/CsvWriter.cpp
|
||||
core/my_boost_assert_handler.cpp
|
||||
core/PasswordManager.cpp
|
||||
core/SqlLexer.cpp)
|
||||
|
||||
add_library(pgsql STATIC
|
||||
pgsql/Pgsql_Connection.cpp
|
||||
pgsql/Pgsql_Params.cpp
|
||||
pgsql/Pgsql_Result.cpp
|
||||
pgsql/Pgsql_Row.cpp
|
||||
pgsql/Pgsql_Value.cpp)
|
||||
|
||||
add_executable(pglab
|
||||
pglab/ASyncDBConnection.cpp
|
||||
pglab/ASyncWindow.cpp
|
||||
pglab/BackupDialog.cpp
|
||||
pglab/BackupRestore.cpp
|
||||
pglab/ConnectionConfig.cpp
|
||||
pglab/ConnectionList.cpp
|
||||
pglab/ConnectionListModel.cpp
|
||||
pglab/ConnectionManagerWindow.cpp
|
||||
pglab/DatabaseInspectorWidget.cpp
|
||||
pglab/DatabasesTableModel.cpp
|
||||
pglab/DatabaseWindow.cpp
|
||||
pglab/ExplainTreeModelItem.cpp
|
||||
pglab/GlobalIoService.cpp
|
||||
pglab/jsoncpp.cpp
|
||||
pglab/main.cpp
|
||||
pglab/MainWindow.cpp
|
||||
pglab/MasterController.cpp
|
||||
pglab/OpenDatabase.cpp
|
||||
pglab/ParamListModel.cpp
|
||||
pglab/ParamTypeDelegate.cpp
|
||||
pglab/PgAuthIdContainer.cpp
|
||||
pglab/PgAuthId.cpp
|
||||
pglab/PgClass.cpp
|
||||
pglab/PgDatabaseCatalogue.cpp
|
||||
pglab/PgDatabaseContainer.cpp
|
||||
pglab/PgDatabase.cpp
|
||||
pglab/PgNamespace.cpp
|
||||
pglab/PgTypeContainer.cpp
|
||||
pglab/PgType.cpp
|
||||
pglab/ProcessStdioWidget.cpp
|
||||
pglab/QueryExplainModel.cpp
|
||||
pglab/QueryResultModel.cpp
|
||||
pglab/QueryTab.cpp
|
||||
pglab/RolesTableModel.cpp
|
||||
pglab/ServerWindow.cpp
|
||||
pglab/SqlSyntaxHighlighter.cpp
|
||||
pglab/stopwatch.cpp
|
||||
pglab/tsqueue.cpp
|
||||
pglab/tuplesresultwidget.cpp
|
||||
pglab/TypeSelectionItemModel.cpp
|
||||
pglab/util.cpp
|
||||
pglab/resources.qrc
|
||||
)
|
||||
|
||||
target_include_directories(pglab PRIVATE
|
||||
./core
|
||||
./pgsql
|
||||
)
|
||||
|
||||
target_link_libraries( pglab
|
||||
core
|
||||
pgsql
|
||||
${Boost_LIBRARIES}
|
||||
Qt5::Widgets
|
||||
${Pq_LIBRARIES}
|
||||
${Botan_LIBRARIES}
|
||||
pthread
|
||||
)
|
||||
|
||||
add_executable(runtests
|
||||
tests/main.cpp
|
||||
tests/tst_CsvWriter.cpp
|
||||
tests/tst_expected.cpp
|
||||
tests/tst_PasswordManager.cpp
|
||||
tests/tst_scopeguard.cpp
|
||||
tests/tst_SqlLexer.cpp
|
||||
)
|
||||
|
||||
target_include_directories(runtests PRIVATE ./core ${GTEST_INCLUDE_DIRS})
|
||||
target_link_libraries(runtests
|
||||
core
|
||||
${GTEST_LIBRARIES}
|
||||
${Botan_LIBRARIES}
|
||||
Qt5::Widgets
|
||||
pthread
|
||||
)
|
||||
|
||||
find_package(Threads)
|
||||
|
||||
enable_testing()
|
||||
add_test(tests runtests)
|
||||
|
||||
add_subdirectory(core)
|
||||
add_subdirectory(pgsql)
|
||||
add_subdirectory(pglab)
|
||||
add_subdirectory(tests)
|
||||
|
||||
|
||||
|
|
|
|||
46
src/cmake/Modules/FindBotan.cmake
Normal file
46
src/cmake/Modules/FindBotan.cmake
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
# - Try to find the Botan library
|
||||
#
|
||||
# Once done this will define
|
||||
#
|
||||
# BOTAN_FOUND - System has Botan
|
||||
# BOTAN_INCLUDE_DIR - The Botan include directory
|
||||
# BOTAN_LIBRARIES - The libraries needed to use Botan
|
||||
# BOTAN_DEFINITIONS - Compiler switches required for using Botan
|
||||
|
||||
IF (BOTAN_INCLUDE_DIR AND BOTAN_LIBRARY)
|
||||
# in cache already
|
||||
SET(Botan_FIND_QUIETLY TRUE)
|
||||
ENDIF (BOTAN_INCLUDE_DIR AND BOTAN_LIBRARY)
|
||||
|
||||
IF (NOT WIN32)
|
||||
# try using pkg-config to get the directories and then use these values
|
||||
# in the FIND_PATH() and FIND_LIBRARY() calls
|
||||
# also fills in BOTAN_DEFINITIONS, although that isn't normally useful
|
||||
FIND_PACKAGE(PkgConfig)
|
||||
PKG_SEARCH_MODULE(PC_BOTAN botan-2)
|
||||
SET(BOTAN_DEFINITIONS ${PC_BOTAN_CFLAGS})
|
||||
ENDIF (NOT WIN32)
|
||||
|
||||
FIND_PATH(BOTAN_INCLUDE_DIR botan/botan.h
|
||||
HINTS
|
||||
${PC_BOTAN_INCLUDEDIR}
|
||||
${PC_BOTAN_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
FIND_LIBRARY(BOTAN_LIBRARY NAMES ${PC_BOTAN_LIBRARIES}
|
||||
HINTS
|
||||
${PC_BOTAN_LIBDIR}
|
||||
${PC_BOTAN_LIBRARY_DIRS}
|
||||
)
|
||||
|
||||
MARK_AS_ADVANCED(BOTAN_INCLUDE_DIR BOTAN_LIBRARY)
|
||||
|
||||
# handle the QUIETLY and REQUIRED arguments and set BOTAN_FOUND to TRUE if
|
||||
# all listed variables are TRUE
|
||||
INCLUDE(FindPackageHandleStandardArgs)
|
||||
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Botan DEFAULT_MSG BOTAN_LIBRARY BOTAN_INCLUDE_DIR)
|
||||
|
||||
IF(BOTAN_FOUND)
|
||||
SET(BOTAN_LIBRARIES ${BOTAN_LIBRARY})
|
||||
SET(BOTAN_INCLUDE_DIRS ${BOTAN_INCLUDE_DIR})
|
||||
ENDIF()
|
||||
23
src/core/CMakeLists.txt
Normal file
23
src/core/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
set(CMAKE_AUTOMOC ON)
|
||||
|
||||
add_library(core STATIC
|
||||
BackupFormatModel.cpp
|
||||
CsvWriter.cpp
|
||||
my_boost_assert_handler.cpp
|
||||
PasswordManager.cpp
|
||||
SqlLexer.cpp)
|
||||
|
||||
target_link_libraries(core PUBLIC
|
||||
botan
|
||||
Qt5::Core
|
||||
)
|
||||
|
||||
target_include_directories(core INTERFACE
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
|
||||
)
|
||||
|
||||
set_target_properties(core PROPERTIES
|
||||
CXX_STANDARD 14
|
||||
CXX_STANDARD_REQUIRED ON
|
||||
POSITION_INDEPENDENT_CODE True
|
||||
)
|
||||
68
src/pglab/CMakeLists.txt
Normal file
68
src/pglab/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
cmake_minimum_required(VERSION 3.2)
|
||||
project(pglab)
|
||||
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
set(CMAKE_AUTOUIC ON)
|
||||
set(CMAKE_AUTORCC ON)
|
||||
|
||||
add_executable(pglab
|
||||
ASyncDBConnection.cpp
|
||||
ASyncWindow.cpp
|
||||
BackupDialog.cpp
|
||||
BackupRestore.cpp
|
||||
ConnectionConfig.cpp
|
||||
ConnectionList.cpp
|
||||
ConnectionListModel.cpp
|
||||
ConnectionManagerWindow.cpp
|
||||
DatabaseInspectorWidget.cpp
|
||||
DatabasesTableModel.cpp
|
||||
DatabaseWindow.cpp
|
||||
ExplainTreeModelItem.cpp
|
||||
GlobalIoService.cpp
|
||||
jsoncpp.cpp
|
||||
main.cpp
|
||||
MainWindow.cpp
|
||||
MasterController.cpp
|
||||
OpenDatabase.cpp
|
||||
ParamListModel.cpp
|
||||
ParamTypeDelegate.cpp
|
||||
PgAuthIdContainer.cpp
|
||||
PgAuthId.cpp
|
||||
PgClass.cpp
|
||||
PgDatabaseCatalogue.cpp
|
||||
PgDatabaseContainer.cpp
|
||||
PgDatabase.cpp
|
||||
PgNamespace.cpp
|
||||
PgTypeContainer.cpp
|
||||
PgType.cpp
|
||||
ProcessStdioWidget.cpp
|
||||
QueryExplainModel.cpp
|
||||
QueryResultModel.cpp
|
||||
QueryTab.cpp
|
||||
RolesTableModel.cpp
|
||||
ServerWindow.cpp
|
||||
SqlSyntaxHighlighter.cpp
|
||||
stopwatch.cpp
|
||||
tsqueue.cpp
|
||||
tuplesresultwidget.cpp
|
||||
TypeSelectionItemModel.cpp
|
||||
util.cpp
|
||||
resources.qrc
|
||||
)
|
||||
|
||||
set_target_properties(pglab PROPERTIES
|
||||
CXX_STANDARD 14
|
||||
CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
if(CMAKE_COMPILER_IS_GNUCXX)
|
||||
# target_compile_options(pglab PRIVATE -Wall -fpic -march=native )
|
||||
# set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Og")
|
||||
endif()
|
||||
|
||||
target_link_libraries( pglab
|
||||
core
|
||||
pgsql
|
||||
boost-system
|
||||
Qt5::Widgets
|
||||
pthread
|
||||
)
|
||||
22
src/pgsql/CMakeLists.txt
Normal file
22
src/pgsql/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
|
||||
add_library(pgsql STATIC
|
||||
Pgsql_Connection.cpp
|
||||
Pgsql_Params.cpp
|
||||
Pgsql_Result.cpp
|
||||
Pgsql_Row.cpp
|
||||
Pgsql_Value.cpp)
|
||||
|
||||
target_link_libraries(pgsql PUBLIC
|
||||
postgresql
|
||||
Qt5::Core
|
||||
)
|
||||
|
||||
target_include_directories(pgsql INTERFACE
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
|
||||
)
|
||||
|
||||
set_target_properties(pgsql PROPERTIES
|
||||
CXX_STANDARD 14
|
||||
CXX_STANDARD_REQUIRED ON
|
||||
POSITION_INDEPENDENT_CODE True
|
||||
)
|
||||
16
src/tests/CMakeLists.txt
Normal file
16
src/tests/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
add_executable(runtests
|
||||
main.cpp
|
||||
tst_CsvWriter.cpp
|
||||
tst_expected.cpp
|
||||
tst_PasswordManager.cpp
|
||||
tst_scopeguard.cpp
|
||||
tst_SqlLexer.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(runtests
|
||||
core
|
||||
gtest
|
||||
Threads::Threads
|
||||
)
|
||||
|
||||
add_test(tests runtests)
|
||||
Loading…
Add table
Add a link
Reference in a new issue