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

[vcpkg-ci-fortran] New test port #42754

Draft
wants to merge 10 commits into
base: master
Choose a base branch
from
Draft
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
40 changes: 40 additions & 0 deletions scripts/test_ports/vcpkg-ci-fortran/portfile.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
set(VCPKG_POLICY_EMPTY_PACKAGE enabled)

# Capture pristine toolchain configuration
vcpkg_cmake_get_vars(cmake_vars_file)
include("${cmake_vars_file}")

# Capture (g)fortran configuration
include(vcpkg_find_fortran)
# Side effects!
block(SCOPE_FOR VARIABLES
PROPAGATE
FORTRAN_CMAKE
VCPKG_CRT_LINKAGE
VCPKG_LIBRARY_LINKAGE
VCPKG_POLICY_SKIP_DUMPBIN_CHECKS
VCPKG_USE_INTERNAL_Fortran
# DO NOT PROPAGATE:
# VCPKG_CHAINLOAD_TOOLCHAIN_FILE
)
set(env_path_backup "$ENV{PATH}")
vcpkg_find_fortran(FORTRAN_CMAKE)
set(ENV{PATH} "${env_path_backup}")
endblock()

# Transform
if(VCPKG_USE_INTERNAL_Fortran)
list(FILTER FORTRAN_CMAKE EXCLUDE REGEX "-DCMAKE_C_COMPILER=")
string(REPLACE "-DCMAKE_Fortran_COMPILER" "-DMINGW_GFORTRAN" FORTRAN_CMAKE "${FORTRAN_CMAKE}")
endif()

vcpkg_cmake_configure(
SOURCE_PATH "${CURRENT_PORT_DIR}/project"
DISABLE_PARALLEL_CONFIGURE # for split stdout/stderr logs
OPTIONS
${FORTRAN_CMAKE}
"-DEXPECTED_C_COMPILER=${VCPKG_DETECTED_CMAKE_C_COMPILER}"
"-DEXPECTED_CXX_COMPILER=${VCPKG_DETECTED_CMAKE_CXX_COMPILER}"
--trace-expand
)
vcpkg_cmake_build()
22 changes: 22 additions & 0 deletions scripts/test_ports/vcpkg-ci-fortran/project/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
cmake_minimum_required(VERSION 3.16)
# Do not unconditionally enable Fortran here.
project(vcpkg-ci-fortran C CXX)

if(NOT EXPECTED_C_COMPILER STREQUAL CMAKE_C_COMPILER)
message(SEND_ERROR "Unexpect C compiler\n actual: ${CMAKE_C_COMPILER}\n expected: ${EXPECTED_C_COMPILER}")
endif()
if(NOT EXPECTED_CXX_COMPILER STREQUAL CMAKE_CXX_COMPILER)
message(SEND_ERROR "Unexpect CXX compiler\n actual: ${CMAKE_CXX_COMPILER}\n expected: ${EXPECTED_CXX_COMPILER}")
endif()

# Enable build with gfortran for MSVC.
include(CMakeAddFortranSubdirectory)
cmake_add_fortran_subdirectory(f NO_EXTERNAL_INSTALL)

# Enable link with gfortran for NOT MSVC.
if(NOT MINGW_GFORTRAN)
enable_language(Fortran)
endif()

add_executable(main main.cxx)
target_link_libraries(main flib)
6 changes: 6 additions & 0 deletions scripts/test_ports/vcpkg-ci-fortran/project/f/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Unconditionally enable Fortran here.
project(pure-fortran Fortran)

add_executable(fmain main.f90)

add_library(flib flib.f90)
4 changes: 4 additions & 0 deletions scripts/test_ports/vcpkg-ci-fortran/project/f/flib.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SUBROUTINE flib( N )
WRITE( *, * ) 'Hello ', N
RETURN
END
3 changes: 3 additions & 0 deletions scripts/test_ports/vcpkg-ci-fortran/project/f/main.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
program main
print *, 'Hello vcpkg!'
end program main
10 changes: 10 additions & 0 deletions scripts/test_ports/vcpkg-ci-fortran/project/main.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
extern "C" {
void flib_(int*);
}

int main()
{
int n = 42;
flib_(&n);
return 0;
}
20 changes: 20 additions & 0 deletions scripts/test_ports/vcpkg-ci-fortran/vcpkg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "vcpkg-ci-fortran",
"version-string": "ci",
"description": "Validates fortran scripts.",
"supports": "!android & !uwp & !(windows & arm)",
"dependencies": [
{
"name": "vcpkg-cmake",
"host": true
},
{
"name": "vcpkg-cmake-get-vars",
"host": true
},
{
"name": "vcpkg-gfortran",
"platform": "windows & !arm & !uwp"
}
]
}
Loading