mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-10-13 16:34:14 +02:00
Build the application's code once as an object library
The executable compiled every source file itself, so a test could only reach the application's classes by listing their .cpp files one by one, which stops working as soon as a class needs a folio, its view or the editor window -- that pulls in nearly everything. The sources (except main.cpp) and the two .qrc files now build once as qelectrotech_objects, an OBJECT library; the executable is main.cpp linked with it. Its link libraries and include folders are PUBLIC, and it passes on this directory's compile definitions, so a target in tests/ that links it compiles and links like the application. lupdate's targets scan the library (main.cpp has no tr() text). The executable, its compile flags and what it saves do not change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+30
-17
@@ -146,6 +146,25 @@ endif()
|
||||
# als laatse
|
||||
include(cmake/define_definitions.cmake)
|
||||
|
||||
# The application's code, compiled once, as an object library: the
|
||||
# executable is main.cpp linked with it, and tests that need the real
|
||||
# classes (a folio, its view, the editor window) link it too.
|
||||
set(QET_MAIN_FILE ${QET_DIR}/sources/main.cpp)
|
||||
list(REMOVE_ITEM QET_SRC_FILES ${QET_MAIN_FILE})
|
||||
add_library(
|
||||
${PROJECT_NAME}_objects
|
||||
OBJECT
|
||||
${QET_RES_FILES}
|
||||
${QET_SRC_FILES}
|
||||
${QET_DIR}/qelectrotech.qrc
|
||||
${QET_DIR}/ico/icon-themes.qrc
|
||||
)
|
||||
# The definitions above are set for this whole directory; a test target
|
||||
# lives in tests/ and gets them from here, through the library.
|
||||
get_directory_property(QET_DIRECTORY_DEFINITIONS COMPILE_DEFINITIONS)
|
||||
target_compile_definitions(${PROJECT_NAME}_objects
|
||||
INTERFACE ${QET_DIRECTORY_DEFINITIONS})
|
||||
|
||||
# On Windows, WIN32 sets /SUBSYSTEM:WINDOWS to suppress the console window.
|
||||
# Qt automatically links qtmain.lib which provides the WinMain entry point,
|
||||
# so no source code change is needed.
|
||||
@@ -153,11 +172,8 @@ if(WIN32)
|
||||
add_executable(
|
||||
${PROJECT_NAME}
|
||||
WIN32
|
||||
${QET_RES_FILES}
|
||||
${QET_SRC_FILES}
|
||||
${QET_MAIN_FILE}
|
||||
${QM_FILES}
|
||||
${QET_DIR}/qelectrotech.qrc
|
||||
${QET_DIR}/ico/icon-themes.qrc
|
||||
)
|
||||
# Our own manifest (it declares longPathAware). MSVC merges a .manifest
|
||||
# listed as a source; MinGW needs it embedded through a resource file,
|
||||
@@ -174,13 +190,11 @@ if(WIN32)
|
||||
else()
|
||||
add_executable(
|
||||
${PROJECT_NAME}
|
||||
${QET_RES_FILES}
|
||||
${QET_SRC_FILES}
|
||||
${QET_MAIN_FILE}
|
||||
${QM_FILES}
|
||||
${QET_DIR}/qelectrotech.qrc
|
||||
${QET_DIR}/ico/icon-themes.qrc
|
||||
)
|
||||
endif()
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE ${PROJECT_NAME}_objects)
|
||||
|
||||
if(QET_SPACEMOUSE_BACKEND_SPNAV_ENABLED)
|
||||
list(APPEND QET_SPACEMOUSE_LIBRARIES PkgConfig::SPNAV)
|
||||
@@ -249,7 +263,7 @@ elseif(Qt6_VERSION VERSION_LESS "6.7")
|
||||
|
||||
# Automatically creates the update_translations umbrella target.
|
||||
qt_add_lupdate(
|
||||
${PROJECT_NAME}
|
||||
${PROJECT_NAME}_objects
|
||||
TS_FILES ${TS_FILES}
|
||||
)
|
||||
|
||||
@@ -262,7 +276,7 @@ else()
|
||||
)
|
||||
|
||||
qt_add_lupdate(
|
||||
SOURCE_TARGETS ${PROJECT_NAME}
|
||||
SOURCE_TARGETS ${PROJECT_NAME}_objects
|
||||
TS_FILES ${TS_FILES}
|
||||
LUPDATE_TARGET update_translations
|
||||
NO_GLOBAL_TARGET
|
||||
@@ -288,7 +302,7 @@ if(QET_ENABLE_PCH)
|
||||
"QET_ENABLE_PCH needs CMake 3.16 or newer (found ${CMAKE_VERSION}); "
|
||||
"building without precompiled headers.")
|
||||
else()
|
||||
target_precompile_headers(${PROJECT_NAME} PRIVATE
|
||||
target_precompile_headers(${PROJECT_NAME}_objects PRIVATE
|
||||
"$<$<COMPILE_LANGUAGE:CXX>:<QtCore/QtCore$<ANGLE-R>>"
|
||||
"$<$<COMPILE_LANGUAGE:CXX>:<QtGui/QtGui$<ANGLE-R>>"
|
||||
"$<$<COMPILE_LANGUAGE:CXX>:<QtWidgets/QtWidgets$<ANGLE-R>>"
|
||||
@@ -299,9 +313,8 @@ if(QET_ENABLE_PCH)
|
||||
endif()
|
||||
|
||||
target_link_libraries(
|
||||
${PROJECT_NAME}
|
||||
${PROJECT_NAME}_objects
|
||||
PUBLIC
|
||||
PRIVATE
|
||||
pugixml::pugixml
|
||||
SingleApplication::SingleApplication
|
||||
SQLite3::SQLite3
|
||||
@@ -311,8 +324,8 @@ target_link_libraries(
|
||||
)
|
||||
|
||||
target_include_directories(
|
||||
${PROJECT_NAME}
|
||||
PRIVATE
|
||||
${PROJECT_NAME}_objects
|
||||
PUBLIC
|
||||
${QET_DIR}/sources/titleblock
|
||||
${QET_DIR}/sources/ui
|
||||
${QET_DIR}/sources/qetgraphicsitem
|
||||
@@ -349,8 +362,8 @@ target_include_directories(
|
||||
|
||||
if(NOT BUILD_WITH_KF)
|
||||
target_include_directories(
|
||||
${PROJECT_NAME}
|
||||
PRIVATE
|
||||
${PROJECT_NAME}_objects
|
||||
PUBLIC
|
||||
${QET_DIR}/sources/ui/nokde
|
||||
)
|
||||
endif()
|
||||
|
||||
Reference in New Issue
Block a user