Skip to content

Commit

Permalink
clang libcxx build on linux
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan Le Lann committed Jun 28, 2016
1 parent 1c51ce3 commit e8c004b
Show file tree
Hide file tree
Showing 7 changed files with 158 additions and 232 deletions.
149 changes: 87 additions & 62 deletions CMakeLists.txt
Expand Up @@ -13,6 +13,12 @@ set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY "libc++")
add_definitions ("-Wall")
add_definitions ("-Werror")

if (${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang" AND
${CMAKE_SYSTEM_NAME} MATCHES "Linux")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
set(CMAKE_EXE_LINKER_FLAGS "-lc++abi")
endif()

# There are two big choices this file makes - how to include Boost, and how to
# include double-conversion, respectively. Build environments vary and we're
# trying to support all of them.
Expand All @@ -23,121 +29,140 @@ add_definitions ("-Werror")
# For double-conversion, the unix makefile setup is able to download the git
# repo and build it

option(USE_SYSTEM_BOOST "use cmake found boost instead of ../boost_libraries" "ON")
option(USE_STLAB_DOUBLECONV "use stlab mirror of double-conversion repository" "OFF")
option(USE_SYSTEM_BOOST "use cmake found boost instead of ../boost_libraries" OFF)
option(USE_STLAB_DOUBLECONV "use stlab mirror of double-conversion repository" OFF)

# with boost 1.60 boost.thread uses boost.move unique_ptr
# which is broken with BOOST_MOVE_USE_STANDARD_LIBRARY_MOVE flag...
# fix is to conditionally remove this last boost thread dependency
# NB: AppleClang lacks thread_local
option(USE_STD_THREAD_LOCAL "use C++11 thread_local instead of Boost" OFF)
if (USE_STD_THREAD_LOCAL AND ${CMAKE_CXX_COMPILER_ID} STREQUAL "AppleClang")
message (WARNING "C++11 thread_local is not supported by AppleClang")
endif()


set(root_path ${CMAKE_SOURCE_DIR}/../)
set(root_path ${CMAKE_SOURCE_DIR}/..)

function(setup_dep)
set(oneValueArgs URL BRANCH)
set(options IS_CMAKE)
set(oneValueArgs URL BRANCH TAG NAME)
cmake_parse_arguments(setup_dep "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
get_filename_component(name ${setup_dep_URL} NAME_WE)

if ("${setup_dep_NAME}" STREQUAL "")
get_filename_component(name ${setup_dep_URL} NAME_WE)
else()
set(name ${setup_dep_NAME})
endif()

set(dep_path ${root_path}/${name})

if(NOT IS_DIRECTORY ${dep_path})
execute_process(COMMAND ${GIT_EXECUTABLE} clone ${setup_dep_URL} WORKING_DIRECTORY ${root_path})
message("ASL_INFO: Setting up dep " ${name} " into " ${dep_path})
execute_process(COMMAND ${GIT_EXECUTABLE} clone --recursive ${setup_dep_URL} ${name} WORKING_DIRECTORY ${root_path})

if("${setup_dep_BRANCH}" STREQUAL "")
message(FATAL_ERROR "ASL_INFO: No branch given for dep " ${name})
endif()

execute_process(COMMAND ${GIT_EXECUTABLE} checkout ${setup_dep_BRANCH} WORKING_DIRECTORY ${dep_path})
else()
message("ASL_INFO: Found dep " ${name} " into " ${dep_path})
endif()

if (setup_dep_IS_CMAKE)
add_subdirectory(${dep_path} ${CMAKE_BINARY_DIR}/imported/${name})
endif()
add_subdirectory(${dep_path} ${CMAKE_BINARY_DIR}/imported/${name})

endfunction()

if (${USE_STLAB_DOUBLECONV})
setup_dep(URL https://github.com/stlab/double-conversion.git BRANCH master)
if (USE_STLAB_DOUBLECONV)
setup_dep(URL https://github.com/stlab/double-conversion.git BRANCH master IS_CMAKE)
target_include_directories(double-conversion PUBLIC $<BUILD_INTERFACE:${root_path}>)
else()
setup_dep(URL https://github.com/google/double-conversion.git BRANCH master)
setup_dep(URL https://github.com/google/double-conversion.git BRANCH master IS_CMAKE)
target_include_directories(double-conversion PUBLIC $<BUILD_INTERFACE:${root_path}/double-conversion>)
# poorly named flag to fix include path
target_compile_definitions(double-conversion PUBLIC ADOBE_BUILT_WITH_CMAKE)
endif()

function(target_link_boost target)
if (${USE_SYSTEM_BOOST})
target_link_libraries(${target} PUBLIC ${Boost_SYSTEM_LIBRARY} ${Boost_FILESYSTEM_LIBRARY} ${Boost_THREAD_LIBRARY})
if (USE_SYSTEM_BOOST)
target_link_libraries(${target} PUBLIC ${Boost_SYSTEM_LIBRARY} ${Boost_FILESYSTEM_LIBRARY})
if(NOT USE_STD_THREAD_LOCAL)
target_link_libraries(${target} PUBLIC ${Boost_THREAD_LIBRARY})
endif()
else()
add_dependencies(${target} boost_glob)

target_link_libraries(${target} PUBLIC boost_glob)
endif()
endfunction(target_link_boost)

function(target_link_boost_test target)
if (${USE_SYSTEM_BOOST})
if (USE_SYSTEM_BOOST)
target_compile_definitions(${target} PRIVATE BOOST_TEST_DYN_LINK)
target_link_libraries(${target} PRIVATE ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})
else()
add_dependencies(${target} boost_unit_test)

target_link_libraries(${target} PUBLIC boost_unit_test)
endif()
endfunction(target_link_boost_test)

if (${USE_SYSTEM_BOOST})
find_package(Boost COMPONENTS system filesystem thread unit_test_framework program_options REQUIRED)
if (USE_SYSTEM_BOOST)
message("ASL_INFO: Using system boost.")
set(ASL_BOOST_COMPONENTS system filesystem unit_test_framework program_options)
if(NOT USE_STD_THREAD_LOCAL)
list(APPEND ASL_BOOST_COMPONENTS thread)
endif()
find_package(Boost COMPONENTS ${ASL_BOOST_COMPONENTS} REQUIRED)
else()
message("ASL_INFO: Building boost ourselves.")

setup_dep(NAME boost_libraries URL https://github.com/boostorg/boost.git BRANCH boost-1.60.0)

# There really isn't a need to separate out these sources, so we build them
# in one large static library.

file(GLOB ASL_BOOST_FILESYSTEM_SRC ../boost_libraries/libs/filesystem/src/*.cpp)
file(GLOB ASL_BOOST_PROGRAM_OPTIONS_SRC ../boost_libraries/libs/program_options/src/*.cpp)
file(GLOB ASL_BOOST_SYSTEM_SRC ../boost_libraries/libs/system/src/*.cpp)
file(GLOB ASL_BOOST_THREAD_SRC ../boost_libraries/libs/thread/src/*.cpp)

if (${UNIX})
file(GLOB ASL_BOOST_THREAD_TSS ../boost_libraries/libs/thread/src/pthread/*.cpp)
elseif (${WIN32})
set(ASL_BOOST_THREAD_TSS
../boost_libraries/libs/thread/src/win32/thread.cpp
../boost_libraries/libs/thread/src/win32/tss_pe.cpp # no idea if this is right...
)

set(BOOST_GLOB_SOURCES
${ASL_BOOST_FILESYSTEM_SRC}
${ASL_BOOST_PROGRAM_OPTIONS_SRC}
${ASL_BOOST_SYSTEM_SRC})

if(NOT USE_STD_THREAD_LOCAL)
file(GLOB ASL_BOOST_THREAD_SRC ../boost_libraries/libs/thread/src/*.cpp)

if (${UNIX})
file(GLOB ASL_BOOST_THREAD_TSS ../boost_libraries/libs/thread/src/pthread/*.cpp)
elseif (${WIN32})
set(ASL_BOOST_THREAD_TSS
../boost_libraries/libs/thread/src/win32/thread.cpp
../boost_libraries/libs/thread/src/win32/tss_pe.cpp # no idea if this is right...
)
endif()
list(APPEND BOOST_GLOB_SOURCES
${ASL_BOOST_THREAD_SRC}
${ASL_BOOST_THREAD_TSS})
endif()

add_library(
boost_glob STATIC
${ASL_BOOST_FILESYSTEM_SRC}
${ASL_BOOST_PROGRAM_OPTIONS_SRC}
${ASL_BOOST_SYSTEM_SRC}
${ASL_BOOST_THREAD_SRC}
${ASL_BOOST_THREAD_TSS}
)
add_library(boost_glob STATIC ${BOOST_GLOB_SOURCES})

target_include_directories(boost_glob PUBLIC ../boost_libraries)

# We separate out the unit test framework from the rest of the boost
# add_library support because it has its own main routine which we only need
# when building unit tests.

# I can't find a way to glob these because one infernal file, cpp_main.cpp,
# mucks with my ability to use it.

add_library(
boost_unit_test STATIC
../boost_libraries/libs/test/src/compiler_log_formatter.cpp
../boost_libraries/libs/test/src/debug.cpp
../boost_libraries/libs/test/src/exception_safety.cpp
../boost_libraries/libs/test/src/execution_monitor.cpp
../boost_libraries/libs/test/src/framework.cpp
../boost_libraries/libs/test/src/interaction_based.cpp
../boost_libraries/libs/test/src/logged_expectations.cpp
../boost_libraries/libs/test/src/plain_report_formatter.cpp
../boost_libraries/libs/test/src/progress_monitor.cpp
../boost_libraries/libs/test/src/results_collector.cpp
../boost_libraries/libs/test/src/results_reporter.cpp
../boost_libraries/libs/test/src/test_main.cpp
../boost_libraries/libs/test/src/test_tools.cpp
../boost_libraries/libs/test/src/unit_test_log.cpp
../boost_libraries/libs/test/src/unit_test_main.cpp
../boost_libraries/libs/test/src/unit_test_monitor.cpp
../boost_libraries/libs/test/src/unit_test_parameters.cpp
../boost_libraries/libs/test/src/unit_test_suite.cpp
../boost_libraries/libs/test/src/xml_log_formatter.cpp
../boost_libraries/libs/test/src/xml_report_formatter.cpp
)
file(GLOB ASL_BOOST_TEST_SRC RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ../boost_libraries/libs/test/src/*.cpp)
list(REMOVE_ITEM ASL_BOOST_TEST_SRC ../boost_libraries/libs/test/src/cpp_main.cpp)

add_library(boost_unit_test STATIC ${ASL_BOOST_TEST_SRC})

target_include_directories(boost_unit_test PRIVATE -DBOOST_TEST_MAIN)
target_include_directories(boost_unit_test PUBLIC ../boost_libraries)
endif()

add_subdirectory(source)
add_subdirectory(test)

141 changes: 2 additions & 139 deletions adobe/cmath.hpp
Expand Up @@ -5,170 +5,33 @@
*/
/*************************************************************************************************/

/*
REVISIT (sparent) : Need to replicate the boost configuration tests to figure out when to fall
back to include math.h. This also needs to add any other C99 math.h extensions.
*/

#ifndef ADOBE_CMATH_HPP
#define ADOBE_CMATH_HPP

#include <adobe/config.hpp>

#include <cmath>
#include <functional>

/*************************************************************************************************/

#if defined(__MWERKS__)
/*
Any (previously) supported version of metrowerks had the C99/TR1 cmath extensions in the
standard namespace in <cmath>.
*/
#define ADOBE_HAS_C99_STD_MATH_H
#include <cmath>
#elif defined(__GNUC__)

// Guessing at gcc 3 support
#if (__GNUC__ == 3) && (__GNUC_MINOR__ > 2)

#define ADOBE_HAS_CPP_CMATH

#elif __GNUC__ == 4
#if (__GNUC_MINOR__ < 6) || (!(defined(_GLIBCXX_USE_C99_MATH_TR1)))
// at least Ubuntu 9.x, gcc 4.4.1, still falls into this case
/*
The currently supported version of GNUC has C99 extensions in math.h. But no TR1 extensions.
*/
#define ADOBE_HAS_C99_MATH_H
#include <cmath>
#else
#include <tr1/cmath>

#define ADOBE_HAS_C99_STD_MATH_H
#endif
#elif __GNUC__ >= 5
#define ADOBE_HAS_C99_STD_MATH_H
#include <cmath>
#endif

#elif defined(_MSC_VER)
#include <cmath>
/*
The currently supported version of VC++ has no C99 extensions.
*/

#if _MSC_VER > 1600
#error "Unknown MSC compiler configureation for cmath (last knownversion is VC++ 10.0)."
#endif

#define ADOBE_HAS_CPP_CMATH

#else
#error "Unknown compiler configuration for cmath."
#endif
namespace adobe {

/*************************************************************************************************/

#if defined(ADOBE_HAS_C99_STD_MATH_H)

namespace adobe {

using std::float_t;
using std::double_t;

using std::round;
using std::lround;
using std::trunc;

} // namespace adobe

/*************************************************************************************************/

#elif defined(ADOBE_HAS_CPP_CMATH)

namespace adobe {

typedef float float_t;
typedef double double_t;

/*************************************************************************************************/

inline float trunc(float x) { return x < 0.0f ? std::ceil(x) : std::floor(x); }

inline double trunc(double x) { return x < 0.0 ? std::ceil(x) : std::floor(x); }

/*************************************************************************************************/

inline float round(float x) { return trunc(x + (x < 0.0f ? -0.5f : 0.5f)); }

inline double round(double x) { return trunc(x + (x < 0.0 ? -0.5 : 0.5)); }

/*************************************************************************************************/

inline long lround(float x) { return static_cast<long>(x + (x < 0.0f ? -0.5f : 0.5f)); }

inline long lround(double x) { return static_cast<long>(x + (x < 0.0 ? -0.5 : 0.5)); }

/*************************************************************************************************/

} // namespace adobe

/*************************************************************************************************/

#elif defined(ADOBE_HAS_C99_MATH_H)

#include <math.h>

namespace adobe {

using ::float_t;
using ::double_t;

/*************************************************************************************************/

using ::round;
using ::lround;
using ::trunc;

inline float round(float x) { return ::roundf(x); }
inline long lround(float x) { return ::lroundf(x); }
inline float trunc(float x) { return ::truncf(x); }

/*************************************************************************************************/

} // namespace adobe

#elif defined(ADOBE_NO_DOCUMENTATION)

namespace adobe {

/*!
\name Compatibility
Compatibility features for C99/TR1 <code>\<cmath\></code>.
@{
*/

/*!
\ingroup cmath
*/

typedef Float double_t;
typedef Float float_t;

double round(double x);
float round(float x);
long lround(double x);
long lround(float x);
double trunc(double x);
float trunc(float x);
/*! @} */

} // namespace adobe

#endif

/*************************************************************************************************/

namespace adobe {
Expand Down

0 comments on commit e8c004b

Please sign in to comment.