diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..378eac2 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +build diff --git a/CMakeLists.txt b/CMakeLists.txt index 09e2afb..e0633a3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,6 +2,8 @@ cmake_minimum_required(VERSION 3.8.2 FATAL_ERROR) project(boost_matheval CXX) +include(GNUInstallDirs) + # Default build type is Debug if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Debug CACHE STRING "Choose the build type" FORCE) @@ -21,31 +23,49 @@ if(WITH_COVERAGE) endif() endif() -if(CMAKE_VERSION VERSION_GREATER 3.5.2 AND CMAKE_CXX_COMPILER_ID STREQUAL "Clang") - option(WITH_CLANG_TIDY "Run Clang-Tidy during compilation" OFF) -endif() -if(WITH_CLANG_TIDY) - string(REGEX REPLACE "^([1-9]+\\.[0-9]+).*$" "\\1" CLANG_MINOR_VERSION "${CMAKE_CXX_COMPILER_VERSION}") - find_program( +option(WITH_CLANG_TIDY "Run Clang-Tidy during compilation" OFF) + +# Find clang-tidy executable (no matter if building with gcc or clang) +string(REGEX REPLACE "^([1-9]+\\.[0-9]+).*$" "\\1" CLANG_MINOR_VERSION "${CMAKE_CXX_COMPILER_VERSION}") +find_program( CLANG_TIDY_EXE NAMES "clang-tidy-${CLANG_MINOR_VERSION}" "clang-tidy" DOC "Path to clang-tidy executable" - ) +) + +if(WITH_CLANG_TIDY) if(NOT CLANG_TIDY_EXE) - message(STATUS "clang-tidy not found.") + message(FATAL_ERROR "clang-tidy was enabled but no executable found.") else() message(STATUS "clang-tidy found: ${CLANG_TIDY_EXE}") set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_EXE}" "-checks=-*,bugprone-*,cert-*,clang-analyzer-*,cppcoreguidelines-*,hicpp-*,misc-*,modernize-*,performance-*,readability-*" - "-header-filter=.*") - #"-warnings-as-errors=*") + "-header-filter=.*" + "-warnings-as-errors=*" + ) endif() endif() + # Subdirectories +add_subdirectory(src/qi) +add_subdirectory(src/x3) +add_subdirectory(doc/doxygen) +add_subdirectory(examples) +add_subdirectory(tests) + + + +# Install +install( + DIRECTORY include/ + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + FILES_MATCHING PATTERN "*.hpp" +) + +install( + EXPORT ${PROJECT_NAME} + NAMESPACE matheval:: + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}/ +) -add_subdirectory(src/qi EXCLUDE_FROM_ALL) -add_subdirectory(src/x3 EXCLUDE_FROM_ALL) -add_subdirectory(doc/doxygen EXCLUDE_FROM_ALL) -add_subdirectory(examples EXCLUDE_FROM_ALL) -add_subdirectory(tests EXCLUDE_FROM_ALL) diff --git a/cmake/FindReadline.cmake b/cmake/FindReadline.cmake index 4c75b38..5d732d1 100644 --- a/cmake/FindReadline.cmake +++ b/cmake/FindReadline.cmake @@ -4,6 +4,6 @@ find_path(READLINE_INCLUDE_DIR NAMES readline/readline.h) find_library(READLINE_LIBRARY NAMES readline) -find_package_handle_standard_args(READLINE DEFAULT_MSG READLINE_LIBRARY READLINE_INCLUDE_DIR) +find_package_handle_standard_args(Readline DEFAULT_MSG READLINE_LIBRARY READLINE_INCLUDE_DIR) mark_as_advanced(READLINE_INCLUDE_DIR READLINE_LIBRARY) diff --git a/src/qi/CMakeLists.txt b/src/qi/CMakeLists.txt index 35bdd4f..f608e84 100644 --- a/src/qi/CMakeLists.txt +++ b/src/qi/CMakeLists.txt @@ -1,22 +1,37 @@ +find_package(Boost 1.65.1 REQUIRED) + add_library(matheval.qi - ast_adapted.hpp - ast.hpp - evaluator.cpp - evaluator.hpp - matheval.cpp - math.hpp - parser.cpp - parser_def.hpp - parser.hpp - ) + ast_adapted.hpp + ast.hpp + evaluator.cpp + evaluator.hpp + matheval.cpp + math.hpp + parser.cpp + parser_def.hpp + parser.hpp +) target_include_directories(matheval.qi - PUBLIC ../../include/matheval/qi - ) + PUBLIC + $ + $ +) target_compile_features(matheval.qi - PUBLIC cxx_std_98 - ) -find_package(Boost 1.65.1 REQUIRED) + PUBLIC + cxx_std_98 +) target_link_libraries(matheval.qi - PRIVATE Boost::boost - ) + PUBLIC + Boost::boost +) + +set_target_properties(matheval.qi PROPERTIES EXPORT_NAME qi) + add_library(matheval::qi ALIAS matheval.qi) + +install( + TARGETS matheval.qi + DESTINATION ${CMAKE_INSTALL_LIBDIR} + EXPORT ${PROJECT_NAME} +) + diff --git a/src/x3/CMakeLists.txt b/src/x3/CMakeLists.txt index 4877d27..7631bb5 100644 --- a/src/x3/CMakeLists.txt +++ b/src/x3/CMakeLists.txt @@ -1,22 +1,36 @@ +find_package(Boost 1.65.1 REQUIRED) + add_library(matheval.x3 - ast_adapted.hpp - ast.hpp - evaluator.cpp - evaluator.hpp - matheval.cpp - math.hpp - parser.cpp - parser_def.hpp - parser.hpp - ) + ast_adapted.hpp + ast.hpp + evaluator.cpp + evaluator.hpp + matheval.cpp + math.hpp + parser.cpp + parser_def.hpp + parser.hpp +) target_include_directories(matheval.x3 - PUBLIC ../../include/matheval/x3 - ) + PUBLIC + $ + $ +) target_compile_features(matheval.x3 - PUBLIC cxx_std_14 - ) -find_package(Boost 1.65.1 REQUIRED) + PUBLIC + cxx_std_14 +) target_link_libraries(matheval.x3 - PRIVATE Boost::boost - ) + PUBLIC + Boost::boost +) + +set_target_properties(matheval.x3 PROPERTIES EXPORT_NAME x3) + add_library(matheval::x3 ALIAS matheval.x3) + +install( + TARGETS matheval.x3 + DESTINATION ${CMAKE_INSTALL_LIBDIR} + EXPORT ${PROJECT_NAME} +)