Fixing structure of the project

*Root Project
            |=> shared library called 'components'.
            |=> executable 'examples'.
This commit is contained in:
Achraf k 2022-02-17 12:03:24 +01:00
parent a9281b2a42
commit 0a6c3373ca
3 changed files with 171 additions and 30 deletions

View File

@ -12,21 +12,23 @@ set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Gui REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core5Compat REQUIRED)
add_subdirectory(components)
add_subdirectory(examples)
set(PROJECT_SOURCES
#set(PROJECT_SOURCES
)
#)
if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
qt_add_executable(QtMaterialWidgets
MANUAL_FINALIZATION
${PROJECT_SOURCES}
)
# qt_add_executable(QtMaterialWidgets
# MANUAL_FINALIZATION
# ${PROJECT_SOURCES}
# )
# Define target properties for Android with Qt 6 as:
# set_property(TARGET QtMaterialWidgets APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR
# ${CMAKE_CURRENT_SOURCE_DIR}/android)
@ -45,20 +47,21 @@ else()
endif()
endif()
target_link_libraries(QtMaterialWidgets PRIVATE Qt${QT_VERSION_MAJOR}::Widgets)
target_link_libraries(QtMaterialWidgets PRIVATE Qt${QT_VERSION_MAJOR}::Core)
target_link_libraries(QtMaterialWidgets PRIVATE Qt${QT_VERSION_MAJOR}::Core5Compat)
#target_link_libraries(QtMaterialWidgets PRIVATE Qt${QT_VERSION_MAJOR}::Core)
#target_link_libraries(QtMaterialWidgets PRIVATE Qt${QT_VERSION_MAJOR}::Widgets)
#target_link_libraries(QtMaterialWidgets PRIVATE Qt${QT_VERSION_MAJOR}::Core5Compat)
set_target_properties(QtMaterialWidgets PROPERTIES
MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
MACOSX_BUNDLE TRUE
WIN32_EXECUTABLE TRUE
)
#set_target_properties(QtMaterialWidgets PROPERTIES
# MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com
# MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
# MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
# MACOSX_BUNDLE TRUE
# WIN32_EXECUTABLE TRUE
#)
#file(COPY assets DESTINATION ${CMAKE_BINARY_DIR})
if(QT_VERSION_MAJOR EQUAL 6)
qt_finalize_executable(QtMaterialWidgets)
# qt_finalize_executable(QtMaterialWidgets)
endif()

View File

