From b61860948fff26b51cb68a972768b6a9adbdff54 Mon Sep 17 00:00:00 2001 From: Rodrigo Torres <5768540+darktorres@users.noreply.github.com> Date: Fri, 7 Feb 2025 13:16:17 -0300 Subject: [PATCH] Improve CMake Moved files to a library so they don't get compiled twice --- CMakeLists.txt | 34 +++++++++------------- CMakeSources.cmake | 1 + app/main.cpp | 3 ++ app/registertypes.h | 71 +++++++++++++++++++++++++++++++++++++++++++++ test/testmain.cpp | 3 ++ 5 files changed, 92 insertions(+), 20 deletions(-) create mode 100644 app/registertypes.h diff --git a/CMakeLists.txt b/CMakeLists.txt index cab9412b..4d1876ae 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -65,17 +65,24 @@ include_directories( app/nodes ) -# ========= APP =================================== +# ========= LIB =================================== -add_executable(wiredpanda - app/main.cpp +add_library(wiredpanda_lib STATIC ${SOURCES} ${HEADERS} ${FORMS} - ${RESOURCES_RCC} ) -target_link_libraries(wiredpanda PRIVATE ${QT_LIBS}) +target_link_libraries(wiredpanda_lib PUBLIC ${QT_LIBS}) + +if(MSVC) + target_precompile_headers(wiredpanda_lib PRIVATE pch.h) +endif() + +# ========= APP =================================== + +add_executable(wiredpanda app/main.cpp ${RESOURCES_RCC}) +target_link_libraries(wiredpanda PRIVATE wiredpanda_lib) if(WIN32) set(WINDOWS_APP_NAME "wiRedPanda - Logic Circuit Simulator") @@ -91,26 +98,13 @@ if(WIN32) endif() endif() -if(MSVC) - target_precompile_headers(wiredpanda PRIVATE pch.h) -endif() - # ========= TESTS =================================== file(GLOB_RECURSE TEST_SOURCES "test/*.cpp") file(GLOB_RECURSE TEST_HEADERS "test/*.h") -add_executable(test - ${TEST_SOURCES} - ${TEST_HEADERS} - ${SOURCES} - ${HEADERS} - ${FORMS} - ${RESOURCES_RCC} -) - -target_link_libraries(test PRIVATE ${QT_LIBS}) -target_precompile_headers(test PRIVATE pch.h) +add_executable(test ${TEST_SOURCES} ${TEST_HEADERS} ${RESOURCES_RCC}) +target_link_libraries(test PRIVATE wiredpanda_lib) target_compile_definitions(test PRIVATE CURRENTDIR=${CMAKE_CURRENT_SOURCE_DIR}/test) if(MSVC) diff --git a/CMakeSources.cmake b/CMakeSources.cmake index c0e4596e..2ef50445 100644 --- a/CMakeSources.cmake +++ b/CMakeSources.cmake @@ -105,6 +105,7 @@ set(HEADERS ${CMAKE_CURRENT_LIST_DIR}/app/nodes/qneconnection.h ${CMAKE_CURRENT_LIST_DIR}/app/nodes/qneport.h ${CMAKE_CURRENT_LIST_DIR}/app/recentfiles.h + ${CMAKE_CURRENT_LIST_DIR}/app/registertypes.h ${CMAKE_CURRENT_LIST_DIR}/app/scene.h ${CMAKE_CURRENT_LIST_DIR}/app/serialization.h ${CMAKE_CURRENT_LIST_DIR}/app/settings.h diff --git a/app/main.cpp b/app/main.cpp index 037a44da..2a4e4c37 100644 --- a/app/main.cpp +++ b/app/main.cpp @@ -5,6 +5,7 @@ #include "common.h" #include "globalproperties.h" #include "mainwindow.h" +#include "registertypes.h" #include #include @@ -15,6 +16,8 @@ int main(int argc, char *argv[]) { + registerTypes(); + Comment::setVerbosity(-1); #ifdef Q_OS_WIN diff --git a/app/registertypes.h b/app/registertypes.h new file mode 100644 index 00000000..f129a967 --- /dev/null +++ b/app/registertypes.h @@ -0,0 +1,71 @@ +#include "and.h" +#include "audiobox.h" +#include "buzzer.h" +#include "clock.h" +#include "demux.h" +#include "dflipflop.h" +#include "display_14.h" +#include "display_7.h" +#include "dlatch.h" +#include "ic.h" +#include "inputbutton.h" +#include "inputgnd.h" +#include "inputrotary.h" +#include "inputswitch.h" +#include "inputvcc.h" +#include "jkflipflop.h" +#include "led.h" +#include "line.h" +#include "mux.h" +#include "nand.h" +#include "node.h" +#include "nor.h" +#include "not.h" +#include "or.h" +#include "qneconnection.h" +#include "qneport.h" +#include "srflipflop.h" +#include "srlatch.h" +#include "text.h" +#include "tflipflop.h" +#include "truth_table.h" +#include "xnor.h" +#include "xor.h" + +inline void registerTypes() { + qRegisterMetaType(); + qRegisterMetaType(); + qRegisterMetaType(); + qRegisterMetaType(); + qRegisterMetaType(); + qRegisterMetaType(); + qRegisterMetaType(); + qRegisterMetaType(); + qRegisterMetaType(); + qRegisterMetaType(); + qRegisterMetaType(); + qRegisterMetaType(); + qRegisterMetaType(); + qRegisterMetaType(); + qRegisterMetaType(); + qRegisterMetaType(); + qRegisterMetaType(); + qRegisterMetaType(); + qRegisterMetaType(); + qRegisterMetaType(); + qRegisterMetaType(); + qRegisterMetaType(); + qRegisterMetaType(); + qRegisterMetaType(); + qRegisterMetaType(); + qRegisterMetaType(); + qRegisterMetaType(); + qRegisterMetaType(); + qRegisterMetaType(); + qRegisterMetaType(); + qRegisterMetaType(); + qRegisterMetaType(); + qRegisterMetaType(); + qRegisterMetaType(); + qRegisterMetaType(); +} diff --git a/test/testmain.cpp b/test/testmain.cpp index 7c80f4e9..d00bf2fa 100644 --- a/test/testmain.cpp +++ b/test/testmain.cpp @@ -2,6 +2,7 @@ // SPDX-License-Identifier: GPL-3.0-or-later #include "common.h" +#include "registertypes.h" #include "testcommands.h" #include "testelements.h" #include "testfiles.h" @@ -14,6 +15,8 @@ int main(int argc, char **argv) { + registerTypes(); + Comment::setVerbosity(-1); QApplication app(argc, argv);