Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate CMake deps to FetchContent and more std:: usage #84

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ xcuserdata
gh-pages/

documentation/doxyfile.bak
build_asl/

# CLion
cmake-build-*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IDE and editor-specific files should be added to global .gitignore files instead of project ones. See this stack overflow article.

152 changes: 31 additions & 121 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
cmake_minimum_required(VERSION 3.0)
include(FindGit)
include(CMakeParseArguments)
cmake_minimum_required(VERSION 3.17)
include(FetchContent)
enable_testing()

project(adobe_source_libraries CXX)
Expand All @@ -10,89 +9,22 @@ set(CMAKE_CXX_STANDARD 14)
set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LANGUAGE_STANDARD "c++14")
set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY "libc++")

add_definitions ("-Wall")
#add_definitions ("-Werror")

# 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.
#
# If USE_SYSTEM_BOOST is defined, that means the headers and libraries have been built
# and are ready for use by CMake. Otherwise, we'll have to roll them ourselves.
#
# 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" 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: Seems fixed for boost 1.65.1
# 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}/..)

function(setup_dep)
set(options IS_CMAKE)
set(oneValueArgs URL BRANCH TAG NAME)
set(multiValueArgs SUBMODULES)
cmake_parse_arguments(setup_dep "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})

if ("${setup_dep_NAME}" STREQUAL "")
get_filename_component(name ${setup_dep_URL} NAME_WE)
else()
set(name ${setup_dep_NAME})
endif()
# by default we will fetch boost from github (see fetchcontent_declare call for boost below)
# If you want to use a custom boost (e.g. ../boost_libraries), define FETCHCONTENT_SOURCE_DIR_BOOST
# you can also "fetchcontent_declare" your own boost before including adobe_source_libraries in your super CMakeList.txt
option(USE_SYSTEM_BOOST OFF)

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

if(NOT IS_DIRECTORY ${dep_path})
message("ASL_INFO: Setting up dep " ${name} " into " ${dep_path})
execute_process(COMMAND ${GIT_EXECUTABLE} clone ${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})

foreach(submodule ${setup_dep_SUBMODULES})
message("ASL_INFO: Setting up submodule " ${submodule} " for " ${name})
execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init ${submodule} WORKING_DIRECTORY ${dep_path})
endforeach(submodule)
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()

endfunction()

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 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()
# cf boost comment above on how to use a custom double-conversion
fetchcontent_declare(double-conversion GIT_REPOSITORY https://github.com/google/double-conversion.git GIT_TAG master GIT_SHALLOW)
fetchcontent_makeavailable(double-conversion)

function(target_link_boost target)
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()
target_link_libraries(${target} PUBLIC Boost::system Boost::filesystem)
else()
target_link_libraries(${target} PUBLIC boost_glob)
endif()
Expand All @@ -101,7 +33,7 @@ endfunction(target_link_boost)
function(target_link_boost_test target)
if (USE_SYSTEM_BOOST)
target_compile_definitions(${target} PRIVATE BOOST_TEST_DYN_LINK)
target_link_libraries(${target} PRIVATE ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})
target_link_libraries(${target} PRIVATE Boost::unit_test_framework)
else()
target_link_libraries(${target} PUBLIC boost_unit_test)
endif()
Expand All @@ -110,9 +42,6 @@ endfunction(target_link_boost_test)
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.")
Expand All @@ -121,11 +50,12 @@ else()
# required by asl
libs/system
libs/filesystem
libs/thread
libs/program_options
libs/signals2
libs/variant
libs/gil
# required by libs/filesystem
libs/container_hash
# required by adobe::fnv unless ADOBE_FNV_NO_BIGINTS is defined
libs/multiprecision
# required by boost test or by the one above
Expand Down Expand Up @@ -167,73 +97,53 @@ else()
libs/array
libs/container
libs/math
# required by thread
libs/atomic
libs/date_time
libs/chrono
libs/tuple
libs/align
# required by chrono
libs/ratio
# required by multiprecision
libs/format
libs/rational
# required by signals2
libs/multi_index
)

