ERGO-Code / HiGHS

Linear optimization software
MIT License
973 stars 180 forks source link

Failed to install highs_fortran_api.mod on Windows #1887

Closed limska closed 1 month ago

limska commented 2 months ago

Description

The packaging is looking for file in build/modules/Debug/highs_fortran_api.mod instead of build/modules/highs_fortran_api.mod. The fix is to treat installation the same for MSVC and non MSVC in src/CMakeLists.txt:355.

Steps to reproduce

Using: cmake 3.28.3, Intel oneAPI 2024.0

C:\Users\sava.slijepcevic\repos\public\HiGHS>cmake -S . -B build -DFORTRAN=ON
...
C:\Users\sava.slijepcevic\repos\public\HiGHS>cmake --build build
...
C:\Users\sava.slijepcevic\repos\public\HiGHS>cpack --config build/CPackConfig.cmake
CPack: Create package using NSIS
CPack: Install projects
CPack: - Install project: HIGHS []
CMake Error at C:/Users/sava.slijepcevic/repos/public/HiGHS/build/src/cmake_install.cmake:956 (file):
  file INSTALL cannot find
  "C:/Users/sava.slijepcevic/repos/public/HiGHS/build/modules/Debug/highs_fortran_api.mod":
  File exists.
Call Stack (most recent call first):
  C:/Users/sava.slijepcevic/repos/public/HiGHS/build/cmake_install.cmake:37 (include)

CPack Error: Error when generating package: HIGHS

C:\Users\sava.slijepcevic\repos\public\HiGHS>dir build\modules
 Volume in drive C has no label.
 Volume Serial Number is 7EE4-9D42

 Directory of C:\Users\sava.slijepcevic\repos\public\HiGHS\build\modules

20/08/2024  12:15    <DIR>          .
20/08/2024  15:34    <DIR>          ..
20/08/2024  12:15            99,974 highs_fortran_api.mod
               1 File(s)         99,974 bytes
               2 Dir(s)  134,009,511,936 bytes free

C:\Users\sava.slijepcevic\repos\public\HiGHS>
limska commented 2 months ago

A potential fix would be to replace HiGHS/CMakeLists.txt:355:

if(NOT MSVC)
    install(FILES ${HIGHS_BINARY_DIR}/modules/highs_fortran_api.mod DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/highs/fortran)
else()
    install(FILES ${HIGHS_BINARY_DIR}/modules/${CMAKE_BUILD_TYPE}/highs_fortran_api.mod DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/highs/fortran)
endif()

with just:

install(FILES ${HIGHS_BINARY_DIR}/modules/highs_fortran_api.mod DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/highs/fortran)
galabovaa commented 2 months ago

Thank you @limska, I will give it a go

galabovaa commented 2 months ago

When I try to build on my Windows mahcine, I get similar results with powershell and the newly installed intel oneAPI shell. However, the intel oneAPI shell on my machine also starts with PS, and yours does not, which shell are you using?

By default, with MSVC, the Debug config is built. To get release code, the config must be specified with

cmake --build build --config Release

or

cmake --build build --config Release --parallel

for parallel build.

It is curious why in your build the path to the Highs lib and exe is not in a Debug or Release subdir.

The reason we have separated the cases is that MSVC specifies the build type on cmake --build, rather than on the CMake generation step with -DCMAKE_BUILD_TYPE, like on unix.

I did get a couple of errors, the first one saying

CMake Error: CMake can not determine linker language for target: fortrantest

which is fixed by specifying the linker language in cmake: see branch fortran-win

image

and

CMake Error at C:/Users/galab/code/HiGHS/build/cmake_install.cmake:60 (file): file INSTALL cannot find "C:/Users/galab/code/HiGHS/build/bin/Release/highs.dll": File exists. which is fixed by adding the --config Release flag, because the default config is Debug.

So, using cpack, after installing NSIS which we had not used so far and was missing, I get

PS C:\Users\galab\code\HiGHS> cmake -S . -B build -DFORTRAN=ON
...

PS C:\Users\galab\code\HiGHS> cpack --config build/CPackConfig.cmake
CPack: Create package using NSIS
CPack: Install projects
CPack: - Install project: HIGHS []
CPack: Create package
CPack: - package: C:/Users/galab/code/HiGHS/HIGHS-1.7.2-win64.exe generated.

Do you use any custom settings anywhere? Is your oneAPI integrated with Visual Studio? Are you using MSVC to build? Perhaps you need to specify the generator for CMake, depending on your configuration.

What happens if you try to specify --config Release at cmake --build?

Could you share a CMake log, so I can see more details about your setup, possibly the file generated at

build\CMakeFiles\CMakeConfigureLog.yaml

limska commented 1 month ago

CMakeConfigureLog.yaml.txt

limska commented 1 month ago

@galabovaa I used Windows command prompt because I had issues with oneAPI and PowerShell. I tried again but this time I specified Release at all 3 stages and the packaging worked as follows:

C:\Users\sava.slijepcevic\repos\public\HiGHS>cmake --build build --config Release
...

cmake --build build --config Release
...

C:\Users\sava.slijepcevic\repos\public\HiGHS>cpack --config build/CPackConfig.cmake -C Release
...

Sorry, looks like this is not a bug after all.