]>
Commit | Line | Data |
---|---|---|
20effc67 TL |
1 | # Copyright 2019 - 2020 Alexander Grund |
2 | # Distributed under the Boost Software License, Version 1.0. | |
3 | # (See accompanying file LICENSE or copy at http://boost.org/LICENSE_1_0.txt) | |
4 | ||
f67539c2 TL |
5 | # Builds the libraries for Boost.Nowide |
6 | # | |
7 | # Options: | |
8 | # Boost_NOWIDE_INSTALL | |
9 | # Boost_NOWIDE_WERROR | |
10 | # BUILD_TESTING | |
11 | # | |
12 | # Created target: Boost::nowide | |
13 | # | |
14 | # When not using CMake to link against the shared library on windows define -DBOOST_NOWIDE_DYN_LINK | |
15 | ||
16 | cmake_minimum_required(VERSION 3.9) | |
17 | # Version number starts at 10 to avoid conflicts with Boost version | |
1e59de90 | 18 | set(_version 11.1.4) |
f67539c2 TL |
19 | if(BOOST_SUPERPROJECT_SOURCE_DIR) |
20 | set(_version ${BOOST_SUPERPROJECT_VERSION}) | |
21 | endif() | |
22 | project(boost_nowide VERSION ${_version} LANGUAGES CXX) | |
23 | ||
24 | if(POLICY CMP0074) | |
25 | cmake_policy(SET CMP0074 NEW) | |
26 | endif() | |
27 | ||
28 | list(INSERT CMAKE_MODULE_PATH 0 ${CMAKE_CURRENT_SOURCE_DIR}/cmake) | |
29 | ||
30 | if(NOT CMAKE_RUNTIME_OUTPUT_DIRECTORY) | |
31 | # Make sure all binarys (especially exe/dll) are in one directory for tests to work | |
32 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) | |
33 | endif() | |
34 | ||
f67539c2 | 35 | include(BoostAddWarnings) |
20effc67 | 36 | include(CheckCXXSourceCompiles) |
f67539c2 TL |
37 | if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) |
38 | include(CTest) | |
1e59de90 TL |
39 | set(def_INSTALL ON) |
40 | set(def_WERROR ON) | |
41 | elseif(BOOST_SUPERPROJECT_SOURCE_DIR) | |
42 | set(Boost_NOWIDE_INSTALL OFF) # Done by the superproject | |
43 | set(def_WERROR ON) | |
44 | else() | |
45 | set(def_INSTALL OFF) | |
46 | set(def_WERROR OFF) | |
47 | endif() | |
48 | ||
49 | if(NOT BOOST_SUPERPROJECT_SOURCE_DIR) | |
50 | option(Boost_NOWIDE_INSTALL "Install library" "${def_INSTALL}") | |
f67539c2 | 51 | endif() |
1e59de90 TL |
52 | option(Boost_NOWIDE_WERROR "Treat warnings as errors" "${def_WERROR}") |
53 | ||
f67539c2 | 54 | |
20effc67 TL |
55 | file(READ ${CMAKE_CURRENT_SOURCE_DIR}/config/check_lfs_support.cpp lfsSource) |
56 | check_cxx_source_compiles("${lfsSource}" BOOST_NOWIDE_HAS_LFS) | |
1e59de90 TL |
57 | file(READ ${CMAKE_CURRENT_SOURCE_DIR}/config/check_attribute_init_priority.cpp attributeInitPrioritySource) |
58 | check_cxx_source_compiles("${attributeInitPrioritySource}" BOOST_NOWIDE_HAS_INIT_PRIORITY) | |
20effc67 | 59 | |
f67539c2 TL |
60 | # Using glob here is ok as it is only for headers |
61 | file(GLOB_RECURSE headers include/*.hpp) | |
1e59de90 | 62 | add_library(boost_nowide src/console_buffer.cpp src/cstdio.cpp src/cstdlib.cpp src/filebuf.cpp src/iostream.cpp src/stat.cpp ${headers}) |
f67539c2 TL |
63 | add_library(Boost::nowide ALIAS boost_nowide) |
64 | set_target_properties(boost_nowide PROPERTIES | |
65 | CXX_VISIBILITY_PRESET hidden | |
66 | VISIBILITY_INLINES_HIDDEN ON | |
67 | VERSION ${PROJECT_VERSION} | |
68 | EXPORT_NAME nowide | |
69 | ) | |
70 | if(BUILD_SHARED_LIBS) | |
71 | target_compile_definitions(boost_nowide PUBLIC BOOST_NOWIDE_DYN_LINK) | |
72 | endif() | |
20effc67 TL |
73 | if(NOT BOOST_NOWIDE_HAS_LFS) |
74 | target_compile_definitions(boost_nowide PRIVATE BOOST_NOWIDE_NO_LFS) | |
75 | endif() | |
1e59de90 TL |
76 | if(BOOST_NOWIDE_HAS_INIT_PRIORITY) |
77 | target_compile_definitions(boost_nowide PRIVATE BOOST_NOWIDE_HAS_INIT_PRIORITY) | |
78 | endif() | |
f67539c2 TL |
79 | target_compile_definitions(boost_nowide PUBLIC BOOST_NOWIDE_NO_LIB) |
80 | target_include_directories(boost_nowide PUBLIC include) | |
81 | boost_add_warnings(boost_nowide pedantic ${Boost_NOWIDE_WERROR}) | |
20effc67 | 82 | target_compile_features(boost_nowide PUBLIC cxx_std_11) |
f67539c2 | 83 | |
1e59de90 TL |
84 | if(BOOST_SUPERPROJECT_SOURCE_DIR OR TARGET Boost::config) |
85 | target_link_libraries(boost_nowide PUBLIC | |
86 | Boost::config | |
87 | ) | |
f67539c2 | 88 | else() |
1e59de90 TL |
89 | if(NOT TARGET Boost::boost) |
90 | # Default boost libs are static on windows and dynamic on linux | |
91 | if(WIN32 AND NOT DEFINED Boost_USE_STATIC_LIBS) | |
92 | set(Boost_USE_STATIC_LIBS ON) | |
93 | endif() | |
94 | find_package(Boost 1.56 REQUIRED) | |
f67539c2 | 95 | endif() |
f67539c2 TL |
96 | target_link_libraries(boost_nowide PUBLIC Boost::boost) |
97 | endif() | |
98 | ||
99 | if(BUILD_TESTING) | |
100 | add_subdirectory(test) | |
101 | endif() | |
102 | ||
103 | if(Boost_NOWIDE_INSTALL) | |
104 | include(InstallTargets) | |
105 | install_targets(TARGETS boost_nowide NAMESPACE Boost CONFIG_FILE ${PROJECT_SOURCE_DIR}/Config.cmake.in) | |
106 | endif() |