Merge pull request #64 from jbzdarkid/patch-1
[cppcodec.git] / CMakeLists.txt
1 cmake_minimum_required(VERSION 2.8.5)
2 project(cppcodec CXX)
3 set(PROJECT_VERSION 0.1)
4
5 include(GNUInstallDirs)
6 include(CTest)
7
8 # These flags are for binaries built by this particular CMake project (test_cppcodec, base64enc, etc.).
9 # In your own project that uses cppcodec, you might want to specify a different standard or error level.
10
11 # Request C++11, or let the user specify the standard on via -D command line option.
12 if (NOT CMAKE_CXX_STANDARD)
13   set(CMAKE_CXX_STANDARD 11)
14 endif()
15 set(CMAKE_CXX_STANDARD_REQUIRED ON)
16 set(CMAKE_CXX_EXTENSIONS OFF)
17
18 if (MSVC)
19   # MSVC will respect CMAKE_CXX_STANDARD for CMake >= 3.10 and MSVC >= 19.0.24215
20   # (VS 2017 15.3). Older versions will use the compiler default, which should be
21   # fine for anything except ancient MSVC versions.
22   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
23 else()
24   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic")
25
26   # CMake versions before 3.1 do not understand CMAKE_CXX_STANDARD.
27   # Remove this block once CMake >=3.1 has fixated in the ecosystem.
28   if(${CMAKE_VERSION} VERSION_LESS 3.1)
29     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++${CMAKE_CXX_STANDARD}")
30   endif()
31 endif()
32
33 set(PUBLIC_HEADERS
34     # base32
35     cppcodec/base32_crockford.hpp
36     cppcodec/base32_default_crockford.hpp
37     cppcodec/base32_default_hex.hpp
38     cppcodec/base32_default_rfc4648.hpp
39     cppcodec/base32_hex.hpp
40     cppcodec/base32_rfc4648.hpp
41     # base64
42     cppcodec/base64_default_rfc4648.hpp
43     cppcodec/base64_default_url.hpp
44     cppcodec/base64_default_url_unpadded.hpp
45     cppcodec/base64_rfc4648.hpp
46     cppcodec/base64_url.hpp
47     cppcodec/base64_url_unpadded.hpp
48     # hex
49     cppcodec/hex_default_lower.hpp
50     cppcodec/hex_default_upper.hpp
51     cppcodec/hex_lower.hpp
52     cppcodec/hex_upper.hpp
53     # other stuff
54     cppcodec/parse_error.hpp
55     cppcodec/data/access.hpp
56     cppcodec/data/raw_result_buffer.hpp
57     cppcodec/detail/base32.hpp
58     cppcodec/detail/base64.hpp
59     cppcodec/detail/codec.hpp
60     cppcodec/detail/config.hpp
61     cppcodec/detail/hex.hpp
62     cppcodec/detail/stream_codec.hpp)
63
64 add_library(cppcodec OBJECT ${PUBLIC_HEADERS}) # unnecessary for building, but makes headers show up in IDEs
65 set_target_properties(cppcodec PROPERTIES LINKER_LANGUAGE CXX)
66 add_subdirectory(tool)
67 add_subdirectory(example)
68
69 if (BUILD_TESTING)
70     add_subdirectory(test)
71 endif()
72
73 foreach(h ${PUBLIC_HEADERS})
74     get_filename_component(FINAL_PATH ${h} PATH) # use DIRECTORY instead of PATH once requiring CMake 3.0
75     install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${h} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${FINAL_PATH} COMPONENT "headers")
76 endforeach()
77
78 if (NOT WIN32)
79     configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cppcodec.pc.in ${CMAKE_CURRENT_BINARY_DIR}/cppcodec-1.pc @ONLY)
80     install(FILES ${CMAKE_CURRENT_BINARY_DIR}/cppcodec-1.pc DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig)
81 endif()