2010-12-11 03:47:54 +08:00
|
|
|
# See www/CMake.html for instructions on how to build libcxx with CMake.
|
|
|
|
|
|
|
|
#===============================================================================
|
|
|
|
# Setup Project
|
|
|
|
#===============================================================================
|
|
|
|
|
|
|
|
project(libcxx CXX C)
|
|
|
|
cmake_minimum_required(VERSION 2.8)
|
|
|
|
|
|
|
|
set(PACKAGE_NAME libcxx)
|
|
|
|
set(PACKAGE_VERSION trunk-svn)
|
|
|
|
set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
|
|
|
|
set(PACKAGE_BUGREPORT "llvmbugs@cs.uiuc.edu")
|
|
|
|
|
|
|
|
# Add path for custom modules
|
|
|
|
set(CMAKE_MODULE_PATH
|
|
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/cmake"
|
|
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules"
|
2013-09-30 17:10:01 +08:00
|
|
|
${CMAKE_MODULE_PATH}
|
2010-12-11 03:47:54 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
# Require out of source build.
|
|
|
|
include(MacroEnsureOutOfSourceBuild)
|
|
|
|
MACRO_ENSURE_OUT_OF_SOURCE_BUILD(
|
|
|
|
"${PROJECT_NAME} requires an out of source build. Please create a separate
|
|
|
|
build directory and run 'cmake /path/to/${PROJECT_NAME} [options]' there."
|
|
|
|
)
|
|
|
|
|
2013-10-04 05:58:25 +08:00
|
|
|
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
|
|
|
|
set(LIBCXX_BUILT_STANDALONE 1)
|
|
|
|
endif()
|
|
|
|
|
2010-12-11 03:47:54 +08:00
|
|
|
#===============================================================================
|
|
|
|
# Setup CMake Options
|
|
|
|
#===============================================================================
|
|
|
|
|
|
|
|
# Define options.
|
|
|
|
option(LIBCXX_ENABLE_EXCEPTIONS "Use exceptions." ON)
|
|
|
|
option(LIBCXX_ENABLE_RTTI "Use run time type information." ON)
|
|
|
|
option(LIBCXX_ENABLE_ASSERTIONS "Enable assertions independent of build mode." ON)
|
|
|
|
option(LIBCXX_ENABLE_PEDANTIC "Compile with pedantic enabled." ON)
|
|
|
|
option(LIBCXX_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF)
|
|
|
|
option(LIBCXX_ENABLE_CXX0X "Enable -std=c++0x and use of c++0x language features if the compiler supports it." ON)
|
|
|
|
option(LIBCXX_ENABLE_SHARED "Build libc++ as a shared library." ON)
|
2013-09-02 15:28:05 +08:00
|
|
|
option(LIBCXX_INSTALL_SUPPORT_HEADERS "Install libc++ support headers." ON)
|
2010-12-11 03:47:54 +08:00
|
|
|
|
2013-10-07 06:13:19 +08:00
|
|
|
set(CXXABIS none libcxxabi libcxxrt libstdc++ libsupc++)
|
2013-01-01 03:34:21 +08:00
|
|
|
if (NOT DEFINED LIBCXX_CXX_ABI)
|
|
|
|
set(LIBCXX_CXX_ABI "none")
|
|
|
|
endif()
|
2012-12-01 05:02:29 +08:00
|
|
|
set(LIBCXX_CXX_ABI "${LIBCXX_CXX_ABI}" CACHE STRING
|
|
|
|
"Specify C++ ABI library to use." FORCE)
|
2013-08-20 05:42:07 +08:00
|
|
|
set_property(CACHE LIBCXX_CXX_ABI PROPERTY STRINGS ;${CXXABIS})
|
2012-12-01 05:02:29 +08:00
|
|
|
|
2010-12-11 03:47:54 +08:00
|
|
|
#===============================================================================
|
|
|
|
# Configure System
|
|
|
|
#===============================================================================
|
|
|
|
|
|
|
|
# Get triples.
|
|
|
|
include(GetTriple)
|
|
|
|
get_host_triple(LIBCXX_HOST_TRIPLE
|
|
|
|
LIBCXX_HOST_ARCH
|
|
|
|
LIBCXX_HOST_VENDOR
|
|
|
|
LIBCXX_HOST_OS
|
|
|
|
)
|
|
|
|
set(LIBCXX_HOST_TRIPLE ${LIBCXX_HOST_TRIPLE} CACHE STRING "Host triple.")
|
|
|
|
get_target_triple(LIBCXX_TARGET_TRIPLE
|
|
|
|
LIBCXX_TARGET_ARCH
|
|
|
|
LIBCXX_TARGET_VENDOR
|
|
|
|
LIBCXX_TARGET_OS
|
|
|
|
)
|
|
|
|
set(LIBCXX_TARGET_TRIPLE ${LIBCXX_TARGET_TRIPLE} CACHE STRING "Target triple.")
|
|
|
|
|
2013-02-09 03:04:53 +08:00
|
|
|
#===============================================================================
|
|
|
|
# Add an ABI library if appropriate
|
|
|
|
#===============================================================================
|
|
|
|
|
|
|
|
#
|
|
|
|
# _setup_abi: Set up the build to use an ABI library
|
|
|
|
#
|
|
|
|
# Parameters:
|
|
|
|
# abidefines: A list of defines needed to compile libc++ with the ABI library
|
|
|
|
# abilibs : A list of libraries to link against
|
|
|
|
# abifiles : A list of files (which may be relative paths) to copy into the
|
|
|
|
# libc++ build tree for the build. These files will also be
|
|
|
|
# installed alongside the libc++ headers.
|
|
|
|
# abidirs : A list of relative paths to create under an include directory
|
|
|
|
# in the libc++ build directory.
|
|
|
|
#
|
|
|
|
macro(setup_abi_lib abipathvar abidefines abilibs abifiles abidirs)
|
|
|
|
list(APPEND LIBCXX_CXX_FEATURE_FLAGS ${abidefines})
|
|
|
|
set(${abipathvar} "${${abipathvar}}"
|
|
|
|
CACHE STRINGS
|
|
|
|
"Paths to ABI include directories separate by ';'."
|
|
|
|
)
|
|
|
|
set(LIBCXX_CXX_ABI_LIBRARIES ${abilibs})
|
|
|
|
set(LIBCXX_ABILIB_FILES ${abifiles})
|
2013-01-01 03:34:21 +08:00
|
|
|
file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/include")
|
2013-02-09 03:04:53 +08:00
|
|
|
foreach(_d ${abidirs})
|
|
|
|
file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/include/${_d}")
|
|
|
|
endforeach()
|
|
|
|
set(LIBCXX_ABILIB_FILE_PATHS)
|
|
|
|
foreach(fpath ${LIBCXX_ABILIB_FILES})
|
2012-12-01 05:02:29 +08:00
|
|
|
set(found FALSE)
|
2013-02-09 03:04:53 +08:00
|
|
|
foreach(incpath ${${abipathvar}})
|
|
|
|
if (EXISTS "${incpath}/${fpath}")
|
2012-12-01 05:02:29 +08:00
|
|
|
set(found TRUE)
|
2013-02-09 03:04:53 +08:00
|
|
|
get_filename_component(dstdir ${fpath} PATH)
|
|
|
|
get_filename_component(ifile ${fpath} NAME)
|
2012-12-01 05:02:29 +08:00
|
|
|
add_custom_command(
|
2013-02-09 03:04:53 +08:00
|
|
|
OUTPUT "${CMAKE_BINARY_DIR}/include/${dstdir}/${ifile}"
|
2012-12-01 05:02:29 +08:00
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
2013-02-09 03:04:53 +08:00
|
|
|
"${incpath}/${fpath}"
|
2013-04-03 05:33:01 +08:00
|
|
|
"${CMAKE_BINARY_DIR}/include/${dstdir}"
|
2013-02-09 03:04:53 +08:00
|
|
|
MAIN_DEPENDENCY "${incpath}/${fpath}"
|
2012-12-01 05:02:29 +08:00
|
|
|
)
|
|
|
|
list(APPEND LIBCXX_CXX_ABI_DEPS
|
2013-02-09 03:04:53 +08:00
|
|
|
"${CMAKE_BINARY_DIR}/include/${dstdir}/${ifile}"
|
|
|
|
)
|
2012-12-01 05:02:29 +08:00
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
if (NOT found)
|
2013-02-09 03:04:53 +08:00
|
|
|
message(FATAL_ERROR "Failed to find ${fpath}")
|
2012-12-01 05:02:29 +08:00
|
|
|
endif()
|
|
|
|
endforeach()
|
2013-02-09 03:04:53 +08:00
|
|
|
add_custom_target(abilib_headers DEPENDS ${LIBCXX_CXX_ABI_DEPS})
|
|
|
|
set(LIBCXX_CXX_ABI_DEPS abilib_headers)
|
2012-12-01 05:02:29 +08:00
|
|
|
include_directories("${CMAKE_BINARY_DIR}/include")
|
|
|
|
install(DIRECTORY "${CMAKE_BINARY_DIR}/include/"
|
|
|
|
DESTINATION include/c++/v1
|
|
|
|
FILES_MATCHING
|
|
|
|
PATTERN "*"
|
|
|
|
)
|
2013-02-09 03:04:53 +08:00
|
|
|
endmacro()
|
|
|
|
|
2013-10-07 06:13:19 +08:00
|
|
|
if ("${LIBCXX_CXX_ABI}" STREQUAL "libstdc++" OR
|
|
|
|
"${LIBCXX_CXX_ABI}" STREQUAL "libsupc++")
|
2013-02-09 03:04:53 +08:00
|
|
|
set(_LIBSUPCXX_INCLUDE_FILES
|
|
|
|
cxxabi.h bits/c++config.h bits/os_defines.h bits/cpu_defines.h
|
|
|
|
bits/cxxabi_tweaks.h bits/cxxabi_forced.h
|
|
|
|
)
|
2013-10-07 06:13:19 +08:00
|
|
|
if ("${LIBCXX_CXX_ABI}" STREQUAL "libstdc++")
|
|
|
|
set(_LIBSUPCXX_DEFINES "-DLIBSTDCXX")
|
|
|
|
set(_LIBSUPCXX_LIBNAME stdc++)
|
|
|
|
else()
|
|
|
|
set(_LIBSUPCXX_DEFINES "")
|
|
|
|
set(_LIBSUPCXX_LIBNAME supc++)
|
|
|
|
endif()
|
|
|
|
setup_abi_lib("LIBCXX_LIBSUPCXX_INCLUDE_PATHS"
|
|
|
|
"-D__GLIBCXX__ ${_LIBSUPCXX_DEFINES}"
|
|
|
|
"${_LIBSUPCXX_LIBNAME}" "${_LIBSUPCXX_INCLUDE_FILES}" "bits"
|
2013-02-09 03:04:53 +08:00
|
|
|
)
|
2013-02-07 23:27:39 +08:00
|
|
|
elseif ("${LIBCXX_CXX_ABI}" STREQUAL "libcxxabi")
|
2013-02-09 03:04:53 +08:00
|
|
|
setup_abi_lib("LIBCXX_LIBCXXABI_INCLUDE_PATHS" ""
|
2013-10-04 06:58:36 +08:00
|
|
|
"c++abi" "cxxabi.h" ""
|
2013-02-07 23:27:39 +08:00
|
|
|
)
|
|
|
|
elseif ("${LIBCXX_CXX_ABI}" STREQUAL "libcxxrt")
|
2013-02-09 03:04:53 +08:00
|
|
|
setup_abi_lib("LIBCXX_LIBCXXRT_INCLUDE_PATHS" "-DLIBCXXRT"
|
|
|
|
"cxxrt" "cxxabi.h;unwind.h;unwind-arm.h;unwind-itanium.h" ""
|
2013-02-07 23:27:39 +08:00
|
|
|
)
|
2013-01-01 03:34:21 +08:00
|
|
|
elseif (NOT "${LIBCXX_CXX_ABI}" STREQUAL "none")
|
2012-12-01 05:02:29 +08:00
|
|
|
message(FATAL_ERROR
|
2013-10-07 06:13:19 +08:00
|
|
|
"Currently libstdc++, libsupc++, libcxxabi, libcxxrt and none are "
|
2013-02-09 03:04:53 +08:00
|
|
|
"supported for c++ abi."
|
|
|
|
)
|
2012-12-01 05:02:29 +08:00
|
|
|
endif ()
|
|
|
|
|
2010-12-11 03:47:54 +08:00
|
|
|
# Configure compiler.
|
|
|
|
include(config-ix)
|
|
|
|
|
|
|
|
#===============================================================================
|
|
|
|
# Setup Compiler Flags
|
|
|
|
#===============================================================================
|
|
|
|
|
|
|
|
# Get required flags.
|
|
|
|
# On all systems the system c++ standard library headers need to be excluded.
|
|
|
|
if (MSVC)
|
|
|
|
# MSVC only has -X, which disables all default includes; including the crt.
|
|
|
|
# Thus, we do nothing and hope we don't accidentally include any of the C++
|
|
|
|
# headers.
|
|
|
|
else()
|
|
|
|
if (LIBCXX_HAS_NOSTDINCXX_FLAG)
|
|
|
|
set(LIBCXX_CXX_REQUIRED_FLAGS -nostdinc++)
|
|
|
|
endif()
|
|
|
|
if (LIBCXX_ENABLE_CXX0X AND LIBCXX_HAS_STDCXX0X_FLAG)
|
|
|
|
list(APPEND LIBCXX_CXX_REQUIRED_FLAGS -std=c++0x)
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
macro(append_if list condition var)
|
|
|
|
if (${condition})
|
|
|
|
list(APPEND ${list} ${var})
|
|
|
|
endif()
|
|
|
|
endmacro()
|
|
|
|
|
|
|
|
# Get warning flags
|
2013-10-05 08:07:35 +08:00
|
|
|
if (NOT MSVC)
|
|
|
|
append_if(LIBCXX_CXX_WARNING_FLAGS LIBCXX_HAS_WALL_FLAG -Wall)
|
2013-10-21 23:56:35 +08:00
|
|
|
set(LIBCXX_CXX_REQUIRED_FLAGS, -Werror=return-type)
|
2013-10-05 08:07:35 +08:00
|
|
|
endif()
|
2013-10-21 23:56:35 +08:00
|
|
|
|
2012-06-08 06:26:00 +08:00
|
|
|
append_if(LIBCXX_CXX_WARNING_FLAGS LIBCXX_HAS_W_FLAG -W)
|
|
|
|
append_if(LIBCXX_CXX_WARNING_FLAGS LIBCXX_HAS_WNO_UNUSED_PARAMETER_FLAG -Wno-unused-parameter)
|
|
|
|
append_if(LIBCXX_CXX_WARNING_FLAGS LIBCXX_HAS_WWRITE_STRINGS_FLAG -Wwrite-strings)
|
|
|
|
append_if(LIBCXX_CXX_WARNING_FLAGS LIBCXX_HAS_WNO_LONG_LONG_FLAG -Wno-long-long)
|
2010-12-11 03:47:54 +08:00
|
|
|
if (LIBCXX_ENABLE_WERROR)
|
2012-06-08 06:26:00 +08:00
|
|
|
append_if(LIBCXX_CXX_WARNING_FLAGS LIBCXX_HAS_WERROR_FLAG -Werror)
|
|
|
|
append_if(LIBCXX_CXX_WARNING_FLAGS LIBCXX_HAS_WX_FLAG -WX)
|
2013-10-02 15:44:19 +08:00
|
|
|
else()
|
|
|
|
append_if(LIBCXX_CXX_WARNING_FLAGS LIBCXX_HAS_WNO_ERROR_FLAG -Wno-error)
|
|
|
|
append_if(LIBCXX_CXX_WARNING_FLAGS LIBCXX_HAS_NO_WX_FLAG -WX-)
|
2010-12-11 03:47:54 +08:00
|
|
|
endif()
|
|
|
|
if (LIBCXX_ENABLE_PEDANTIC)
|
2012-06-08 06:26:00 +08:00
|
|
|
append_if(LIBCXX_CXX_WARNING_FLAGS LIBCXX_HAS_PEDANTIC_FLAG -pedantic)
|
2010-12-11 03:47:54 +08:00
|
|
|
endif()
|
|
|
|
|
|
|
|
# Get feature flags.
|
|
|
|
# Exceptions
|
|
|
|
if (LIBCXX_ENABLE_EXCEPTIONS)
|
|
|
|
# Catches C++ exceptions only and tells the compiler to assume that extern C
|
|
|
|
# functions never throw a C++ exception.
|
|
|
|
append_if(LIBCXX_CXX_FEATURE_FLAGS LIBCXX_HAS_EHSC_FLAG -EHsc)
|
|
|
|
else()
|
|
|
|
list(APPEND LIBCXX_CXX_FEATURE_FLAGS -D_LIBCPP_NO_EXCEPTIONS)
|
|
|
|
append_if(LIBCXX_CXX_FEATURE_FLAGS LIBCXX_HAS_NO_EHS_FLAG -EHs-)
|
|
|
|
append_if(LIBCXX_CXX_FEATURE_FLAGS LIBCXX_HAS_NO_EHA_FLAG -EHa-)
|
|
|
|
append_if(LIBCXX_CXX_FEATURE_FLAGS LIBCXX_HAS_FNO_EXCEPTIONS_FLAG -fno-exceptions)
|
|
|
|
endif()
|
|
|
|
# RTTI
|
|
|
|
if (NOT LIBCXX_ENABLE_RTTI)
|
|
|
|
list(APPEND LIBCXX_CXX_FEATURE_FLAGS -D_LIBCPP_NO_RTTI)
|
|
|
|
append_if(LIBCXX_CXX_FEATURE_FLAGS LIBCXX_HAS_NO_GR_FLAG -GR-)
|
|
|
|
append_if(LIBCXX_CXX_FEATURE_FLAGS LIBCXX_HAS_FNO_RTTI_FLAG -fno-rtti)
|
|
|
|
endif()
|
|
|
|
# Assert
|
2012-08-06 01:37:39 +08:00
|
|
|
string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE)
|
|
|
|
if (LIBCXX_ENABLE_ASSERTIONS)
|
2010-12-11 03:47:54 +08:00
|
|
|
# MSVC doesn't like _DEBUG on release builds. See PR 4379.
|
|
|
|
if (NOT MSVC)
|
|
|
|
list(APPEND LIBCXX_CXX_FEATURE_FLAGS -D_DEBUG)
|
|
|
|
endif()
|
|
|
|
# On Release builds cmake automatically defines NDEBUG, so we
|
|
|
|
# explicitly undefine it:
|
|
|
|
if (uppercase_CMAKE_BUILD_TYPE STREQUAL "RELEASE")
|
|
|
|
list(APPEND LIBCXX_CXX_FEATURE_FLAGS -UNDEBUG)
|
|
|
|
endif()
|
|
|
|
else()
|
|
|
|
if (NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "RELEASE")
|
|
|
|
list(APPEND LIBCXX_CXX_FEATURE_FLAGS -DNDEBUG)
|
|
|
|
endif()
|
|
|
|
endif()
|
2013-02-25 23:50:36 +08:00
|
|
|
# Static library
|
|
|
|
if (NOT LIBCXX_ENABLE_SHARED)
|
|
|
|
list(APPEND LIBCXX_CXX_FEATURE_FLAGS -D_LIBCPP_BUILD_STATIC)
|
|
|
|
endif()
|
2010-12-11 03:47:54 +08:00
|
|
|
|
|
|
|
# This is the _ONLY_ place where add_definitions is called.
|
2013-10-21 23:56:35 +08:00
|
|
|
if (MSVC)
|
|
|
|
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
|
|
|
|
endif()
|
|
|
|
|
2010-12-11 03:47:54 +08:00
|
|
|
add_definitions(
|
|
|
|
${LIBCXX_CXX_REQUIRED_FLAGS}
|
|
|
|
${LIBCXX_CXX_WARNING_FLAGS}
|
|
|
|
${LIBCXX_CXX_FEATURE_FLAGS}
|
|
|
|
)
|
|
|
|
|
|
|
|
#===============================================================================
|
|
|
|
# Setup Source Code
|
|
|
|
#===============================================================================
|
|
|
|
|
|
|
|
include_directories(include)
|
2013-11-16 01:18:57 +08:00
|
|
|
add_subdirectory(include)
|
2010-12-11 03:47:54 +08:00
|
|
|
|
|
|
|
# Add source code. This also contains all of the logic for deciding linker flags
|
|
|
|
# soname, etc...
|
|
|
|
add_subdirectory(lib)
|
|
|
|
|
|
|
|
#===============================================================================
|
|
|
|
# Setup Tests
|
|
|
|
#===============================================================================
|
|
|
|
|
|
|
|
add_subdirectory(test)
|