@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.5)
project(components VERSION 0.1 LANGUAGES CXX)
#project(components VERSION 0.1 LANGUAGES CXX)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
@ -17,6 +17,8 @@ find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core5Compat REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS StateMachine REQUIRED)
# Create a library called "components" which includes the source file "*.cpp".
# The extension is already found. Any number of sources could be listed here.
set(PROJECT_SOURCES
qtmaterialavatar.cpp
lib/qtmaterialstyle.cpp
@ -145,25 +147,18 @@ set(PROJECT_SOURCES
)
if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
qt_add_executable(components
MANUAL_FINALIZATION
${PROJECT_SOURCES}
)
add_library(components SHARED ${PROJECT_SOURCES})
# Define target properties for Android with Qt 6 as:
# set_property(TARGET components APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR
# ${CMAKE_CURRENT_SOURCE_DIR}/android)
# For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation
else()
if(ANDROID)
add_library(components SHARED
${PROJECT_SOURCES}
)
add_library(components SHARED ${PROJECT_SOURCES})
# Define properties for Android with Qt 5 after find_package() calls as:
# set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
else()
add_executable(components
${PROJECT_SOURCES}
)
# add_executable(components ${PROJECT_SOURCES})
endif()
endif()
@ -172,6 +167,11 @@ target_link_libraries(components PRIVATE Qt${QT_VERSION_MAJOR}::Core)
target_link_libraries(components PRIVATE Qt${QT_VERSION_MAJOR}::Core5Compat)
target_link_libraries(components PRIVATE Qt${QT_VERSION_MAJOR}::StateMachine)
# Make sure the compiler can find include files for our components library
# when other libraries or executables link to components
target_include_directories (components PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
set_target_properties(components PROPERTIES
MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
@ -183,5 +183,5 @@ set_target_properties(components PROPERTIES
file(COPY icons DESTINATION ${CMAKE_BINARY_DIR})
if(QT_VERSION_MAJOR EQUAL 6)
qt_finalize_executable(components)
# qt_finalize_executable(components)
endif()

138
examples/CMakeLists.txt Normal file
View File

@ -0,0 +1,138 @@
cmake_minimum_required(VERSION 3.5)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Gui REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core5Compat REQUIRED)
# Add executable called "examples" that is built from the source files
# "*.cpp". The extensions are automatically found.
# add_executable (examples)
set(PROJECT_SOURCES
#sources
main.cpp
mainwindow.cpp
avatarsettingseditor.cpp
badgesettingseditor.cpp
checkboxsettingseditor.cpp
fabsettingseditor.cpp
raisedbuttonsettingseditor.cpp
flatbuttonsettingseditor.cpp
iconbuttonsettingseditor.cpp
progresssettingseditor.cpp
circularprogresssettingseditor.cpp
slidersettingseditor.cpp
radiobuttonsettingseditor.cpp
togglesettingseditor.cpp
textfieldsettingseditor.cpp
tabssettingseditor.cpp
snackbarsettingseditor.cpp
dialogsettingseditor.cpp
drawersettingseditor.cpp
scrollbarsettingseditor.cpp
appbarsettingseditor.cpp
autocompletesettingseditor.cpp
menusettingseditor.cpp
# Headers
mainwindow.h
avatarsettingseditor.h
badgesettingseditor.h
checkboxsettingseditor.h
fabsettingseditor.h
raisedbuttonsettingseditor.h
flatbuttonsettingseditor.h
iconbuttonsettingseditor.h
progresssettingseditor.h
circularprogresssettingseditor.h
slidersettingseditor.h
radiobuttonsettingseditor.h
togglesettingseditor.h
textfieldsettingseditor.h
tabssettingseditor.h
snackbarsettingseditor.h
dialogsettingseditor.h
drawersettingseditor.h
scrollbarsettingseditor.h
appbarsettingseditor.h
autocompletesettingseditor.h
menusettingseditor.h
# Forms
avatarsettingsform.ui
badgesettingsform.ui
checkboxsettingsform.ui
fabsettingsform.ui
flatbuttonsettingsform.ui
iconbuttonsettingsform.ui
progresssettingsform.ui
circularprogresssettingsform.ui
slidersettingsform.ui
snackbarsettingsform.ui
radiobuttonsettingsform.ui
togglesettingsform.ui
textfieldsettingsform.ui
tabssettingsform.ui
dialogsettingsform.ui
drawersettingsform.ui
scrollbarsettingsform.ui
appbarsettingsform.ui
)
if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
qt_add_executable(examples
MANUAL_FINALIZATION
${PROJECT_SOURCES}
)
# Define target properties for Android with Qt 6 as:
# set_property(TARGET examples APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR
# ${CMAKE_CURRENT_SOURCE_DIR}/android)
# For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation
else()
if(ANDROID)
add_library(examples SHARED
${PROJECT_SOURCES}
)
# Define properties for Android with Qt 5 after find_package() calls as:
# set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
else()
add_executable(examples
${PROJECT_SOURCES}
)
endif()
endif()
target_link_libraries(examples PRIVATE Qt${QT_VERSION_MAJOR}::Core)
target_link_libraries(examples PRIVATE Qt${QT_VERSION_MAJOR}::Gui)
target_link_libraries(examples PRIVATE Qt${QT_VERSION_MAJOR}::Widgets)
target_link_libraries(examples PRIVATE Qt${QT_VERSION_MAJOR}::Core5Compat)
# Link the executable to the 'components' library. Since the 'components' library has
# public include directories we will use those link directories when building
# examples
target_link_libraries(examples LINK_PUBLIC components)
set_target_properties(examples PROPERTIES
MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
MACOSX_BUNDLE TRUE
WIN32_EXECUTABLE TRUE
)
file(COPY assets DESTINATION ${CMAKE_BINARY_DIR})
if(QT_VERSION_MAJOR EQUAL 6)
qt_finalize_executable(examples)
endif()