2017-01-30 16:34:56 +01:00
# 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.
2016-11-09 13:04:56 +01:00
cmake_minimum_required ( VERSION 3.2.2 )
project ( Parsodus VERSION 1.0 )
2016-11-25 16:30:56 +01:00
set ( CMAKE_CXX_STANDARD 14 )
set ( CMAKE_CXX_STANDARD_REQUIRED 14 )
2016-11-09 13:04:56 +01:00
2016-11-27 14:49:28 +01:00
set ( CMAKE_MODULE_PATH ${ CMAKE_MODULE_PATH } ${ CMAKE_CURRENT_SOURCE_DIR } /cmake )
2016-11-09 13:04:56 +01:00
2017-01-26 20:59:17 +01:00
find_package ( Threads )
2016-11-09 13:04:56 +01:00
include ( ExternalProject )
find_package ( mstch QUIET )
2017-01-27 20:49:29 +01:00
2016-11-09 13:04:56 +01:00
if ( NOT mstch_FOUND )
ExternalProject_Add ( ext-mstch
G I T _ R E P O S I T O R Y h t t p s : / / g i t h u b . c o m / n o 1 m s d / m s t c h
G I T _ T A G 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
G I T _ S U B M O D U L E S " N O N E \ C O M M A N D \ t r u e \ E R R O R _ Q U I E T "
C M A K E _ A R G S - D W I T H _ U N I T _ T E S T S = N O
I N S T A L L _ C O M M A N D " "
)
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
G I T _ R E P O S I T O R Y h t t p s : / / g i t h u b . c o m / m y i n t / o p t p a r s e
C O N F I G U R E _ C O M M A N D " "
B U I L D _ C O M M A N D " "
I N S T A L L _ C O M M A N D " "
)
ExternalProject_Get_Property ( ext-optparse source_dir )
include_directories ( ${ source_dir } )
2016-11-27 14:06:26 +01:00
2017-01-26 20:59:17 +01:00
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 )
2017-01-27 17:18:03 +01:00
find_program ( GIT_COMMAND git )
if ( ${ GIT_COMMAND } STREQUAL "GIT_COMMAND-NOTFOUND" )
ExternalProject_Add ( ext-g3log
G I T _ R E P O S I T O R Y h t t p s : / / g i t h u b . c o m / K j e l l K o d / g 3 l o g
C M A K E _ A R G S - D A D D _ F A T A L _ E X A M P L E = O F F
I N S T A L L _ C O M M A N D " "
)
else ( )
ExternalProject_Add ( ext-g3log
G I T _ R E P O S I T O R Y h t t p s : / / g i t h u b . c o m / K j e l l K o d / g 3 l o g
C M A K E _ A R G S - D A D D _ F A T A L _ E X A M P L E = O F F
P A T C H _ C O M M A N D " $ { G I T _ C O M M A N D } " a p p l y < " $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / c m a k e / g 3 l o g - p a t c h . p a t c h "
I N S T A L L _ C O M M A N D " "
)
endif ( )
2017-01-26 20:59:17 +01:00
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 } )
2017-01-26 16:14:00 +01:00
find_package ( Lexesis QUIET )
if ( NOT LEXESIS_FOUND )
2016-11-27 14:06:26 +01:00
ExternalProject_Add ( ext-lexesis
2017-01-30 16:21:31 +01:00
G I T _ R E P O S I T O R Y h t t p s : / / g i t l a b . c o m / R o b i n _ J a d o u l / L e x e s i s . g i t
2017-01-26 16:14:00 +01:00
C M A K E _ A R G S - D C M A K E _ I N S T A L L _ P R E F I X = .
2016-11-27 14:06:26 +01:00
)
2017-01-20 13:28:09 +01:00
add_library ( templ IMPORTED STATIC GLOBAL )
2017-01-27 20:49:29 +01:00
add_library ( lxsinput IMPORTED STATIC GLOBAL )
2017-01-20 13:28:09 +01:00
add_dependencies ( templ ext-lexesis )
2017-01-27 20:49:29 +01:00
add_dependencies ( lxsinput ext-lexesis )
2017-01-20 13:28:09 +01:00
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}" )
2017-01-27 20:49:29 +01:00
set_target_properties ( lxsinput PROPERTIES "IMPORTED_LOCATION" "${binary_dir}/src/${CMAKE_STATIC_LIBRARY_PREFIX}lxsinput${CMAKE_STATIC_LIBRARY_SUFFIX}" )
2017-01-26 16:14:00 +01:00
include_directories ( ${ binary_dir } /include )
2016-11-27 14:06:26 +01:00
set ( LEXESIS_EXE "${binary_dir}/bin/Lexesis" )
endif ( )
2016-11-27 14:49:28 +01:00
#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
G I T _ R E P O S I T O R Y h t t p s : / / g i t h u b . c o m / l i n u x - t e s t - p r o j e c t / l c o v
C O N F I G U R E _ C O M M A N D " "
B U I L D _ C O M M A N D " "
I N S T A L L _ C O M M A N D " "
T E S T _ C O M M A N D " " )
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
G I T _ R E P O S I T O R Y h t t p s : / / g i t h u b . c o m / g o o g l e / g o o g l e t e s t . g i t
C M A K E _ A R G S - D B U I L D _ G M O C K = N O - D B U I L D _ G T E S T = Y E S
I N S T A L L _ C O M M A N D " "
)
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
" I M P O R T E D _ L O C A T I O N " " $ { b i n a r y _ d i r } / g o o g l e t e s t / $ { C M A K E _ S T A T I C _ L I B R A R Y _ P R E F I X } g t e s t $ { C M A K E _ S T A T I C _ L I B R A R Y _ S U F F I X } "
" I M P O R T E D _ L I N K _ I N T E R F A C E _ L I B R A R I E S " " $ { C M A K E _ T H R E A D _ L I B S _ I N I T } "
)
set_target_properties ( gtest_main PROPERTIES
" I M P O R T E D _ L O C A T I O N " " $ { b i n a r y _ d i r } / g o o g l e t e s t / $ { C M A K E _ S T A T I C _ L I B R A R Y _ P R E F I X } g t e s t _ m a i n $ { C M A K E _ S T A T I C _ L I B R A R Y _ S U F F I X } "
" I M P O R T E D _ L I N K _ I N T E R F A C E _ L I B R A R I E S " " $ { C M A K E _ T H R E A D _ L I B S _ I N I T } "
)
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 ( )
2016-11-09 13:04:56 +01:00
##########################################
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 )
2016-11-27 14:49:28 +01:00
##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 ( )
2016-11-09 13:04:56 +01:00
include_directories ( include )
add_subdirectory ( src )
2017-01-21 11:05:25 +01:00
add_dependencies ( Parsodus ext-optparse )
2016-11-27 14:49:28 +01:00
enable_testing ( )
add_subdirectory ( tests )
2017-01-21 11:05:25 +01:00
add_subdirectory ( examples )
2016-11-09 13:04:56 +01:00
install ( DIRECTORY templates
D E S T I N A T I O N s h a r e / P a r s o d u s
)
2017-01-26 16:14:00 +01:00
install ( DIRECTORY include/Parsodus
D E S T I N A T I O N i n c l u d e )
2017-01-30 16:21:31 +01:00
install ( EXPORT ParsodusTargets DESTINATION lib/cmake/Parsodus )
install ( FILES cmake/ParsodusConfig.cmake DESTINATION lib/cmake/Parsodus )
install ( DIRECTORY man/man1 man/man5 DESTINATION man )