Skip to content

Commit 031ebde

Browse files
committed
Bug #2524: Addition of CMake build files - use of module "FindPCRE"
A few build scripts were updated for the use of the module "FindPCRE.cmake" and corresponding variables so that the software can work with the programming interface "Perl-compatible regular expressions". Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
1 parent 1c4124a commit 031ebde

5 files changed

Lines changed: 58 additions & 8 deletions

File tree

cli/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Minimal CMake build file to build cppcheck command line executable
2+
find_package(PCRE REQUIRED)
23

34
SET(CHECKCLI_SRCS
45
cppcheckexecutor.cpp

cmake/modules/FindPCRE.cmake

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# - Try to find the PCRE regular expression library
2+
# Once done this will define
3+
#
4+
# PCRE_FOUND - system has the PCRE library
5+
# PCRE_INCLUDE_DIR - the PCRE include directory
6+
# PCRE_LIBRARIES - The libraries needed to use PCRE
7+
8+
# Copyright (c) 2006, Alexander Neundorf, <neundorf@kde.org>
9+
#
10+
# Redistribution and use is allowed according to the terms of the BSD license.
11+
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
12+
13+
14+
if (PCRE_INCLUDE_DIR AND PCRE_PCREPOSIX_LIBRARY AND PCRE_PCRE_LIBRARY)
15+
# Already in cache, be silent
16+
set(PCRE_FIND_QUIETLY TRUE)
17+
endif (PCRE_INCLUDE_DIR AND PCRE_PCREPOSIX_LIBRARY AND PCRE_PCRE_LIBRARY)
18+
19+
20+
if (NOT WIN32)
21+
# use pkg-config to get the directories and then use these values
22+
# in the FIND_PATH() and FIND_LIBRARY() calls
23+
find_package(PkgConfig)
24+
25+
pkg_check_modules(PC_PCRE QUIET libpcre)
26+
27+
set(PCRE_DEFINITIONS ${PC_PCRE_CFLAGS_OTHER})
28+
29+
endif (NOT WIN32)
30+
31+
find_path(PCRE_INCLUDE_DIR pcre.h
32+
HINTS ${PC_PCRE_INCLUDEDIR} ${PC_PCRE_INCLUDE_DIRS}
33+
PATH_SUFFIXES pcre)
34+
35+
find_library(PCRE_PCRE_LIBRARY NAMES pcre pcred HINTS ${PC_PCRE_LIBDIR} ${PC_PCRE_LIBRARY_DIRS})
36+
37+
find_library(PCRE_PCREPOSIX_LIBRARY NAMES pcreposix pcreposixd HINTS ${PC_PCRE_LIBDIR} ${PC_PCRE_LIBRARY_DIRS})
38+
39+
include(FindPackageHandleStandardArgs)
40+
find_package_handle_standard_args(PCRE DEFAULT_MSG PCRE_INCLUDE_DIR PCRE_PCRE_LIBRARY PCRE_PCREPOSIX_LIBRARY )
41+
42+
set(PCRE_LIBRARIES ${PCRE_PCRE_LIBRARY} ${PCRE_PCREPOSIX_LIBRARY})
43+
44+
mark_as_advanced(PCRE_INCLUDE_DIR PCRE_LIBRARIES PCRE_PCREPOSIX_LIBRARY PCRE_PCRE_LIBRARY)

gui/CMakeLists.txt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Minimal CMake build file to build cppcheck Qt GUI
2+
find_package(PCRE REQUIRED)
23

34
# find and setup Qt4 for this project
45
find_package(Qt4)
@@ -10,9 +11,12 @@ set(QT_USE_QTMAIN TRUE)
1011
set(QT_USE_QTXML TRUE)
1112
include(${QT_USE_FILE})
1213

13-
include_directories (${CPPCHECK_SOURCE_DIR}/lib)
14+
include_directories("${CPPCHECK_SOURCE_DIR}/lib"
1415
# Generated files (in build directory) need to know gui directory
15-
include_directories (${CPPCHECK_SOURCE_DIR}/gui)
16+
"${CPPCHECK_SOURCE_DIR}/gui"
17+
# Include binary directory where code from UI files gets created
18+
"${CMAKE_CURRENT_BINARY_DIR}"
19+
"${PCRE_INCLUDE_DIR}")
1620

1721
# Header files - listed for mocking
1822
SET(CHECK_HEADERS
@@ -119,12 +123,9 @@ SOURCE_GROUP("Header Files" FILES ${CHECK_HEADERS})
119123
SOURCE_GROUP("Ui Files" ".ui$")
120124
SOURCE_GROUP("Moc Files" "moc_.*cxx$")
121125

122-
# Include binary directory where code from UI files gets created
123-
include_directories(${CMAKE_CURRENT_BINARY_DIR})
124-
125126
ADD_EXECUTABLE(gui WIN32 ${CHECKGUI_SRCS} ${CHECK_MOC_SRCS} ${CHECK_HEADERS}
126127
${CHECK_UIS_H} ${CHECK_RCC_SRCS} ${LIB_SRCS})
127-
TARGET_LINK_LIBRARIES(gui ${CHECK_LIBS} ${QT_LIBRARIES})
128+
TARGET_LINK_LIBRARIES(gui ${CHECK_LIBS} ${PCRE_LIBRARIES} ${QT_LIBRARIES})
128129

129130
ELSE(QT4_FOUND)
130131
message("GUI not built since QT4 not found.")

lib/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
# - cli
44
# - tests
55
# - Qt GUI
6+
find_package(PCRE REQUIRED)
7+
include_directories("${PCRE_INCLUDE_DIR}")
68

79
SET(CHECKLIB_SRCS
810
checkautovariables.cpp
@@ -33,3 +35,4 @@ if (CMAKE_COMPILER_IS_GNUCXX)
3335
endif (CMAKE_COMPILER_IS_GNUCXX)
3436

3537
ADD_LIBRARY(checklib STATIC ${CHECKLIB_SRCS})
38+
target_link_libraries(checklib ${PCRE_LIBRARIES})

test/CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Minimal CMake build file to build cppcheck test suite
2+
find_package(PCRE REQUIRED)
23

34
SET(CHECKTEST_SRCS
45
testmemleak.cpp
@@ -47,9 +48,9 @@ if (CMAKE_COMPILER_IS_GNUCXX)
4748
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic -Wshadow -Wno-long-long -Wfloat-equal -Wcast-qual")
4849
endif (CMAKE_COMPILER_IS_GNUCXX)
4950

50-
include_directories (${CPPCHECK_SOURCE_DIR}/lib)
51+
include_directories("${CPPCHECK_SOURCE_DIR}/lib" "${PCRE_INCLUDE_DIR}")
5152
ADD_EXECUTABLE(test ${CHECKTEST_SRCS} ${LIB_SRCS})
52-
TARGET_LINK_LIBRARIES(test ${CHECK_LIBS})
53+
TARGET_LINK_LIBRARIES(test ${CHECK_LIBS} ${PCRE_LIBRARIES})
5354

5455
# Add custom 'make check' -target
5556
# It compiles and runs tests

0 commit comments

Comments
 (0)