Skip to content

Commit

Permalink
Merge pull request lewissbaker#15 from Garcia6l20/add_cmake_support
Browse files Browse the repository at this point in the history
Add cmake support
  • Loading branch information
andreasbuhr authored Oct 24, 2020
2 parents f6fb710 + e0cd46a commit 07bb85e
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 7 deletions.
9 changes: 5 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
include(CTest)

add_subdirectory(lib)

enable_testing()
if(BUILD_TESTING)
add_subdirectory(test)
endif()
Expand All @@ -20,10 +21,10 @@ configure_file(cmake/cppcoroConfig.cmake
COPYONLY)

set(config_package_location lib/cmake/cppcoro)
install(DIRECTORY include
DESTINATION .
install(DIRECTORY include/cppcoro
DESTINATION include
COMPONENT Devel)
install(FILES cmake/FindCppcoroCoroutines.cmake
install(FILES cmake/FindCoroutines.cmake
DESTINATION ${config_package_location}
COMPONENT Devel)
install(EXPORT cppcoroTargets
Expand Down
4 changes: 4 additions & 0 deletions cmake/FindCoroutines.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,15 @@ cmake_push_check_state()
set(CMAKE_REQUIRED_QUIET ${Coroutines_FIND_QUIETLY})

check_cxx_compiler_flag(/await _CXX_COROUTINES_SUPPORTS_MS_FLAG)
check_cxx_compiler_flag(/await:heapelide _CXX_COROUTINES_SUPPORTS_MS_HEAPELIDE_FLAG)
check_cxx_compiler_flag(-fcoroutines-ts _CXX_COROUTINES_SUPPORTS_TS_FLAG)
check_cxx_compiler_flag(-fcoroutines _CXX_COROUTINES_SUPPORTS_CORO_FLAG)

if(_CXX_COROUTINES_SUPPORTS_MS_FLAG)
set(_CXX_COROUTINES_EXTRA_FLAGS "/await")
if(_CXX_COROUTINES_SUPPORTS_MS_HEAPELIDE_FLAG AND CMAKE_SIZEOF_VOID_P GREATER_EQUAL 8)
list(APPEND _CXX_COROUTINES_EXTRA_FLAGS "/await:heapelide")
endif()
elseif(_CXX_COROUTINES_SUPPORTS_TS_FLAG)
set(_CXX_COROUTINES_EXTRA_FLAGS "-fcoroutines-ts")
elseif(_CXX_COROUTINES_SUPPORTS_CORO_FLAG)
Expand Down
2 changes: 1 addition & 1 deletion cmake/cppcoroConfig.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR})

include(CMakeFindDependencyMacro)
find_dependency(CppcoroCoroutines QUIET REQUIRED)
find_dependency(Coroutines QUIET REQUIRED)

include("${CMAKE_CURRENT_LIST_DIR}/cppcoroTargets.cmake")
12 changes: 11 additions & 1 deletion lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,14 @@ if(WIN32)
socket_recv_from_operation.cpp
)
list(APPEND sources ${win32Sources})

list(APPEND libraries Ws2_32 Mswsock Synchronization)
list(APPEND compile_options /EHsc)

if("${MSVC_VERSION}" VERSION_GREATER_EQUAL 1900)
# TODO remove this when experimental/non-experimental include are fixed
list(APPEND compile_definition _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING=1)
endif()
endif()

add_library(cppcoro
Expand All @@ -158,9 +166,11 @@ target_include_directories(cppcoro PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)
target_compile_features(cppcoro PUBLIC cxx_std_20)
target_compile_definitions(cppcoro PUBLIC ${compile_definition})
target_compile_options(cppcoro PUBLIC ${compile_options})

find_package(Coroutines COMPONENTS Experimental Final REQUIRED)
target_link_libraries(cppcoro PUBLIC std::coroutines)
target_link_libraries(cppcoro PUBLIC std::coroutines ${libraries})

install(TARGETS cppcoro EXPORT cppcoroTargets
LIBRARY DESTINATION lib
Expand Down
2 changes: 1 addition & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ include(${CMAKE_CURRENT_LIST_DIR}/doctest/doctest.cmake)

find_package(Threads REQUIRED)

add_library(tests-main SHARED
add_library(tests-main STATIC
main.cpp
counted.cpp
)
Expand Down

0 comments on commit 07bb85e

Please sign in to comment.