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

feat: add basic windows support for poac #1045

Open
wants to merge 4 commits 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
14 changes: 14 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Set the default behavior for all files.
* text=auto eol=lf

# Normalized and converts to native line endings on checkout.
*.c text
*.cc text
*.cxx text
*.cpp text
*.mpp text
*.cppm text
*.ixx text
*.h text
*.hxx text
*.hpp text
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,12 @@ poac-out/

# Doxygen
html

# CMake & XMake
.xmake
build
out

# Visual Studio
*.sdf
*.vs
122 changes: 122 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
cmake_minimum_required(VERSION 3.15)

if (UNIX)
find_program(CLANGPP clang++)
if (CLANGPP)
set(CMAKE_CXX_COMPILER ${CLANGPP})
endif()
endif()


file(READ "${CMAKE_CURRENT_SOURCE_DIR}/poac.toml" POAC_TOML_CONTENT)

string(REGEX MATCH "([0-9]+\\.[0-9]+\\.[0-9]+)" version_match "${POAC_TOML_CONTENT}")

if(NOT version_match)
message(FATAL_ERROR "Failed to extract version from poac.toml")
endif()

project(poac VERSION ${version_match} LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

if(CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU")
add_compile_options(-fdiagnostics-color -pedantic-errors -Wall -Wextra -Wpedantic)
elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
# add_compile_options(/W4 /permissive-)
endif()

if("${CMAKE_GENERATOR}" STREQUAL "Ninja")
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
add_custom_target(copy_compile_commands ALL
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${CMAKE_BINARY_DIR}/compile_commands.json
${CMAKE_SOURCE_DIR}/.vscode/compile_commands.json
DEPENDS ${CMAKE_BINARY_DIR}/compile_commands.json
)
endif()

find_package(Git REQUIRED)

if(GIT_FOUND)
execute_process(
COMMAND ${GIT_EXECUTABLE} rev-parse HEAD
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE GIT_COMMIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE GIT_COMMIT_SHORT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND ${GIT_EXECUTABLE} log -1 --format=%cd --date=short
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE GIT_COMMIT_DATE
OUTPUT_STRIP_TRAILING_WHITESPACE
)
else()
set(GIT_COMMIT_HASH "unknown")
set(GIT_COMMIT_SHORT_HASH "unknown")
set(GIT_COMMIT_DATE "unknown")
endif()

file(GLOB_RECURSE SOURCES "src/*.cc")
list(REMOVE_ITEM SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/main.cc")

add_library(poac_lib ${SOURCES})

target_compile_definitions(poac_lib PRIVATE
POAC_POAC_PKG_VERSION="${PROJECT_VERSION}"
POAC_POAC_COMMIT_HASH="${GIT_COMMIT_HASH}"
POAC_POAC_COMMIT_SHORT_HASH="${GIT_COMMIT_SHORT_HASH}"
POAC_POAC_COMMIT_DATE="${GIT_COMMIT_DATE}"
NOMINMAX
)

# dependencies
find_package(fmt REQUIRED)
find_package(nlohmann_json REQUIRED)
find_package(TBB REQUIRED)
find_package(toml11 REQUIRED)
find_package(CURL REQUIRED)
find_package(unofficial-libgit2 CONFIG REQUIRED)

target_link_libraries(poac_lib PUBLIC
fmt::fmt
nlohmann_json::nlohmann_json
TBB::tbb
toml11::toml11
CURL::libcurl
unofficial::libgit2::libgit2
)

add_executable(poac "src/main.cc")
target_link_libraries(poac PRIVATE poac_lib)

enable_testing()

set(UNITTEST_SRCS
src/BuildConfig.cc
src/Algos.cc
src/Semver.cc
src/VersionReq.cc
src/Manifest.cc
)

foreach(TEST_SRC ${UNITTEST_SRCS})
get_filename_component(TEST_NAME ${TEST_SRC} NAME_WE)
set(TEST_EXEC "test_${TEST_NAME}")
add_executable(${TEST_EXEC} ${TEST_SRC})
target_compile_definitions(${TEST_EXEC} PRIVATE
POAC_TEST
NOMINMAX
)
target_link_libraries(${TEST_EXEC} PRIVATE
poac_lib
)
add_test(NAME ${TEST_EXEC} COMMAND ${TEST_EXEC})
endforeach()
51 changes: 51 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"version": 8,
"configurePresets": [
{
"name": "VS-x64-msvc",
"displayName": "Visual Studio Community 2022 Release - amd64",
"generator": "Visual Studio 17 2022",
"binaryDir": "${sourceDir}/out/build/${presetName}",
"cacheVariables": {
"CMAKE_INSTALL_PREFIX": "${sourceDir}/out/install/${presetName}",
"CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
}
},
{
"name": "Ninja",
"description": "Ninja build system",
"generator": "Ninja",
"inherits": "VS-x64-msvc"
}
],
"buildPresets": [
{
"name": "VS-x64-msvc-debug",
"configurePreset": "VS-x64-msvc",
"configuration": "Debug"
},
{
"name": "VS-x64-msvc-release",
"configurePreset": "VS-x64-msvc",
"configuration": "Release"
},
{
"name": "Ninja-debug",
"configurePreset": "Ninja",
"configuration": "Debug"
},
{
"name": "Ninja-release",
"configurePreset": "Ninja",
"configuration": "Release"
}
],
"testPresets": [
{
"name": "poac-Unitests",
"description": "",
"displayName": "",
"configurePreset": "Ninja"
}
]
}
6 changes: 3 additions & 3 deletions src/Algos.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ getCmdOutput(const Command& cmd, const size_t retry) {
int exitCode = EXIT_SUCCESS;
int waitTime = 1;
for (size_t i = 0; i < retry; ++i) {
const auto [curExitCode, stdout, stderr] = cmd.output();
static_cast<void>(stderr);
const auto [curExitCode, out, err] = cmd.output();
static_cast<void>(err);
if (curExitCode == EXIT_SUCCESS) {
return stdout;
return out;
}
exitCode = curExitCode;

Expand Down
Loading