forked from docopt/docopt.cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
141 lines (123 loc) · 5.62 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
cmake_minimum_required(VERSION 3.1)
project(docopt.cpp VERSION 0.6.1)
include(GNUInstallDirs)
#============================================================================
# Settable options
#============================================================================
option(WITH_TESTS "Build tests." OFF)
option(WITH_EXAMPLE "Build example." OFF)
option(USE_BOOST_REGEX "Replace std::regex with Boost.Regex" OFF)
#============================================================================
# Internal compiler options
#============================================================================
# C++ standard
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
if(NOT CMAKE_CXX_STANDARD OR CMAKE_CXX_STANDARD LESS 11)
set(CMAKE_CXX_STANDARD 11)
endif()
# Suppression of "unknown pragma" warning on GCC
if(CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unknown-pragmas") # Code uses #pragma mark
endif()
#============================================================================
# Sources & headers
#============================================================================
set(docopt_SOURCES docopt.cpp)
set(docopt_HEADERS
docopt.h
docopt_private.h
docopt_util.h
docopt_value.h
)
#============================================================================
# Compile targets
#============================================================================
if(XCODE)
# Xcode does not support libraries with only object files as sources.
# See https://cmake.org/cmake/help/v3.0/command/add_library.html?highlight=add_library
add_library(docopt SHARED ${docopt_SOURCES} ${docopt_HEADERS})
add_library(docopt_s STATIC ${docopt_SOURCES} ${docopt_HEADERS})
else()
# If not using Xcode, we will create an intermediate object target to avoid
# compiling the source code twice.
add_library(docopt_o OBJECT ${docopt_SOURCES} ${docopt_HEADERS})
set_target_properties(docopt_o PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
add_library(docopt SHARED $<TARGET_OBJECTS:docopt_o>)
add_library(docopt_s STATIC $<TARGET_OBJECTS:docopt_o>)
endif()
target_include_directories(docopt PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}> $<INSTALL_INTERFACE:include/docopt>)
target_include_directories(docopt_s PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}> $<INSTALL_INTERFACE:include/docopt>)
# To control the exporting of symbols (on Windows).
set_target_properties(docopt PROPERTIES DEFINE_SYMBOL DOCOPT_EXPORTS)
if(NOT MSVC)
set_target_properties(docopt PROPERTIES OUTPUT_NAME docopt)
set_target_properties(docopt_s PROPERTIES OUTPUT_NAME docopt)
endif()
if(USE_BOOST_REGEX)
add_definitions("-DDOCTOPT_USE_BOOST_REGEX")
# This is needed on Linux, where linking a static library into docopt.so
# fails because boost static libs are not compiled with -fPIC
set(Boost_USE_STATIC_LIBS OFF)
find_package(Boost 1.53 REQUIRED COMPONENTS regex)
include_directories(${Boost_INCLUDE_DIRS})
target_link_libraries(docopt ${Boost_LIBRARIES})
if(WITH_STATIC)
target_link_libraries(docopt_s ${Boost_LIBRARIES})
endif()
endif()
#============================================================================
# Examples
#============================================================================
if(WITH_EXAMPLE)
add_executable(docopt_example examples/naval_fate.cpp)
target_link_libraries(docopt_example docopt)
endif()
#============================================================================
# Tests
#============================================================================
if(WITH_TESTS)
set(TESTPROG "${CMAKE_CURRENT_BINARY_DIR}/run_testcase")
set(TESTCASES "${PROJECT_SOURCE_DIR}/testcases.docopt")
add_executable(run_testcase run_testcase.cpp)
target_link_libraries(run_testcase docopt)
configure_file(
"${PROJECT_SOURCE_DIR}/run_tests.py"
"${CMAKE_CURRENT_BINARY_DIR}/run_tests"
ESCAPE_QUOTES
)
add_test("Testcases docopt" ${TESTPROG})
endif()
#============================================================================
# Install
#============================================================================
set(export_name "docopt-targets")
# Runtime package
install(TARGETS docopt EXPORT ${export_name} DESTINATION ${CMAKE_INSTALL_LIBDIR})
# Development package
install(TARGETS docopt_s EXPORT ${export_name} DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(FILES ${docopt_HEADERS} DESTINATION include/docopt)
# CMake Package
include(CMakePackageConfigHelpers)
write_basic_package_version_file("${PROJECT_BINARY_DIR}/docopt-config-version.cmake" COMPATIBILITY SameMajorVersion)
install(FILES docopt-config.cmake ${PROJECT_BINARY_DIR}/docopt-config-version.cmake DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/docopt")
install(EXPORT ${export_name} DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/docopt")
#============================================================================
# CPack
#============================================================================
set(CPACK_PACKAGE_NAME "docopt")
set(CPACK_DEBIAN_PACKAGE_DEPENDS "")
set(CPACK_RPM_PACKAGE_REQUIRES "")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Beautiful command line interfaces")
set(CPACK_PACKAGE_VENDOR "Jared Grubb")
set(CPACK_PACKAGE_CONTACT ${CPACK_PACKAGE_VENDOR})
set(CPACK_PACKAGE_DESCRIPTION_FILE "${PROJECT_SOURCE_DIR}/README.rst")
set(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/LICENSE-MIT")
set(CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${PROJECT_VERSION_MINOR})
set(CPACK_PACKAGE_VERSION_PATCH ${PROJECT_VERSION_PATCH})
set(CPACK_DEBIAN_PACKAGE_SECTION "Development")
set(CPACK_RPM_PACKAGE_GROUP "Development/Libraries")
set(CPACK_RPM_PACKAGE_LICENSE "MIT")
set(CPACK_STRIP_FILES TRUE)
include(CPack)