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)
5 # Builds the libraries for Boost.Nowide
12 # Created target: Boost::nowide
14 # When not using CMake to link against the shared library on windows define -DBOOST_NOWIDE_DYN_LINK
16 cmake_minimum_required(VERSION 3.9)
17 # Version number starts at 10 to avoid conflicts with Boost version
19 if(BOOST_SUPERPROJECT_SOURCE_DIR)
20 set(_version ${BOOST_SUPERPROJECT_VERSION})
22 project(boost_nowide VERSION ${_version} LANGUAGES CXX)
25 cmake_policy(SET CMP0074 NEW)
28 list(INSERT CMAKE_MODULE_PATH 0 ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
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})
35 include(BoostAddOptions)
36 include(BoostAddWarnings)
37 include(CheckCXXSourceCompiles)
38 if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
42 file(READ ${CMAKE_CURRENT_SOURCE_DIR}/config/check_lfs_support.cpp lfsSource)
43 check_cxx_source_compiles("${lfsSource}" BOOST_NOWIDE_HAS_LFS)
45 # Using glob here is ok as it is only for headers
46 file(GLOB_RECURSE headers include/*.hpp)
47 add_library(boost_nowide src/cstdio.cpp src/cstdlib.cpp src/filebuf.cpp src/iostream.cpp src/stat.cpp ${headers})
48 add_library(Boost::nowide ALIAS boost_nowide)
49 set_target_properties(boost_nowide PROPERTIES
50 CXX_VISIBILITY_PRESET hidden
51 VISIBILITY_INLINES_HIDDEN ON
52 VERSION ${PROJECT_VERSION}
56 target_compile_definitions(boost_nowide PUBLIC BOOST_NOWIDE_DYN_LINK)
58 if(NOT BOOST_NOWIDE_HAS_LFS)
59 target_compile_definitions(boost_nowide PRIVATE BOOST_NOWIDE_NO_LFS)
61 target_compile_definitions(boost_nowide PUBLIC BOOST_NOWIDE_NO_LIB)
62 target_include_directories(boost_nowide PUBLIC include)
63 boost_add_warnings(boost_nowide pedantic ${Boost_NOWIDE_WERROR})
64 target_compile_features(boost_nowide PUBLIC cxx_std_11)
66 if(BOOST_SUPERPROJECT_SOURCE_DIR)
67 target_link_libraries(boost_nowide PUBLIC Boost::config)
69 # Default boost libs are static on windows and dynamic on linux
70 if(WIN32 AND NOT DEFINED Boost_USE_STATIC_LIBS)
71 set(Boost_USE_STATIC_LIBS ON)
73 find_package(Boost 1.56 REQUIRED)
74 target_link_libraries(boost_nowide PUBLIC Boost::boost)
78 add_subdirectory(test)
81 if(Boost_NOWIDE_INSTALL)
82 include(InstallTargets)
83 install_targets(TARGETS boost_nowide NAMESPACE Boost CONFIG_FILE ${PROJECT_SOURCE_DIR}/Config.cmake.in)