Skip to content

Commit 0b02a72

Browse files
committed
Refactor CMake
1 parent 7f17904 commit 0b02a72

4 files changed

Lines changed: 22 additions & 28 deletions

File tree

CMakeLists.txt

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ project(notonlymodbusscope
66
VERSION 0.0.1
77
)
88

9-
add_definitions("-DDEBUG")
10-
119
set(SCOPESOURCE ScopeSource)
1210

1311
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
@@ -50,26 +48,17 @@ set(QT_LIB
5048
Qt::SerialPort
5149
)
5250

53-
include_directories(
54-
${CMAKE_CURRENT_SOURCE_DIR}/src
55-
${CMAKE_CURRENT_SOURCE_DIR}/libraries
56-
)
57-
58-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
59-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wextra")
60-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
51+
add_compile_options(-Wall -Wextra -Werror)
6152
if (MINGW)
62-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wa,-mbig-obj")
53+
add_compile_options(-Wa,-mbig-obj)
6354
endif()
6455

65-
66-
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
56+
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
6757
# Code Coverage Report
6858
if(USE_GCOV)
69-
message(STATUS "Enabling coverage")
70-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage")
71-
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage")
72-
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} --coverage")
59+
message(STATUS "Enabling coverage")
60+
add_compile_options(--coverage)
61+
add_link_options(--coverage)
7362
endif()
7463
endif()
7564

libraries/muparser/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ elseif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
4242
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-long-long -pedantic")
4343
endif()
4444

45-
FILE(GLOB_RECURSE MUPARSER_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp") #all .cpp
45+
FILE(GLOB_RECURSE MUPARSER_SOURCES CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp") #all .cpp
4646
add_library(muparser ${MUPARSER_SOURCES})
4747

4848
# Use the headers in the build-tree or the installed ones

src/CMakeLists.txt

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,25 @@ execute_process(
1818
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/util/version.h.in ${CMAKE_CURRENT_SOURCE_DIR}/util/version.h)
1919
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/../resources/modbusscope.rc.in ${CMAKE_CURRENT_SOURCE_DIR}/../resources/modbusscope.rc)
2020

21-
FILE(GLOB_RECURSE SRCS "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/*.h") #all .cpp/.h in current "src" folder and sub folders
22-
FILE(GLOB_RECURSE UIS "${CMAKE_CURRENT_SOURCE_DIR}/*.ui") #all .ui in current "src" folder and sub folders
21+
file(GLOB_RECURSE SRCS CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/*.h") #all .cpp/.h in current "src" folder and sub folders
22+
file(GLOB_RECURSE UIS CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/*.ui") #all .ui in current "src" folder and sub folders
2323

24-
qt_add_library (${SCOPESOURCE} STATIC ${SRCS} ${UIS})
24+
qt_add_library(${SCOPESOURCE} STATIC ${SRCS} ${UIS})
25+
26+
target_compile_definitions(${SCOPESOURCE} PRIVATE DEBUG)
27+
28+
target_include_directories(${SCOPESOURCE} PUBLIC
29+
${CMAKE_CURRENT_SOURCE_DIR}
30+
${CMAKE_CURRENT_SOURCE_DIR}/../libraries
31+
)
2532

2633
# Default GUI type is blank
2734
set(GUI_TYPE "")
2835

2936
if(WIN32)
3037
set(GUI_TYPE WIN32)
3138
set(target_dir "bin/win")
32-
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
39+
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
3340
set(target_dir "bin/linux")
3441
else()
3542
message(SEND_ERROR "You are on an unsupported platform! (Not Win or Unix)")
@@ -62,10 +69,10 @@ add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
6269
)
6370

6471
# Do platform specific post target stuff
65-
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
72+
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
6673

6774
install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION bin)
6875

6976
elseif(WIN32)
7077
# not required
71-
endif (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
78+
endif (CMAKE_SYSTEM_NAME STREQUAL "Linux")

tests/CMakeLists.txt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
add_definitions(-DGTEST_LANGUAGE_CXX11)
2-
31
find_package(Threads REQUIRED)
42

53
if ($ENV{GOOGLETEST_DIR})
@@ -16,8 +14,6 @@ else ()
1614
message( FATAL_ERROR "No googletest src dir found - set GOOGLETEST_DIR to enable!")
1715
endif ()
1816

19-
include_directories(${GTestSrc} ${GTestSrc}/include ${GMockSrc} ${GMockSrc}/include)
20-
2117
set(
2218
GOOGLE_TEST_SOURCE
2319
${GTestSrc}/src/gtest-all.cc
@@ -43,6 +39,8 @@ function(add_xtest_mock SOURCE_NAME)
4339
${SOURCE_NAME}.cpp
4440
${GOOGLE_TEST_SOURCE}
4541
${ARGN})
42+
target_include_directories(${SOURCE_NAME} PRIVATE ${GTestSrc} ${GTestSrc}/include ${GMockSrc} ${GMockSrc}/include)
43+
target_compile_definitions(${SOURCE_NAME} PRIVATE GTEST_LANGUAGE_CXX11)
4644
target_link_libraries(${SOURCE_NAME} Qt::Test Threads::Threads ${QT_LIB} ${SCOPESOURCE})
4745
add_test(NAME ${SOURCE_NAME} COMMAND ${SOURCE_NAME})
4846
endfunction()

0 commit comments

Comments
 (0)