Skip to content

Commit

Permalink
Improve CMake
Browse files Browse the repository at this point in the history
Moved files to a library so they don't get compiled twice
  • Loading branch information
darktorres committed Feb 7, 2025
1 parent d1bde77 commit b618609
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 20 deletions.
34 changes: 14 additions & 20 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions CMakeSources.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "common.h"
#include "globalproperties.h"
#include "mainwindow.h"
#include "registertypes.h"

#include <QCommandLineParser>
#include <QMessageBox>
Expand All @@ -15,6 +16,8 @@

int main(int argc, char *argv[])
{
registerTypes();

Comment::setVerbosity(-1);

#ifdef Q_OS_WIN
Expand Down
71 changes: 71 additions & 0 deletions app/registertypes.h
Original file line number Diff line number Diff line change
@@ -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<And>();
qRegisterMetaType<AudioBox>();
qRegisterMetaType<Buzzer>();
qRegisterMetaType<Clock>();
qRegisterMetaType<DFlipFlop>();
qRegisterMetaType<DLatch>();
qRegisterMetaType<Demux>();
qRegisterMetaType<Display14>();
qRegisterMetaType<Display7>();
qRegisterMetaType<GraphicElement>();
qRegisterMetaType<IC>();
qRegisterMetaType<InputButton>();
qRegisterMetaType<InputGnd>();
qRegisterMetaType<InputRotary>();
qRegisterMetaType<InputSwitch>();
qRegisterMetaType<InputVcc>();
qRegisterMetaType<JKFlipFlop>();
qRegisterMetaType<Led>();
qRegisterMetaType<Line>();
qRegisterMetaType<Mux>();
qRegisterMetaType<Nand>();
qRegisterMetaType<Node>();
qRegisterMetaType<Nor>();
qRegisterMetaType<Not>();
qRegisterMetaType<Or>();
qRegisterMetaType<QNEConnection>();
qRegisterMetaType<QNEInputPort>();
qRegisterMetaType<QNEOutputPort>();
qRegisterMetaType<SRFlipFlop>();
qRegisterMetaType<SRLatch>();
qRegisterMetaType<TFlipFlop>();
qRegisterMetaType<Text>();
qRegisterMetaType<TruthTable>();
qRegisterMetaType<Xnor>();
qRegisterMetaType<Xor>();
}
3 changes: 3 additions & 0 deletions test/testmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -14,6 +15,8 @@

int main(int argc, char **argv)
{
registerTypes();

Comment::setVerbosity(-1);

QApplication app(argc, argv);
Expand Down

0 comments on commit b618609

Please sign in to comment.