# Parsodus - A language agnostic parser generator # Copyright © 2016-2017 Thomas Avé, Robin Jadoul, Kobe Wullaert # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the "Software"), # to deal in the Software without restriction, including without limitation # the rights to use, copy, modify, merge, publish, distribute, sublicense, # and/or sell copies of the Software, and to permit persons to whom the # Software is furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included # in all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES # OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, # DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE # OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. cmake_minimum_required(VERSION 3.2.2) project(Parsodus VERSION 1.0) set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD_REQUIRED 14) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake) find_package(Threads) include(ExternalProject) find_package(mstch QUIET) if (NOT mstch_FOUND) ExternalProject_Add(ext-mstch GIT_REPOSITORY https://github.com/no1msd/mstch GIT_TAG 1.0.2 #The following line is a dirty hack #to prevent cmake from needlessly clone any submodule #inspect `ext-mstch-prefix/tmp/ext-mstch-gitclone.cmake` for more info GIT_SUBMODULES "NONE\ COMMAND\ true\ ERROR_QUIET" CMAKE_ARGS -DWITH_UNIT_TESTS=NO INSTALL_COMMAND "" ) add_library(mstch::mstch IMPORTED STATIC GLOBAL) add_dependencies(mstch::mstch ext-mstch) ExternalProject_Get_Property(ext-mstch source_dir binary_dir) set_target_properties(mstch::mstch PROPERTIES "IMPORTED_LOCATION" "${binary_dir}/src/${CMAKE_STATIC_LIBRARY_PREFIX}mstch${CMAKE_STATIC_LIBRARY_SUFFIX}") include_directories(${source_dir}/include) endif() ExternalProject_Add(ext-optparse GIT_REPOSITORY https://github.com/myint/optparse CONFIGURE_COMMAND "" BUILD_COMMAND "" INSTALL_COMMAND "" ) ExternalProject_Get_Property(ext-optparse source_dir) include_directories(${source_dir}) set(OLD_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES}) set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_STATIC_LIBRARY_SUFFIX}) find_package(G3LOG QUIET) set(CMAKE_FIND_LIBRARY_SUFFIXES ${OLD_SUFFIXES}) if(NOT G3LOG_FOUND) find_program(GIT_COMMAND git) if (${GIT_COMMAND} STREQUAL "GIT_COMMAND-NOTFOUND") ExternalProject_Add(ext-g3log GIT_REPOSITORY https://github.com/KjellKod/g3log CMAKE_ARGS -DADD_FATAL_EXAMPLE=OFF INSTALL_COMMAND "" ) else() ExternalProject_Add(ext-g3log GIT_REPOSITORY https://github.com/KjellKod/g3log CMAKE_ARGS -DADD_FATAL_EXAMPLE=OFF PATCH_COMMAND "${GIT_COMMAND}" apply < "${CMAKE_CURRENT_SOURCE_DIR}/cmake/g3log-patch.patch" INSTALL_COMMAND "" ) endif() ExternalProject_Get_Property(ext-g3log source_dir binary_dir) set(G3LOG_INCLUDE_DIR "${source_dir}/src") add_library(g3logger IMPORTED STATIC GLOBAL) set(G3LOG_LIBRARY g3logger) add_dependencies(g3logger ext-g3log) set_target_properties(g3logger PROPERTIES "IMPORTED_LOCATION" "${binary_dir}/${CMAKE_STATIC_LIBRARY_PREFIX}g3logger${CMAKE_STATIC_LIBRARY_SUFFIX}") include_directories(${source_dir}/include) endif() include_directories(${G3LOG_INCLUDE_DIR}) find_package(Lexesis QUIET) if (NOT LEXESIS_FOUND) ExternalProject_Add(ext-lexesis GIT_REPOSITORY https://gitlab.com/Robin_Jadoul/Lexesis.git CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=. ) add_library(templ IMPORTED STATIC GLOBAL) add_library(lxsinput IMPORTED STATIC GLOBAL) add_dependencies(templ ext-lexesis) add_dependencies(lxsinput ext-lexesis) ExternalProject_Get_Property(ext-lexesis binary_dir source_dir) set_target_properties(templ PROPERTIES "IMPORTED_LOCATION" "${binary_dir}/src/${CMAKE_STATIC_LIBRARY_PREFIX}templ${CMAKE_STATIC_LIBRARY_SUFFIX}") set_target_properties(lxsinput PROPERTIES "IMPORTED_LOCATION" "${binary_dir}/src/${CMAKE_STATIC_LIBRARY_PREFIX}lxsinput${CMAKE_STATIC_LIBRARY_SUFFIX}") include_directories(${binary_dir}/include) set(LEXESIS_EXE "${binary_dir}/bin/Lexesis") endif() #Enable code coverage on debug if(CMAKE_BUILD_TYPE MATCHES Debug) option(USE_SYSTEM_LCOV "Use the lcov version found on the system, if available" YES) include(CodeCoverage) if (NOT LCOV_PATH OR NOT USE_SYSTEM_LCOV) ExternalProject_Add(ext-lcov GIT_REPOSITORY https://github.com/linux-test-project/lcov CONFIGURE_COMMAND "" BUILD_COMMAND "" INSTALL_COMMAND "" TEST_COMMAND "") if (${CMAKE_VERSION} STRGREATER "3.0.1") set_target_properties(ext-lcov PROPERTIES EXCLUDE_FROM_ALL 1) endif() ExternalProject_Get_Property(ext-lcov source_dir) set(LCOV_PATH "${source_dir}/bin/lcov") set(GENHTML_PATH "${source_dir}/bin/genhtml") endif() SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0 -fprofile-arcs -ftest-coverage") endif() option(USE_SYSTEM_GTEST "Use the google test framework installed on the system, if available" YES) find_package(GTest) if (NOT GTEST_FOUND OR NOT USE_SYSTEM_GTEST) #Google test framework ExternalProject_Add(ext-gtest GIT_REPOSITORY https://github.com/google/googletest.git CMAKE_ARGS -DBUILD_GMOCK=NO -DBUILD_GTEST=YES INSTALL_COMMAND "" ) add_library(gtest IMPORTED STATIC GLOBAL) add_dependencies(gtest ext-gtest) add_library(gtest_main IMPORTED STATIC GLOBAL) add_dependencies(gtest_main ext-gtest) ExternalProject_Get_Property(ext-gtest source_dir binary_dir) find_package(Threads) set_target_properties(gtest PROPERTIES "IMPORTED_LOCATION" "${binary_dir}/googletest/${CMAKE_STATIC_LIBRARY_PREFIX}gtest${CMAKE_STATIC_LIBRARY_SUFFIX}" "IMPORTED_LINK_INTERFACE_LIBRARIES" "${CMAKE_THREAD_LIBS_INIT}" ) set_target_properties(gtest_main PROPERTIES "IMPORTED_LOCATION" "${binary_dir}/googletest/${CMAKE_STATIC_LIBRARY_PREFIX}gtest_main${CMAKE_STATIC_LIBRARY_SUFFIX}" "IMPORTED_LINK_INTERFACE_LIBRARIES" "${CMAKE_THREAD_LIBS_INIT}" ) include_directories(${source_dir}/googletest/include) set(GTEST_LIBRARIES gtest) set(GTEST_BOTH_LIBRARIES gtest_main gtest) else() find_package(GTest REQUIRED) find_package(Threads REQUIRED) include_directories(GTEST_INCLUDE_DIRS) set(GTEST_BOTH_LIBRARIES gtest_main gtest ${CMAKE_THREAD_LIBS_INIT}) endif() ########################################## find_package(Doxygen) if(DOXYGEN_FOUND) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY) add_custom_target(doc ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMENT "Generating API documentation" VERBATIM) endif(DOXYGEN_FOUND) ##Warning level if (${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU" OR ${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic") elseif (${CMAKE_CXX_COMPILER_ID} STREQUAL "MSVC") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4") endif() include_directories(include) add_subdirectory(src) add_dependencies(Parsodus ext-optparse) enable_testing() add_subdirectory(tests) add_subdirectory(examples) install(DIRECTORY templates DESTINATION share/Parsodus ) install(DIRECTORY include/Parsodus DESTINATION include) install(EXPORT ParsodusTargets DESTINATION lib/cmake/Parsodus) install(FILES cmake/ParsodusConfig.cmake DESTINATION lib/cmake/Parsodus) install(DIRECTORY man/man1 man/man5 DESTINATION man)