diff --git a/CMakeLists.txt b/CMakeLists.txt index 99973095d..1cfa48a77 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 "$<$:>" "$<$:>" "$<$:>" @@ -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()