diff --git a/scripts/test_ports/vcpkg-ci-fortran/portfile.cmake b/scripts/test_ports/vcpkg-ci-fortran/portfile.cmake new file mode 100644 index 00000000000000..eabe79188e232a --- /dev/null +++ b/scripts/test_ports/vcpkg-ci-fortran/portfile.cmake @@ -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() diff --git a/scripts/test_ports/vcpkg-ci-fortran/project/CMakeLists.txt b/scripts/test_ports/vcpkg-ci-fortran/project/CMakeLists.txt new file mode 100644 index 00000000000000..cbdd0bede3e7f9 --- /dev/null +++ b/scripts/test_ports/vcpkg-ci-fortran/project/CMakeLists.txt @@ -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) diff --git a/scripts/test_ports/vcpkg-ci-fortran/project/f/CMakeLists.txt b/scripts/test_ports/vcpkg-ci-fortran/project/f/CMakeLists.txt new file mode 100644 index 00000000000000..46e2cd3d6216a5 --- /dev/null +++ b/scripts/test_ports/vcpkg-ci-fortran/project/f/CMakeLists.txt @@ -0,0 +1,6 @@ +# Unconditionally enable Fortran here. +project(pure-fortran Fortran) + +add_executable(fmain main.f90) + +add_library(flib flib.f90) diff --git a/scripts/test_ports/vcpkg-ci-fortran/project/f/flib.f90 b/scripts/test_ports/vcpkg-ci-fortran/project/f/flib.f90 new file mode 100644 index 00000000000000..b5df840be898af --- /dev/null +++ b/scripts/test_ports/vcpkg-ci-fortran/project/f/flib.f90 @@ -0,0 +1,4 @@ +SUBROUTINE flib( N ) + WRITE( *, * ) 'Hello ', N + RETURN + END diff --git a/scripts/test_ports/vcpkg-ci-fortran/project/f/main.f90 b/scripts/test_ports/vcpkg-ci-fortran/project/f/main.f90 new file mode 100644 index 00000000000000..fe0f9ea39c07d0 --- /dev/null +++ b/scripts/test_ports/vcpkg-ci-fortran/project/f/main.f90 @@ -0,0 +1,3 @@ +program main + print *, 'Hello vcpkg!' +end program main diff --git a/scripts/test_ports/vcpkg-ci-fortran/project/main.cxx b/scripts/test_ports/vcpkg-ci-fortran/project/main.cxx new file mode 100644 index 00000000000000..a9dab0dc8cdfad --- /dev/null +++ b/scripts/test_ports/vcpkg-ci-fortran/project/main.cxx @@ -0,0 +1,10 @@ +extern "C" { + void flib_(int*); +} + +int main() +{ + int n = 42; + flib_(&n); + return 0; +} diff --git a/scripts/test_ports/vcpkg-ci-fortran/vcpkg.json b/scripts/test_ports/vcpkg-ci-fortran/vcpkg.json new file mode 100644 index 00000000000000..0535532ad38da5 --- /dev/null +++ b/scripts/test_ports/vcpkg-ci-fortran/vcpkg.json @@ -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" + } + ] +}