setup_dep(NAME boost_libraries URL https://github.com/boostorg/boost.git BRANCH boost-1.76.0 SUBMODULES ${BOOST_SUBMODULES})
fetchcontent_declare(boost
GIT_REPOSITORY https://github.com/boostorg/boost.git
GIT_TAG boost-1.76.0
GIT_SUBMODULES ${BOOST_SUBMODULES}
GIT_SHALLOW
SOURCE_SUBDIR "some value that will prevent cmake from finding root boost CMakeLists.txt (and I don't know why CONFIGURE_COMMAND \"\" does not work)")
fetchcontent_makeavailable(boost)
fetchcontent_getproperties(boost SOURCE_DIR boost_root)

# 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_FILESYSTEM_SRC ${boost_root}/libs/filesystem/src/*.cpp)
file(GLOB ASL_BOOST_PROGRAM_OPTIONS_SRC ${boost_root}/libs/program_options/src/*.cpp)
file(GLOB ASL_BOOST_SYSTEM_SRC ${boost_root}/libs/system/src/*.cpp)

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

if(NOT USE_STD_THREAD_LOCAL)
message("ASL_INFO: adding boost thread to local boost build")
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 ${BOOST_GLOB_SOURCES})

target_include_directories(boost_glob PUBLIC ../boost_libraries)

foreach (submodule ${BOOST_SUBMODULES})
target_include_directories(boost_glob PUBLIC ../boost_libraries/${submodule}/include)
target_include_directories(boost_glob PUBLIC ${boost_root}/${submodule}/include)
endforeach(submodule)

# 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.

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)
file(GLOB ASL_BOOST_TEST_SRC RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${boost_root}/libs/test/src/*.cpp)
set(asl_boost_unit_test_cpp_main_cpp_path ${boost_root}/libs/test/src/cpp_main.cpp)
cmake_path(RELATIVE_PATH asl_boost_unit_test_cpp_main_cpp_path)
list(REMOVE_ITEM ASL_BOOST_TEST_SRC ${asl_boost_unit_test_cpp_main_cpp_path})

add_library(boost_unit_test STATIC ${ASL_BOOST_TEST_SRC})

target_include_directories(boost_unit_test PUBLIC ../boost_libraries)

target_include_directories(boost_unit_test PUBLIC ${boost_root}/libs/test/include)
foreach (submodule ${BOOST_SUBMODULES})
target_include_directories(boost_unit_test PUBLIC ../boost_libraries/${submodule}/include)
target_include_directories(boost_unit_test PUBLIC ${boost_root}/${submodule}/include)
endforeach(submodule)
endif()

Expand Down
12 changes: 12 additions & 0 deletions adobe/forest.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,12 @@ class forest_iterator

forest_iterator(const forest_iterator& x) : node_m(x.node_m), edge_m(x.edge_m) {}

forest_iterator& operator=(const forest_iterator& x) {
node_m = x.node_m;
edge_m = x.edge_m;
return *this;
}

std::size_t edge() const { return edge_m; }
std::size_t& edge() { return edge_m; }
bool equal_node(forest_iterator const& y) const { return node_m == y.node_m; }
Expand Down Expand Up @@ -477,6 +483,12 @@ class forest_const_iterator : public boost::iterator_facade<forest_const_iterato

forest_const_iterator(const forest_const_iterator& x) : node_m(x.node_m), edge_m(x.edge_m) {}

forest_const_iterator& operator=(const forest_const_iterator& x) {
node_m = x.node_m;
edge_m = x.edge_m;
return *this;
}

forest_const_iterator(const forest_iterator<T>& x) : node_m(x.node_m), edge_m(x.edge_m) {}

std::size_t edge() const { return edge_m; }
Expand Down
8 changes: 4 additions & 4 deletions adobe/functional.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@

#include <functional>
#include <utility>
#include <tuple>

#include <boost/compressed_pair.hpp>
#include <boost/tuple/tuple.hpp>

#include <adobe/functional/is_member.hpp>
#include <adobe/functional/operator.hpp>
Expand Down Expand Up @@ -221,7 +221,7 @@ struct binary_compose {

template <int N, typename T> // T is boost::tuple<>
struct element {
typedef typename boost::tuples::element<N, T>::type type;
typedef typename std::tuple_element_t<N, T> type;
};

template <typename T1, typename T2>
Expand All @@ -238,9 +238,9 @@ struct element<1, std::pair<T1, T2>> {

template <int N, typename T> // T is pair or tuple
struct get_element {
typename element<N, T>::type& operator()(T& x) const { return boost::get<N>(x); }
typename element<N, T>::type& operator()(T& x) const { return std::get<N>(x); }

const typename element<N, T>::type& operator()(const T& x) const { return boost::get<N>(x); }
const typename element<N, T>::type& operator()(const T& x) const { return std::get<N>(x); }
};

/**************************************************************************************************/
Expand Down
27 changes: 5 additions & 22 deletions adobe/implementation/zuid_sys_dep.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,39 +41,22 @@

#include <adobe/md5.hpp>

#include <boost/cstdint.hpp>

#include <ctime>

/*
set the following to the number of 100ns ticks of
the actual resolution of your system's clock
*/
#define UUIDS_PER_TICK 10

/*
Set the following to a call to acquire a system wide global lock
*/
#define STD_LOCK
#define STD_UNLOCK

#ifdef BOOST_NO_INT64_T
#error "Your platform has no 64-bit integral type."
#endif
#include <array>
#include <chrono>

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

namespace adobe {

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

typedef boost::uint64_t uuid_time_t;
typedef boost::array<char, 6> uuid_node_t;
typedef std::chrono::system_clock::duration::rep uuid_time_t;
typedef std::array<char, 6> uuid_node_t;

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

void get_ieee_node_identifier(uuid_node_t* node);
void get_system_time(uuid_time_t* uuid_time);
std::chrono::system_clock::time_point get_system_time();

boost::uint64_t true_random();

Expand Down
4 changes: 0 additions & 4 deletions adobe/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@
#include <unordered_map>
#include <vector>

#ifdef ADOBE_BUILT_WITH_CMAKE
#include <double-conversion/double-conversion.h>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure how non-CMake build setups will react to that :)

#else
#include <double-conversion/src/double-conversion.h>
#endif

#include <adobe/cassert.hpp>
#include <adobe/string/to_string.hpp>
Expand Down
4 changes: 2 additions & 2 deletions adobe/md5.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@

#include <adobe/config.hpp>

#include <boost/array.hpp>
#include <boost/cstdint.hpp>

#include <array>
#include <cstddef>

/**************************************************************************************************/
Expand Down Expand Up @@ -94,7 +94,7 @@ Finalizes the input hash and clears the MD5 hash state information

class md5_t {
public:
typedef boost::array<boost::uint8_t, 16> digest_t;
typedef std::array<boost::uint8_t, 16> digest_t;

md5_t();

Expand Down
Loading