Update TODO
[dueringa_WikiWalker.git] / src / CMakeLists.txt
blob4679950e20f48c61de91a8f84a260fbe88bc6c6d
1 cmake_minimum_required(VERSION 3.1.0)
2 project(WikiWalker VERSION 0.2.0)
4 set(walker_version "v${PROJECT_VERSION}")
6 add_custom_target(
7     gitversion
8     ${CMAKE_COMMAND}
9     -D SRC=${CMAKE_SOURCE_DIR}/inc/
10     -D BIN=${CMAKE_CURRENT_BINARY_DIR}
11     -D walker_version=${walker_version}
12     -P ${CMAKE_CURRENT_SOURCE_DIR}/version.cmake
15 find_package(CURL REQUIRED)
17 find_package(Boost
18     COMPONENTS program_options
21 set(ww_cmdparse_helpstring "Command line parser to use (boostpo or getopt)")
23 set(WW_COMMANDLINEPARSER "" CACHE STRING ${ww_cmdparse_helpstring})
25 # empty list, otherwise we end up appending forever
26 set_property(CACHE WW_COMMANDLINEPARSER PROPERTY STRINGS)
28 # if boost found
29 if(Boost_PROGRAM_OPTIONS_FOUND)
30     set_property(CACHE WW_COMMANDLINEPARSER APPEND PROPERTY STRINGS "boostpo")
31     # set default value to boostpo
32     if(WW_COMMANDLINEPARSER STREQUAL "")
33         set(WW_COMMANDLINEPARSER "boostpo" CACHE STRING
34             ${ww_cmdparse_helpstring} FORCE)
35     endif()
36 endif() #Boost_PROGRAM_OPTIONS_FOUND
38 message("Checking whether getopt is available.")
39 include(CheckFunctionExists)
40 include(CheckIncludeFile)
41 check_function_exists(getopt_long  HAS_GETOPT_FUNCTION)
42 check_include_file(getopt.h  HAS_GETOPT_HEADER)
44 if(HAS_GETOPT_FUNCTION AND HAS_GETOPT_HEADER)
45     set_property(CACHE WW_COMMANDLINEPARSER APPEND PROPERTY STRINGS "getopt")
46     # set default value to getopt
47     if(WW_COMMANDLINEPARSER STREQUAL "")
48         set(WW_COMMANDLINEPARSER "getopt" CACHE STRING
49             ${ww_cmdparse_helpstring} FORCE)
50     endif()
51 endif() #HAS_GETOPT_FUNCTION AND HAS_GETOPT_HEADER
53 if("${WW_COMMANDLINEPARSER}" STREQUAL "boostpo")
54     set(WW_USE_BOOST_PO TRUE)
55 elseif("${WW_COMMANDLINEPARSER}" STREQUAL "getopt")
56     set(WW_USE_GETOPT TRUE)
57 else()
58     message(SEND_ERROR "Must use either getopt or boost. Make sure \
59 either is available and set WW_COMMANDLINEPARSER")
60 endif()
62 configure_file(
63     "${CMAKE_SOURCE_DIR}/inc/config.h.in"
64     "${CMAKE_CURRENT_BINARY_DIR}/config.h"
67 # Define commonly used source files (with tests)
68 add_library(WikiWalkerSource OBJECT
69     ${CMAKE_CURRENT_SOURCE_DIR}/Article.cpp
70     ${CMAKE_CURRENT_SOURCE_DIR}/ArticleCollection.cpp
71     ${CMAKE_CURRENT_SOURCE_DIR}/CommandLineParserBase.cpp
72     ${CMAKE_CURRENT_SOURCE_DIR}/CommandLineParserUtils.cpp
73     ${CMAKE_CURRENT_SOURCE_DIR}/CurlUrlCreator.cpp
74     ${CMAKE_CURRENT_SOURCE_DIR}/CurlWikiGrabber.cpp
75     ${CMAKE_CURRENT_SOURCE_DIR}/DataOutputBase.cpp
76     ${CMAKE_CURRENT_SOURCE_DIR}/JsonSerializer.cpp
77     ${CMAKE_CURRENT_SOURCE_DIR}/StringUtils.cpp
78     ${CMAKE_CURRENT_SOURCE_DIR}/ToGraphvizWriter.cpp
79     ${CMAKE_CURRENT_SOURCE_DIR}/Walker.cpp
80     ${CMAKE_CURRENT_SOURCE_DIR}/WalkerException.cpp
81     ${CMAKE_CURRENT_SOURCE_DIR}/WikimediaApi.cpp
82     ${CMAKE_CURRENT_SOURCE_DIR}/WikimediaJsonToArticleConverter.cpp
83     ${CMAKE_CURRENT_SOURCE_DIR}/WikiWalker.cpp
85     ${CMAKE_SOURCE_DIR}/inc/Article.h
86     ${CMAKE_SOURCE_DIR}/inc/ArticleCollection.h
87     ${CMAKE_SOURCE_DIR}/inc/CommandLineParserBase.h
88     ${CMAKE_SOURCE_DIR}/inc/CommandLineParserUtils.h
89     ${CMAKE_SOURCE_DIR}/inc/CurlUrlCreator.h
90     ${CMAKE_SOURCE_DIR}/inc/CurlWikiGrabber.h
91     ${CMAKE_SOURCE_DIR}/inc/DataOutputBase.h
92     ${CMAKE_SOURCE_DIR}/inc/JsonSerializer.h
93     ${CMAKE_SOURCE_DIR}/inc/StringUtils.h
94     ${CMAKE_SOURCE_DIR}/inc/ToGraphvizWriter.h
95     ${CMAKE_SOURCE_DIR}/inc/Walker.h
96     ${CMAKE_SOURCE_DIR}/inc/WalkerException.h
97     ${CMAKE_SOURCE_DIR}/inc/WikimediaApi.h
98     ${CMAKE_SOURCE_DIR}/inc/WikimediaJsonToArticleConverter.h
99     ${CMAKE_SOURCE_DIR}/inc/WikiWalker.h
102 target_include_directories(WikiWalkerSource BEFORE PRIVATE
103     ${CURL_INCLUDE_DIRS}
104     $<TARGET_PROPERTY:jsoncpp,INTERFACE_INCLUDE_DIRECTORIES>
105     $<TARGET_PROPERTY:lurlparser,INTERFACE_INCLUDE_DIRECTORIES>
106     ${CMAKE_SOURCE_DIR}/inc/
109 add_executable(walker
110     ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp
111     $<TARGET_OBJECTS:WikiWalkerSource>
114 if(${WW_USE_BOOST_PO})
115     target_sources(walker PRIVATE
116         ${CMAKE_CURRENT_SOURCE_DIR}/BoostPoCommandLineParser.cpp
117         ${CMAKE_SOURCE_DIR}/inc/BoostPoCommandLineParser.h
118     )
119 elseif(${WW_USE_GETOPT})
120     target_sources(walker PRIVATE
121         ${CMAKE_CURRENT_SOURCE_DIR}/GetoptCommandLineParser.cpp
122         ${CMAKE_SOURCE_DIR}/inc/GetoptCommandLineParser.h
123     )
124 endif()
126 # Compiler options
127 option(WW_EXTENDED_WARNINGS "Enable extended compiler warnings for gcc / clang")
129 if(WW_EXTENDED_WARNINGS)
130     if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "[Cc]lang")
131         target_compile_options(WikiWalkerSource PRIVATE
132             -Wall -Wextra -Wshadow -Werror=return-type)
133         target_compile_options(walker PRIVATE
134             -Wall -Wextra -Wshadow -Werror=return-type)
135     endif() # clang or gcc
137     if(CMAKE_CXX_COMPILER_ID MATCHES "[Cc]lang")
138         target_compile_options(WikiWalkerSource PRIVATE
139             -Weverything -Wno-c++98-compat -Wno-padded)
140         target_compile_options(walker PRIVATE
141             -Weverything -Wno-c++98-compat -Wno-padded)
142     endif() # clang
143     
144     if(MSVC)
145         # Wall emits too many "(not) inlined" warnings
146         target_compile_options(WikiWalkerSource PRIVATE /W4)
147         target_compile_options(walker PRIVATE /W4)
148     endif() #MSVC
149 endif() # WW_EXTENDED_WARNINGS
151 target_link_libraries(walker
152     ${CURL_LIBRARIES}
153     jsoncpp
154     lurlparser
157 # if boost wanted
158 if(${WW_USE_BOOST_PO})
159     target_include_directories(walker PRIVATE
160         ${Boost_INCLUDE_DIR}
161     )
162     target_link_libraries(walker
163         ${Boost_PROGRAM_OPTIONS_LIBRARY}
164     )
165 endif()
167 target_include_directories(walker PRIVATE
168     ${CMAKE_SOURCE_DIR}/inc/
169     ${CMAKE_CURRENT_BINARY_DIR}
172 install(TARGETS walker DESTINATION bin)
174 enable_testing()
175 add_test(NAME versiondisplay
176     COMMAND walker -v)
178 add_dependencies(walker gitversion)