Re: [Fwd: GLPK CMake build configuration (Windows)]

2024-02-01 Thread Derek Huang
Hi,

Just wanted to put an update for the CMakeLists.txt since I forgot to CC to
the mailing list, apologies.

Also, since I forgot to CC my previous email about this, maybe we just
remove glp_netgen_prob from netgen.c and glpk.h since it is not called and
causes linker error when building DLL on Windows since glp_netgen_prob is
listed in the .def file?

I saw the other possible change as mentioned in
https://www.mail-archive.com/bug-glpk@gnu.org/msg01020.html; maybe that
could be done officially?

Best,
Derek

On Mon, Jan 29, 2024 at 3:43 PM Derek Huang  wrote:

> I see, thank you.
>
>
>
> So maybe we can just add these netgen.c changes to the upstream? Since it
> is definitely a bit strange to have only a public API function declaration
> without a definition.
>
>
>
> Best,
>
> Derek
>
cmake_minimum_required(VERSION 3.15)

##
# Usage
# =
#
# This section provides some brief instructions on how to compile, test, and
# install GLPK using CMake. Although currently configured only for use on
# Windows, the config can be extended to support *nix systems as well.
#
# Note:
#
# This file can be split up into smaller .cmake files if desired. It is a few
# hundred lines long unfortunately in large part since the sources are all
# listed explicitly instead of using globs and because of the install logic.
#
# Windows
# ---
#
# The following items are values to be determined by the user. They are used in
# the build commands enclosed in brackets to distinguish them.
#
# Arch: Win32, x64
# Config: Debug, Release
# Prefix: (desired install root)
#
# Building
# 
#
# Note:
#
# Building dynamically, i.e. with -DBUILD_SHARED_LIBS=ON, will result in a
# linker error about an unresolved external symbol (glp_netgen_prob). The
# definition of this function is nowhere to be found in the GLPK source. To fix
# this, glp_netgen_prob needs to be removed from the .def file. It is also
# better that glp_netgen_prob is simply commented out from glpk.h too.
#
# Build static linking against C runtime dynamically + also build examples:
#
#   cmake -S . -B build_windows_[Arch] -A [Arch]
#   cmake --build build_windows_[Arch] --config [Config] -j
#
# Build dynamic linking against C runtime statically + no examples:
#
#   cmake -S . -B build_windows_[Arch] -A [Arch] -DBUILD_SHARED_LIBS=ON ^
#   -DGLPK_USE_STATIC_CRT=ON -DGLPK_BUILD_EXAMPLES=OFF
#   cmake --build build_windows_[Arch] --config [Config] -j
#
# Build dynamic linking against C runtime dynamically + also build examples
# while installing with multi-configuration install tree:
#
#   cmake -S . -B build_windows_[Arch] -A [Arch] -DBUILD_SHARED_LIBS=ON ^
#   -DGLPK_INSTALL_MULTI_CONFIG=ON
#   cmake --build build_windows_[Arch] --config [Config] -j
#
# Testing
# ~~~
#
# Note:
#
# Testing a dynamic build's example programs will result in an exit code of
# C135 since PATH must be updated or the DLL must be in the working
# directory for correct run-time loading. The example programs assume their
# inputs are in the current directory which makes this difficult.
#
#   ctest --test-dir build_windows_[Arch] -C [Config] -j
#
# Install
# ~~~
#
#   cmake --install build_windows_[Arch] --prefix [Prefix] --config [Config]
#
# If GLPK_INSTALL_MULTI_CONFIG is specified, and assuming that we are building
# shared libraries, the install tree looks like this:
#
# install_root/
#   bin/
# Debug/
#   glpk.dll
#   glpsol.exe
# Release/
#   glpk.dll
#   glpsol.exe
#   include/
# glpk.h
#   lib/
# Debug/
#   glpk.lib
#   glpk.pdb
# Release/
#   glpk.lib
#
# Otherwise, we have a flat install with "d" suffices, e.g.
#
# install_root/
#   bin/
# glpk.dll
# glpkd.dll
# glpsol.exe
# glpsold.exe
#   include/
# glpk.h
#   lib/
# glpk.lib
# glpkd.lib
# glpkd.pdb
#

# GLPK version
set(GLPK_VERSION_MAJOR 5)
set(GLPK_VERSION_MINOR 0)
set(GLPK_VERSION ${GLPK_VERSION_MAJOR}.${GLPK_VERSION_MINOR})

project(
glpk
VERSION ${GLPK_VERSION}
DESCRIPTION "GNU Linear Programming Kit"
HOMEPAGE_URL "https://www.gnu.org/software/glpk/;
LANGUAGES C
)

# select static/shared library compilation
option(BUILD_SHARED_LIBS "Build GLPK library as shared" OFF)
# use static C runtime library. defaulted to OFF to match the CMake default of
# using MultiThreaded$<$:Debug>DLL to select dynamic C runtime.
# see https://cmake.org/cmake/help/latest/prop_tgt/MSVC_RUNTIME_LIBRARY.html,
# https://learn.microsoft.com/en-us/cpp/c-runtime-library/crt-library-features
option(GLPK_USE_STATIC_CRT "Link against C runtime statically" OFF)
# to separate Debug and Release libraries, which also link against debug and
# release C runtimes respectively (should never be mixed), add an extra layer
# of namespacing to lib and bin, e.g. lib/Debug, bin/Release, etc. for MSVC, if
# this is not specified, debug libraries + PDB is suffixed with "d"
option(GLPK_INSTALL_MULTI_CONFIG OFF)
# build example programs

Re: [Fwd: GLPK CMake build configuration (Windows)]

2024-01-29 Thread Andrew Makhorin
On Mon, 2024-01-29 at 12:25 -0500, Derek Huang wrote:
> Hi,
>  
> Quick update on this—I tried rebuilding clean again using the
> CMakeLists.txt and realized there is an issue with the glpk_5_0.def
> files in ./w32 and ./w64 since they list glp_netgen_prob as an export,
> but it has no definition for the linker to find. I would think either
> glp_netgen_prob should be removed from glpk.h and the .def file or
> some definition for glp_netgen_prob that just asserts should be added.

It is a minor annoying bug in the batch script for MS Windows.

Please see https://www.mail-archive.com/bug-glpk@gnu.org/msg01020.html .



>  
> There is also an issue with running tests using ctest due to how DLL
> lookup is done at runtime, as the example programs must be run from
> ./examples (inputs are relative to that directory) so the GLPK DLL is
> not picked up. Static library builds and testing are fine however.
>  
> I have updated the CMakeLists.txt docs to reflect these and have done
> a bit of cleanup and since I couldn’t fine official VCS for GLPK I’ve
> attached the updated file here.
>  
> Best,
> Derek
>