Parsodus/CMakeLists.txt

136 lines
4.8 KiB
CMake

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)
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})
find_program(LEXESIS_EXE Lexesis)
if (NOT LEXESIS_EXE_FOUND)
ExternalProject_Add(ext-lexesis
GIT_REPOSITORY git@gitlab.com:Robin_Jadoul/Lexesis.git
)
ExternalProject_Get_Property(ext-lexesis binary_dir)
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)
set(CMAKE_INSTALL_PREFIX "${CMAKE_CURRENT_BINARY_DIR}")
##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)
enable_testing()
add_subdirectory(tests)
add_dependencies(Parsodus ext-optparse)
install(DIRECTORY templates
DESTINATION share/Parsodus
)
# add_subdirectory(examples)