Modernise CMake
[cppcodec.git] / CMakeLists.txt
1 cmake_minimum_required(VERSION 2.8.5)
2 project(cppcodec CXX)
3
4 include(GNUInstallDirs)
5 include(CTest)
6
7 # These flags are for binaries built by this particular CMake project (test_cppcodec, base64enc, etc.).
8 # In your own project that uses cppcodec, you might want to specify a different standard or error level.
9 if (MSVC)
10   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W3")
11 else()
12   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic")
13
14   # Request C++11
15   if(${CMAKE_VERSION} VERSION_LESS 3.1)
16     # CMake versions before 3.1 do not understand CMAKE_CXX_STANDARD
17     # remove this block once CMake >=3.1 has fixated in the ecosystem
18     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
19   else()
20     set(CMAKE_CXX_STANDARD 11)
21     set(CMAKE_CXX_STANDARD_REQUIRED ON)
22     set(CMAKE_CXX_EXTENSIONS OFF)
23   endif()
24 endif()
25
26 set(PUBLIC_HEADERS
27     # base32
28     cppcodec/base32_crockford.hpp
29     cppcodec/base32_default_crockford.hpp
30     cppcodec/base32_default_hex.hpp
31     cppcodec/base32_default_rfc4648.hpp
32     cppcodec/base32_hex.hpp
33     cppcodec/base32_rfc4648.hpp
34     # base64
35     cppcodec/base64_default_rfc4648.hpp
36     cppcodec/base64_default_url.hpp
37     cppcodec/base64_default_url_unpadded.hpp
38     cppcodec/base64_rfc4648.hpp
39     cppcodec/base64_url.hpp
40     cppcodec/base64_url_unpadded.hpp
41     # hex
42     cppcodec/hex_default_lower.hpp
43     cppcodec/hex_default_upper.hpp
44     cppcodec/hex_lower.hpp
45     cppcodec/hex_upper.hpp
46     # other stuff
47     cppcodec/parse_error.hpp
48     cppcodec/data/access.hpp
49     cppcodec/data/raw_result_buffer.hpp
50     cppcodec/detail/base32.hpp
51     cppcodec/detail/base64.hpp
52     cppcodec/detail/codec.hpp
53     cppcodec/detail/config.hpp
54     cppcodec/detail/hex.hpp
55     cppcodec/detail/stream_codec.hpp)
56
57 add_library(cppcodec OBJECT ${PUBLIC_HEADERS}) # unnecessary for building, but makes headers show up in IDEs
58 set_target_properties(cppcodec PROPERTIES LINKER_LANGUAGE CXX)
59 add_subdirectory(tool)
60
61 if (BUILD_TESTING)
62     add_subdirectory(test)
63 endif()
64
65 foreach(h ${PUBLIC_HEADERS})
66     get_filename_component(FINAL_PATH ${h} PATH) # use DIRECTORY instead of PATH once requiring CMake 3.0
67     install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${h} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${FINAL_PATH} COMPONENT "headers")
68 endforeach()