From fe37a1646df942fe9dc58f37e1394745523c2743 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Wed, 4 Oct 2017 20:31:35 -0700 Subject: [PATCH] Build pcre2 and muparser with CMake This adds files MuParser.cmake and PCRE2.cmake. PCRE2 is built using its own CMake path, while MuParser uses ExternalProject. --- CMakeFiles/MuParser.cmake | 28 ++++++++++++++++++++++++++++ CMakeFiles/PCRE2.cmake | 20 ++++++++++++++++++++ CMakeLists.txt | 11 +++++------ 3 files changed, 53 insertions(+), 6 deletions(-) create mode 100644 CMakeFiles/MuParser.cmake create mode 100644 CMakeFiles/PCRE2.cmake diff --git a/CMakeFiles/MuParser.cmake b/CMakeFiles/MuParser.cmake new file mode 100644 index 000000000..525181f6f --- /dev/null +++ b/CMakeFiles/MuParser.cmake @@ -0,0 +1,28 @@ +INCLUDE(ExternalProject) + +SET(MUPARSER_PREFIX muparser-build) +SET(MUPARSER_SRC ${CMAKE_CURRENT_SOURCE_DIR}/muparser-2.2.5) +SET(MUPARSER_OBJ ${MUPARSER_PREFIX}/obj) +SET(MUPARSER_DST ${MUPARSER_PREFIX}/dst) + +# MuParser configure has an obnoxious victory message which we suppress. +EXTERNALPROJECT_ADD( + muparser_project + PREFIX ${MUPARSER_PREFIX} + SOURCE_DIR ${MUPARSER_SRC} + BINARY_DIR ${MUPARSER_OBJ} + INSTALL_DIR ${MUPARSER_DST} + CONFIGURE_COMMAND ${MUPARSER_SRC}/configure + --prefix=${CMAKE_CURRENT_BINARY_DIR}/${MUPARSER_DST} + --quiet --enable-shared=no --enable-samples=no --enable-debug=no > /dev/null + BUILD_COMMAND make -j 3 CPPFLAGS=-D_UNICODE=1\ -Wno-switch lib/libmuparser.a + INSTALL_COMMAND make install + BUILD_BYPRODUCTS ${MUPARSER_DST}/lib/libmuparser.a + EXCLUDE_FROM_ALL +) + +ADD_LIBRARY(muparser STATIC IMPORTED) +SET_TARGET_PROPERTIES(muparser PROPERTIES IMPORTED_LOCATION + ${CMAKE_CURRENT_BINARY_DIR}/${MUPARSER_DST}/lib/libmuparser.a) +ADD_DEPENDENCIES(muparser muparser_project) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}/${MUPARSER_DST}/include/) diff --git a/CMakeFiles/PCRE2.cmake b/CMakeFiles/PCRE2.cmake new file mode 100644 index 000000000..2b4afce25 --- /dev/null +++ b/CMakeFiles/PCRE2.cmake @@ -0,0 +1,20 @@ +# PCRE2 needs some settings. +SET(PCRE2_WIDTH ${WCHAR_T_BITS}) +SET(PCRE2_BUILD_PCRE2_8 OFF CACHE BOOL "Build 8bit PCRE2 library") +SET(PCRE2_BUILD_PCRE2_${PCRE2_WIDTH} ON CACHE BOOL "Build ${PCRE2_WIDTH}bit PCRE2 library") +SET(PCRE2_SHOW_REPORT OFF CACHE BOOL "Show the final configuration report") +SET(PCRE2_BUILD_PCRE2GREP OFF CACHE BOOL "Build pcre2grep") + + +SET(PCRE2_MIN_VERSION 10.21) +FIND_LIBRARY(PCRE2_LIB pcre2-${PCRE2_WIDTH}) +FIND_PATH(PCRE2_INCLUDE_DIR pcre2.h) +IF (PCRE2_LIB AND PCRE2_INCLUDE_DIR) + MESSAGE(STATUS "Found system PCRE2 library ${PCRE2_INCLUDE_DIR}") +ELSE() + MESSAGE(STATUS "Using bundled PCRE2 library") + ADD_SUBDIRECTORY(pcre2-10.22 EXCLUDE_FROM_ALL) + SET(PCRE2_INCLUDE_DIR ${CMAKE_BINARY_DIR}/pcre2-10.22/) + SET(PCRE2_LIB pcre2-${PCRE2_WIDTH}) +endif(PCRE2_LIB AND PCRE2_INCLUDE_DIR) +INCLUDE_DIRECTORIES(${PCRE2_INCLUDE_DIR}) diff --git a/CMakeLists.txt b/CMakeLists.txt index 96e176b17..95a54ea6c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -53,17 +53,16 @@ ADD_DEFINITIONS(-D_UNICODE=1 -DBINDIR=L"${CMAKE_INSTALL_FULL_BINDIR}" -DDOCDIR=L"${CMAKE_INSTALL_FULL_DOCDIR}") -# Set up dependency paths. -INCLUDE_DIRECTORIES(muparser-2.2.5/include/ pcre2-10.22/src/) -LINK_DIRECTORIES(muparser-2.2.5/lib/ pcre2-10.22/.libs/) +# Set up PCRE2 +INCLUDE(CMakeFiles/PCRE2.cmake) -# PCRE2 needs a define. -SET(PCRE2_WIDTH ${WCHAR_T_BITS}) +# Set up muparser. +INCLUDE(CMakeFiles/MuParser.cmake) # Define a function to link dependencies. FUNCTION(FISH_LINK_DEPS target) TARGET_LINK_LIBRARIES(${target} ${CURSES_LIBRARIES} Threads::Threads) - TARGET_LINK_LIBRARIES(${target} pcre2-${PCRE2_WIDTH} muparser) + TARGET_LINK_LIBRARIES(${target} ${PCRE2_LIB} muparser) ENDFUNCTION(FISH_LINK_DEPS) # Define fish.