Skip to content

Commit

Permalink
Split cmake files between core and gui
Browse files Browse the repository at this point in the history
  • Loading branch information
MickaelG committed Mar 30, 2018
1 parent 6682ff0 commit a1b94ed
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 63 deletions.
66 changes: 4 additions & 62 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,69 +7,11 @@ enable_testing()
set (CMAKE_CXX_STANDARD 14)
set (CMAKE_CXX_STANDARD_REQUIRED ON)

# Find includes in corresponding build directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)
include_directories( ${CMAKE_SOURCE_DIR}/src/core/ ${CMAKE_SOURCE_DIR}/lib/
${CMAKE_SOURCE_DIR}/src/gui/ ${CMAKE_SOURCE_DIR}/src/gui/gui_widgets )
# Instruct CMake to run moc automatically when needed.
set(CMAKE_AUTOMOC ON)

find_package(Boost 1.53 COMPONENTS date_time filesystem system unit_test_framework REQUIRED)

find_package(Qt5Widgets 5.5)

file(GLOB WIDGETS_SRC src/gui/gui_widgets/*.cpp)
file(GLOB GUI_SRC src/gui/*.cpp)
file(GLOB CORE_SRC src/core/*.cpp lib/pugixml.cpp)

set( qrc_outfile ${CMAKE_CURRENT_BINARY_DIR}/qrc_tomate.cxx)

file(GLOB ui_FORMS src/gui/gui_widgets/*.ui src/gui/mainwindow.ui)
QT5_WRAP_UI(ui_FORMS_HEADERS ${ui_FORMS})

add_executable(tomate_gui ${CORE_SRC} ${GUI_SRC} ${WIDGETS_SRC} src/main.cpp ${qrc_outfile} ${ui_FORMS_HEADERS})
#qt4_use_modules(tomate_gui Widgets)
target_link_libraries(tomate_gui boost_date_time boost_filesystem boost_system)
QT5_USE_MODULES(tomate_gui Widgets)
add_subdirectory(lib)
add_subdirectory(src/core)
add_subdirectory(src/gui)

set (CORE_TEST_SRC src/test/test.cpp src/test/testgeometry.cpp)
add_executable(tomate_test ${CORE_SRC} ${CORE_TEST_SRC})
target_link_libraries(tomate_test boost_unit_test_framework boost_date_time)
QT5_USE_MODULES(tomate_test Core)
add_test(core tomate_test)

add_executable(tomate_test_gui src/test/test_gui.cpp ${CORE_SRC} ${GUI_SRC} ${WIDGETS_SRC} ${ui_FORMS_HEADERS})
target_link_libraries(tomate_test_gui boost_date_time)
target_link_libraries(tomate_test_gui boost_date_time boost_filesystem boost_system)
QT5_USE_MODULES(tomate_test_gui Widgets Test)
add_test(gui tomate_test_gui)
#qt4_use_modules(test_gui Widgets)

#Translation files
add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/tomate_fr.qm
COMMAND lrelease ${CMAKE_SOURCE_DIR}/tomate_fr.ts -qm ${CMAKE_BINARY_DIR}/tomate_fr.qm
MAIN_DEPENDENCY ${CMAKE_SOURCE_DIR}/tomate_fr.ts)

set(qm_files ${CMAKE_BINARY_DIR}/tomate_fr.qm)
set(qrc_srcfile ${CMAKE_CURRENT_SOURCE_DIR}/tomate.qrc)
set(qrc_infile ${CMAKE_CURRENT_BINARY_DIR}/tomate_copied.qrc)
# Copy the QRC file to the output directory, because the files listed in the
# qrc file are relative to that directory.
add_custom_command(
OUTPUT ${qrc_infile}
COMMAND ${CMAKE_COMMAND} -E copy ${qrc_srcfile} ${qrc_infile}
MAIN_DEPENDENCY ${qrc_srcfile}
)
# Run the resource compiler (rcc_options should already be set). We can't
# use QT4_ADD_RESOURCES because the qrc file may not exist yet.
add_custom_command(
OUTPUT ${qrc_outfile}
COMMAND ${QT_RCC_EXECUTABLE}
ARGS ${rcc_options} -name tomate -o ${qrc_outfile} ${qrc_infile}
MAIN_DEPENDENCY ${qrc_infile}
DEPENDS ${qm_files}
)

#Installation
install(TARGETS tomate_gui RUNTIME DESTINATION bin)
install(PROGRAMS tomate.desktop DESTINATION share/applications/)

4 changes: 4 additions & 0 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

add_library(pugixml ./pugixml.cpp)
target_include_directories(pugixml PUBLIC ./)

21 changes: 21 additions & 0 deletions src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

find_package(Boost 1.53 COMPONENTS date_time filesystem system unit_test_framework REQUIRED)

file(GLOB CORE_SRC *.cpp)
set (CORE_TEST_SRC ./test/test.cpp ./test/testgeometry.cpp)

add_library(tomate_core ${CORE_SRC})
target_link_libraries(tomate_core pugixml)
target_include_directories(tomate_core PUBLIC ./)
QT5_USE_MODULES(tomate_core Core)

add_executable(tomate_test ${CORE_TEST_SRC})

target_link_libraries(tomate_test tomate_core)
target_link_libraries(tomate_test boost_unit_test_framework)
target_link_libraries(tomate_test boost_date_time)

add_test(NAME core
COMMAND tomate_test
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})

File renamed without changes.
File renamed without changes.
67 changes: 67 additions & 0 deletions src/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@


# Instruct CMake to run moc automatically when needed.
set(CMAKE_AUTOMOC ON)

file(GLOB WIDGETS_SRC ./gui_widgets/*.cpp)

set(GUI_SRC
croptimerepresentation.cpp
DateRuler.cpp
gui_calendar.cpp
gui_controller.cpp
gui_plants.cpp
gui_plots.cpp
gui_utils.cpp
mainwindow.cpp
spacescene.cpp
spaceview.cpp
timescene.cpp
timeview.cpp
)

file(GLOB ui_FORMS gui_widgets/*.ui mainwindow.ui)
QT5_WRAP_UI(ui_FORMS_HEADERS ${ui_FORMS})

add_executable(tomate_gui ${GUI_SRC} ${WIDGETS_SRC} main.cpp ${qrc_outfile} ${ui_FORMS_HEADERS})
target_include_directories(tomate_gui PUBLIC ./ ./gui_widgets)
target_link_libraries(tomate_gui tomate_core)
target_include_directories(tomate_gui PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
target_link_libraries(tomate_gui boost_date_time boost_filesystem boost_system)
QT5_USE_MODULES(tomate_gui Widgets)
install(TARGETS tomate_gui RUNTIME DESTINATION bin)

add_executable(tomate_test_gui ./test/test_gui.cpp ${GUI_SRC} ${WIDGETS_SRC} ${ui_FORMS_HEADERS})
target_include_directories(tomate_test_gui PUBLIC ./ ./gui_widgets)
target_include_directories(tomate_test_gui PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
target_link_libraries(tomate_test_gui tomate_core)
target_link_libraries(tomate_test_gui boost_date_time boost_filesystem boost_system)
QT5_USE_MODULES(tomate_test_gui Widgets Test)
add_test(gui tomate_test_gui)

#Translation files
add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/tomate_fr.qm
COMMAND lrelease ${CMAKE_SOURCE_DIR}/tomate_fr.ts -qm ${CMAKE_BINARY_DIR}/tomate_fr.qm
MAIN_DEPENDENCY ${CMAKE_SOURCE_DIR}/tomate_fr.ts)

set( qrc_outfile ${CMAKE_CURRENT_BINARY_DIR}/qrc_tomate.cxx)
set(qm_files ${CMAKE_BINARY_DIR}/tomate_fr.qm)
set(qrc_srcfile ${CMAKE_CURRENT_SOURCE_DIR}/tomate.qrc)
set(qrc_infile ${CMAKE_CURRENT_BINARY_DIR}/tomate_copied.qrc)
# Copy the QRC file to the output directory, because the files listed in the
# qrc file are relative to that directory.
add_custom_command(
OUTPUT ${qrc_infile}
COMMAND ${CMAKE_COMMAND} -E copy ${qrc_srcfile} ${qrc_infile}
MAIN_DEPENDENCY ${qrc_srcfile}
)
# Run the resource compiler (rcc_options should already be set). We can't
# use QT4_ADD_RESOURCES because the qrc file may not exist yet.
add_custom_command(
OUTPUT ${qrc_outfile}
COMMAND ${QT_RCC_EXECUTABLE}
ARGS ${rcc_options} -name tomate -o ${qrc_outfile} ${qrc_infile}
MAIN_DEPENDENCY ${qrc_infile}
DEPENDS ${qm_files}
)

2 changes: 1 addition & 1 deletion src/main.cpp → src/gui/main.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

#include "gui/mainwindow.h"
#include "mainwindow.h"

#include <QApplication>
#include <QTranslator>
Expand Down
File renamed without changes.

0 comments on commit a1b94ed

Please sign in to comment.