fu7mu4’s diary

はてなダイアリーから移転しました。

building cppcheck on macOS by cmake

たぶん、これでビルドできるはず。

必要なもの

  • cmake
  • pcre
  • qt
  • git

取得

git で最新コードを取得する。

git clone https://github.com/danmar/cppcheck.git
cd cppcheck

設定

cmake/options.cmake を修正

--- options.cmake~	2018-07-13 23:20:37.000000000 +0900
+++ options.cmake	2018-07-16 22:06:35.000000000 +0900
@@ -13,7 +13,7 @@
 # ----------------------------------------------------------------------------
 #   PROJECT CONFIGURATION
 # ----------------------------------------------------------------------------
-option(USE_CLANG            "Use Clang compiler"                                            OFF)
+option(USE_CLANG            "Use Clang compiler"                                            ON)
 option(USE_ANALYZE          "Use Clang compiler with analyze mode"                          OFF)
 option(ANALYZE_MEMORY       "Clang dynamic analyzer: detector of uninitialized reads."      OFF)
 option(ANALYZE_ADDRESS      "Clang dynamic analyzer: fast memory error detector. "          OFF)
@@ -36,9 +36,9 @@
 endif()
 
 option(BUILD_TESTS          "Build tests"                                                   OFF)
-option(BUILD_GUI            "Build the qt application"                                      OFF)
+option(BUILD_GUI            "Build the qt application"                                      ON)
 
-option(HAVE_RULES           "Usage of rules (needs PCRE library and headers)"               OFF)
+option(HAVE_RULES           "Usage of rules (needs PCRE library and headers)"               ON)
 
 set(CMAKE_INCLUDE_DIRS_CONFIGCMAKE ${CMAKE_INSTALL_PREFIX}/include      CACHE PATH "Output directory for headers")
 set(CMAKE_LIB_DIRS_CONFIGCMAKE     ${CMAKE_INSTALL_PREFIX}/lib          CACHE PATH "Output directory for libraries")

cmake/compileroptions.cmake を編集して、pcre.h のパスを追加する(ここでは-I/opt/local/include)

--- compileroptions.cmake~	2018-07-13 23:20:37.000000000 +0900
+++ compileroptions.cmake	2018-07-16 22:36:06.000000000 +0900
@@ -122,10 +122,10 @@
 set(EXTRA_C_FLAGS_DEBUG "${EXTRA_C_FLAGS_DEBUG}" CACHE INTERNAL "Extra compiler options for Debug build")
 
 #combine all "extra" options
-set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_C_FLAGS}")
-set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${EXTRA_C_FLAGS_DEBUG}")
-set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${EXTRA_C_FLAGS_RELEASE}")
+set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_C_FLAGS} -I/opt/local/include")
+set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${EXTRA_C_FLAGS_DEBUG} -I/opt/local/include")
+set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${EXTRA_C_FLAGS_RELEASE} -I/opt/local/include")
 
-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_C_FLAGS}")
-set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}  ${EXTRA_C_FLAGS_RELEASE}")
-set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${EXTRA_C_FLAGS_DEBUG}")
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_C_FLAGS} -I/opt/local/include")
+set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}  ${EXTRA_C_FLAGS_RELEASE} -I/opt/local/include")
+set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${EXTRA_C_FLAGS_DEBUG} -I/opt/local/include")
mkdir build
cd build
make
make install