From 0164145b068004316c91fd21ea075ea07cec19ae Mon Sep 17 00:00:00 2001 From: Kai Pastor Date: Tue, 17 Dec 2024 09:08:52 +0100 Subject: [PATCH 01/10] [vcpkg-ci-fortran] New test port --- .../vcpkg-ci-fortran/portfile.cmake | 16 ++++++++++++++++ .../vcpkg-ci-fortran/project/CMakeLists.txt | 12 ++++++++++++ .../vcpkg-ci-fortran/project/f/CMakeLists.txt | 1 + .../vcpkg-ci-fortran/project/f/main.f90 | 3 +++ .../test_ports/vcpkg-ci-fortran/vcpkg.json | 19 +++++++++++++++++++ 5 files changed, 51 insertions(+) create mode 100644 scripts/test_ports/vcpkg-ci-fortran/portfile.cmake create mode 100644 scripts/test_ports/vcpkg-ci-fortran/project/CMakeLists.txt create mode 100644 scripts/test_ports/vcpkg-ci-fortran/project/f/CMakeLists.txt create mode 100644 scripts/test_ports/vcpkg-ci-fortran/project/f/main.f90 create mode 100644 scripts/test_ports/vcpkg-ci-fortran/vcpkg.json 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..b48ea62f5f4ab6 --- /dev/null +++ b/scripts/test_ports/vcpkg-ci-fortran/portfile.cmake @@ -0,0 +1,16 @@ +set(VCPKG_POLICY_EMPTY_PACKAGE enabled) + +vcpkg_cmake_get_vars(cmake_vars_file) +include("${cmake_vars_file}") + +include(vcpkg_find_fortran) +vcpkg_find_fortran(FORTRAN_CMAKE) + +vcpkg_cmake_configure( + SOURCE_PATH "${CURRENT_PORT_DIR}/project" + OPTIONS + ${FORTRAN_CMAKE} + "-DEXPECTED_C_COMPILER=${VCPKG_DETECTED_CMAKE_C_COMPILER}" + "-DEXPECTED_CXX_COMPILER=${VCPKG_DETECTED_CMAKE_CXX_COMPILER}" +) +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..06be20c8842b5a --- /dev/null +++ b/scripts/test_ports/vcpkg-ci-fortran/project/CMakeLists.txt @@ -0,0 +1,12 @@ +cmake_minimum_required(VERSION 3.16) +project(vcpkg-ci-fortran C CXX Fortran) + +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() + +include(CMakeAddFortranSubdirectory) +cmake_add_fortran_subdirectory(f NO_EXTERNAL_INSTALL) 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..542e359d0afe47 --- /dev/null +++ b/scripts/test_ports/vcpkg-ci-fortran/project/f/CMakeLists.txt @@ -0,0 +1 @@ +add_executable(main main.f90) 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/vcpkg.json b/scripts/test_ports/vcpkg-ci-fortran/vcpkg.json new file mode 100644 index 00000000000000..35c25fdbc5fb6c --- /dev/null +++ b/scripts/test_ports/vcpkg-ci-fortran/vcpkg.json @@ -0,0 +1,19 @@ +{ + "name": "vcpkg-ci-fortran", + "version-string": "ci", + "description": "Validates fortran scripts.", + "dependencies": [ + { + "name": "vcpkg-cmake", + "host": true + }, + { + "name": "vcpkg-cmake-get-vars", + "host": true + }, + { + "name": "vcpkg-gfortran", + "platform": "windows & !arm & !uwp" + } + ] +} From 2bac8555e7d58d94214131343c799c145598a4c9 Mon Sep 17 00:00:00 2001 From: Kai Pastor Date: Wed, 18 Dec 2024 07:53:28 +0100 Subject: [PATCH 02/10] Disable android, uwp --- scripts/test_ports/vcpkg-ci-fortran/vcpkg.json | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/test_ports/vcpkg-ci-fortran/vcpkg.json b/scripts/test_ports/vcpkg-ci-fortran/vcpkg.json index 35c25fdbc5fb6c..bff77de9ba5e85 100644 --- a/scripts/test_ports/vcpkg-ci-fortran/vcpkg.json +++ b/scripts/test_ports/vcpkg-ci-fortran/vcpkg.json @@ -2,6 +2,7 @@ "name": "vcpkg-ci-fortran", "version-string": "ci", "description": "Validates fortran scripts.", + "supports": "!android & !uwp", "dependencies": [ { "name": "vcpkg-cmake", From d6e7b6ae84505135db974f4e05f2c7949bd9fa18 Mon Sep 17 00:00:00 2001 From: Kai Pastor Date: Wed, 18 Dec 2024 08:14:52 +0100 Subject: [PATCH 03/10] WIP --- .../vcpkg-ci-fortran/portfile.cmake | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/scripts/test_ports/vcpkg-ci-fortran/portfile.cmake b/scripts/test_ports/vcpkg-ci-fortran/portfile.cmake index b48ea62f5f4ab6..25447c3c62adcc 100644 --- a/scripts/test_ports/vcpkg-ci-fortran/portfile.cmake +++ b/scripts/test_ports/vcpkg-ci-fortran/portfile.cmake @@ -4,7 +4,24 @@ vcpkg_cmake_get_vars(cmake_vars_file) include("${cmake_vars_file}") include(vcpkg_find_fortran) -vcpkg_find_fortran(FORTRAN_CMAKE) +# 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 +) + vcpkg_find_fortran(FORTRAN_CMAKE) +endblock() + +if(VCPKG_USE_INTERNAL_Fortran) + list(FILTER FORTRAN_CMAKE EXCLUDE REGEX "-DCMAKE_C_COMPILER=") + list(APPEND FORTRAN_CMAKE --trace-expand) +endif() vcpkg_cmake_configure( SOURCE_PATH "${CURRENT_PORT_DIR}/project" From a72282abdf3c1dfb273c11b187be80249e035f78 Mon Sep 17 00:00:00 2001 From: Kai Pastor Date: Wed, 18 Dec 2024 22:41:28 +0100 Subject: [PATCH 04/10] WIP --- scripts/test_ports/vcpkg-ci-fortran/portfile.cmake | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/test_ports/vcpkg-ci-fortran/portfile.cmake b/scripts/test_ports/vcpkg-ci-fortran/portfile.cmake index 25447c3c62adcc..f65d2d4c7dee85 100644 --- a/scripts/test_ports/vcpkg-ci-fortran/portfile.cmake +++ b/scripts/test_ports/vcpkg-ci-fortran/portfile.cmake @@ -20,6 +20,8 @@ endblock() if(VCPKG_USE_INTERNAL_Fortran) list(FILTER FORTRAN_CMAKE EXCLUDE REGEX "-DCMAKE_C_COMPILER=") + list(APPEND FORTRAN_CMAKE "-DCMAKE_C_COMPILER=${VCPKG_DETECTED_CMAKE_C_COMPILER}") + list(APPEND FORTRAN_CMAKE "-DCMAKE_CXX_COMPILER=${VCPKG_DETECTED_CMAKE_CXX_COMPILER}") list(APPEND FORTRAN_CMAKE --trace-expand) endif() From 22448e4d2df5efe0c6b8b3c5a73a8d9edd3bfae7 Mon Sep 17 00:00:00 2001 From: Kai Pastor Date: Thu, 19 Dec 2024 04:38:39 +0100 Subject: [PATCH 05/10] WIP --- scripts/test_ports/vcpkg-ci-fortran/portfile.cmake | 4 ++-- scripts/test_ports/vcpkg-ci-fortran/project/CMakeLists.txt | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/test_ports/vcpkg-ci-fortran/portfile.cmake b/scripts/test_ports/vcpkg-ci-fortran/portfile.cmake index f65d2d4c7dee85..d04550d747ed85 100644 --- a/scripts/test_ports/vcpkg-ci-fortran/portfile.cmake +++ b/scripts/test_ports/vcpkg-ci-fortran/portfile.cmake @@ -20,8 +20,8 @@ endblock() if(VCPKG_USE_INTERNAL_Fortran) list(FILTER FORTRAN_CMAKE EXCLUDE REGEX "-DCMAKE_C_COMPILER=") - list(APPEND FORTRAN_CMAKE "-DCMAKE_C_COMPILER=${VCPKG_DETECTED_CMAKE_C_COMPILER}") - list(APPEND FORTRAN_CMAKE "-DCMAKE_CXX_COMPILER=${VCPKG_DETECTED_CMAKE_CXX_COMPILER}") + #list(APPEND FORTRAN_CMAKE "-DCMAKE_C_COMPILER=${VCPKG_DETECTED_CMAKE_C_COMPILER}") + #list(APPEND FORTRAN_CMAKE "-DCMAKE_CXX_COMPILER=${VCPKG_DETECTED_CMAKE_CXX_COMPILER}") list(APPEND FORTRAN_CMAKE --trace-expand) endif() diff --git a/scripts/test_ports/vcpkg-ci-fortran/project/CMakeLists.txt b/scripts/test_ports/vcpkg-ci-fortran/project/CMakeLists.txt index 06be20c8842b5a..8d0e5c5d76e1ab 100644 --- a/scripts/test_ports/vcpkg-ci-fortran/project/CMakeLists.txt +++ b/scripts/test_ports/vcpkg-ci-fortran/project/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.16) -project(vcpkg-ci-fortran C CXX Fortran) +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}") From 466e0fe7bcc316abe3c24ec3f1321581bd2f5609 Mon Sep 17 00:00:00 2001 From: Kai Pastor Date: Wed, 1 Jan 2025 21:15:07 +0100 Subject: [PATCH 06/10] WIP --- scripts/test_ports/vcpkg-ci-fortran/portfile.cmake | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/test_ports/vcpkg-ci-fortran/portfile.cmake b/scripts/test_ports/vcpkg-ci-fortran/portfile.cmake index d04550d747ed85..ffe4c65edcb1be 100644 --- a/scripts/test_ports/vcpkg-ci-fortran/portfile.cmake +++ b/scripts/test_ports/vcpkg-ci-fortran/portfile.cmake @@ -27,6 +27,7 @@ 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}" From 74a325db100577c8beeb207087a2774e7419285d Mon Sep 17 00:00:00 2001 From: Kai Pastor Date: Thu, 2 Jan 2025 07:23:50 +0100 Subject: [PATCH 07/10] WIP --- scripts/test_ports/vcpkg-ci-fortran/portfile.cmake | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/test_ports/vcpkg-ci-fortran/portfile.cmake b/scripts/test_ports/vcpkg-ci-fortran/portfile.cmake index ffe4c65edcb1be..f2473c00fdb16d 100644 --- a/scripts/test_ports/vcpkg-ci-fortran/portfile.cmake +++ b/scripts/test_ports/vcpkg-ci-fortran/portfile.cmake @@ -15,7 +15,9 @@ block(SCOPE_FOR VARIABLES # 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() if(VCPKG_USE_INTERNAL_Fortran) From 9ca720d8964d3ff610b21690ed0251a2db02ca19 Mon Sep 17 00:00:00 2001 From: Kai Pastor Date: Thu, 2 Jan 2025 08:04:11 +0100 Subject: [PATCH 08/10] WIP --- scripts/test_ports/vcpkg-ci-fortran/project/f/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/test_ports/vcpkg-ci-fortran/project/f/CMakeLists.txt b/scripts/test_ports/vcpkg-ci-fortran/project/f/CMakeLists.txt index 542e359d0afe47..1f471489b1601e 100644 --- a/scripts/test_ports/vcpkg-ci-fortran/project/f/CMakeLists.txt +++ b/scripts/test_ports/vcpkg-ci-fortran/project/f/CMakeLists.txt @@ -1 +1,2 @@ -add_executable(main main.f90) +project(pure-fortran Fortran) +add_library(flib SHARED main.f90) From aa724fed95271350f8ec1634c79255da2a3079ce Mon Sep 17 00:00:00 2001 From: Kai Pastor Date: Thu, 2 Jan 2025 19:16:34 +0100 Subject: [PATCH 09/10] WIP --- scripts/test_ports/vcpkg-ci-fortran/portfile.cmake | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/test_ports/vcpkg-ci-fortran/portfile.cmake b/scripts/test_ports/vcpkg-ci-fortran/portfile.cmake index f2473c00fdb16d..d2b0b58fcbd141 100644 --- a/scripts/test_ports/vcpkg-ci-fortran/portfile.cmake +++ b/scripts/test_ports/vcpkg-ci-fortran/portfile.cmake @@ -22,6 +22,7 @@ endblock() 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}") #list(APPEND FORTRAN_CMAKE "-DCMAKE_C_COMPILER=${VCPKG_DETECTED_CMAKE_C_COMPILER}") #list(APPEND FORTRAN_CMAKE "-DCMAKE_CXX_COMPILER=${VCPKG_DETECTED_CMAKE_CXX_COMPILER}") list(APPEND FORTRAN_CMAKE --trace-expand) From 746eb97f54adf24bb28e67e5fd3e397761e12333 Mon Sep 17 00:00:00 2001 From: Kai Pastor Date: Fri, 3 Jan 2025 09:19:32 +0100 Subject: [PATCH 10/10] WIP --- scripts/test_ports/vcpkg-ci-fortran/portfile.cmake | 7 ++++--- .../test_ports/vcpkg-ci-fortran/project/CMakeLists.txt | 10 ++++++++++ .../vcpkg-ci-fortran/project/f/CMakeLists.txt | 6 +++++- scripts/test_ports/vcpkg-ci-fortran/project/f/flib.f90 | 4 ++++ scripts/test_ports/vcpkg-ci-fortran/project/main.cxx | 10 ++++++++++ scripts/test_ports/vcpkg-ci-fortran/vcpkg.json | 2 +- 6 files changed, 34 insertions(+), 5 deletions(-) create mode 100644 scripts/test_ports/vcpkg-ci-fortran/project/f/flib.f90 create mode 100644 scripts/test_ports/vcpkg-ci-fortran/project/main.cxx diff --git a/scripts/test_ports/vcpkg-ci-fortran/portfile.cmake b/scripts/test_ports/vcpkg-ci-fortran/portfile.cmake index d2b0b58fcbd141..eabe79188e232a 100644 --- a/scripts/test_ports/vcpkg-ci-fortran/portfile.cmake +++ b/scripts/test_ports/vcpkg-ci-fortran/portfile.cmake @@ -1,8 +1,10 @@ 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 @@ -20,12 +22,10 @@ block(SCOPE_FOR VARIABLES 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}") - #list(APPEND FORTRAN_CMAKE "-DCMAKE_C_COMPILER=${VCPKG_DETECTED_CMAKE_C_COMPILER}") - #list(APPEND FORTRAN_CMAKE "-DCMAKE_CXX_COMPILER=${VCPKG_DETECTED_CMAKE_CXX_COMPILER}") - list(APPEND FORTRAN_CMAKE --trace-expand) endif() vcpkg_cmake_configure( @@ -35,5 +35,6 @@ vcpkg_cmake_configure( ${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 index 8d0e5c5d76e1ab..cbdd0bede3e7f9 100644 --- a/scripts/test_ports/vcpkg-ci-fortran/project/CMakeLists.txt +++ b/scripts/test_ports/vcpkg-ci-fortran/project/CMakeLists.txt @@ -1,4 +1,5 @@ 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) @@ -8,5 +9,14 @@ 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 index 1f471489b1601e..46e2cd3d6216a5 100644 --- a/scripts/test_ports/vcpkg-ci-fortran/project/f/CMakeLists.txt +++ b/scripts/test_ports/vcpkg-ci-fortran/project/f/CMakeLists.txt @@ -1,2 +1,6 @@ +# Unconditionally enable Fortran here. project(pure-fortran Fortran) -add_library(flib SHARED main.f90) + +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/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 index bff77de9ba5e85..0535532ad38da5 100644 --- a/scripts/test_ports/vcpkg-ci-fortran/vcpkg.json +++ b/scripts/test_ports/vcpkg-ci-fortran/vcpkg.json @@ -2,7 +2,7 @@ "name": "vcpkg-ci-fortran", "version-string": "ci", "description": "Validates fortran scripts.", - "supports": "!android & !uwp", + "supports": "!android & !uwp & !(windows & arm)", "dependencies": [ { "name": "vcpkg-cmake",