• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
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
16cmake_minimum_required(VERSION 3.9)
17# Version number starts at 10 to avoid conflicts with Boost version
18set(_version 11.0.0)
19if(BOOST_SUPERPROJECT_SOURCE_DIR)
20  set(_version ${BOOST_SUPERPROJECT_VERSION})
21endif()
22project(boost_nowide VERSION ${_version} LANGUAGES CXX)
23
24if(POLICY CMP0074)
25  cmake_policy(SET CMP0074 NEW)
26endif()
27
28list(INSERT CMAKE_MODULE_PATH 0 ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
29
30if(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})
33endif()
34
35include(BoostAddOptions)
36include(BoostAddWarnings)
37include(CheckCXXSourceCompiles)
38if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
39  include(CTest)
40endif()
41
42file(READ ${CMAKE_CURRENT_SOURCE_DIR}/test/check_lfs_support.cpp lfsSource)
43check_cxx_source_compiles("${lfsSource}" BOOST_NOWIDE_HAS_LFS)
44
45# Using glob here is ok as it is only for headers
46file(GLOB_RECURSE headers include/*.hpp)
47add_library(boost_nowide src/cstdio.cpp src/cstdlib.cpp src/filebuf.cpp src/iostream.cpp src/stat.cpp ${headers})
48add_library(Boost::nowide ALIAS boost_nowide)
49set_target_properties(boost_nowide PROPERTIES
50    CXX_VISIBILITY_PRESET hidden
51    VISIBILITY_INLINES_HIDDEN ON
52    VERSION ${PROJECT_VERSION}
53    EXPORT_NAME nowide
54)
55if(BUILD_SHARED_LIBS)
56  target_compile_definitions(boost_nowide PUBLIC BOOST_NOWIDE_DYN_LINK)
57endif()
58if(NOT BOOST_NOWIDE_HAS_LFS)
59  target_compile_definitions(boost_nowide PRIVATE BOOST_NOWIDE_NO_LFS)
60endif()
61target_compile_definitions(boost_nowide PUBLIC BOOST_NOWIDE_NO_LIB)
62target_include_directories(boost_nowide PUBLIC include)
63boost_add_warnings(boost_nowide pedantic ${Boost_NOWIDE_WERROR})
64target_compile_features(boost_nowide PUBLIC cxx_std_11)
65
66if(BOOST_SUPERPROJECT_SOURCE_DIR)
67  target_link_libraries(boost_nowide PUBLIC Boost::config)
68else()
69  find_package(Boost 1.56 REQUIRED)
70  target_link_libraries(boost_nowide PUBLIC Boost::boost)
71endif()
72
73if(BUILD_TESTING)
74  add_subdirectory(test)
75endif()
76
77if(Boost_NOWIDE_INSTALL)
78  include(InstallTargets)
79  install_targets(TARGETS boost_nowide NAMESPACE Boost CONFIG_FILE ${PROJECT_SOURCE_DIR}/Config.cmake.in)
80endif()
81