-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
106 lines (86 loc) · 3.59 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
cmake_minimum_required(VERSION 3.5)
project(M4 CXX)
# add source for any additional non-gui modules here
set(LIB_SOURCE
token.hpp token.cpp
lexer.hpp lexer.cpp
parser.hpp parser.cpp
virtualMachine.hpp virtualMachine.cpp)
# add source for any additional gui modules here
set(UI_SOURCE
virtual_machine_gui.hpp virtual_machine_gui.cpp)
# add source for any additional unit tests here
set(LIB_TEST_SOURCE
lexer_test.cpp
parser_test.cpp)
# add source for simmips program here
set(SIMMIPS_SOURCE simmips.cpp)
# You should not need to edit below this line
#-----------------------------------------------------------------------
#-----------------------------------------------------------------------
set(UI_TEST_SOURCE
virtual_machine_gui_test.cpp)
# try to prevent accidental in-source builds, these cause lots of problems
if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
message(FATAL_ERROR "In-source builds not allowed. Remove any files created thus far and use a different directory for the build.")
endif()
# require a C++11 compiler for all targets
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# configure Qt
set(CMAKE_AUTOMOC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
find_package(Qt5 COMPONENTS Widgets Test REQUIRED)
# optional strict mode
if(UNIX AND STRICT)
message("-- Enabling strict compilation mode")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror")
endif()
# setup testing
set(TEST_FILE_DIR "${CMAKE_SOURCE_DIR}/tests")
configure_file(${CMAKE_SOURCE_DIR}/test_config.hpp.in
${CMAKE_BINARY_DIR}/test_config.hpp)
configure_file(${CMAKE_SOURCE_DIR}/test_config.py.in
${CMAKE_BINARY_DIR}/test_config.py)
include_directories(${CMAKE_BINARY_DIR})
# executables
add_executable(unit_tests catch.hpp unit_tests.cpp ${LIB_TEST_SOURCE} ${LIB_SOURCE})
if(UNIX AND NOT APPLE AND CMAKE_COMPILER_IS_GNUCXX)
target_link_libraries(unit_tests pthread)
endif()
add_executable(virtual_machine_gui_test ${UI_TEST_SOURCE} ${UI_SOURCE} ${LIB_SOURCE})
if(UNIX AND NOT APPLE AND CMAKE_COMPILER_IS_GNUCXX)
target_link_libraries(virtual_machine_gui_test Qt5::Widgets Qt5::Test pthread)
else(UNIX AND NOT APPLE AND CMAKE_COMPILER_IS_GNUCXX)
target_link_libraries(virtual_machine_gui_test Qt5::Widgets Qt5::Test)
endif()
add_executable(simmips ${SIMMIPS_SOURCE} ${UI_SOURCE} ${LIB_SOURCE})
if(UNIX AND NOT APPLE AND CMAKE_COMPILER_IS_GNUCXX)
target_link_libraries(simmips Qt5::Widgets pthread)
else(UNIX AND NOT APPLE AND CMAKE_COMPILER_IS_GNUCXX)
target_link_libraries(simmips Qt5::Widgets)
endif()
# Tests
#----------------------------------------------------------------------
enable_testing()
# unit tests
add_test(unit_tests unit_tests)
add_test(ui_tests virtual_machine_gui_test)
# In the reference environment enable coverage on tests
if(UNIX AND NOT APPLE AND CMAKE_COMPILER_IS_GNUCXX)
message("-- Enabling test coverage")
set(GCC_COVERAGE_COMPILE_FLAGS "-g -O0 -fprofile-arcs -ftest-coverage")
set_target_properties(unit_tests PROPERTIES COMPILE_FLAGS ${GCC_COVERAGE_COMPILE_FLAGS} )
set_target_properties(virtual_machine_gui_test PROPERTIES COMPILE_FLAGS ${GCC_COVERAGE_COMPILE_FLAGS} )
target_link_libraries(unit_tests gcov)
target_link_libraries(virtual_machine_gui_test gcov)
add_custom_target(coverage
COMMAND ${CMAKE_COMMAND} -E env "ROOT=${CMAKE_CURRENT_SOURCE_DIR}"
${CMAKE_CURRENT_SOURCE_DIR}/scripts/coverage.sh)
endif()
# In the reference environment enable memory checking on tests
if(UNIX AND NOT APPLE AND CMAKE_COMPILER_IS_GNUCXX)
message("-- Enabling memory checks")
add_custom_target(memtest
COMMAND valgrind ${CMAKE_BINARY_DIR}/unit_tests)
endif()