Cannot prevent import library from being created with VS generator

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Cannot prevent import library from being created with VS generator

Jason Heeris
I'm using CMake 3.12-rc1 on Windows 10. I have the following `CMakeLists.txt`:

cmake_minimum_required(VERSION 3.8)
project(cmake_test)
unset(CMAKE_IMPORT_LIBRARY_SUFFIX)
add_library(main MODULE "main.c")

The generator is Visual Studio 15 2017.

I would like to suppress the "/IMPLIB" argument created for the "main" library. In my real project, I have static and shared libraries named the same. This works fine, because they have different extensions (lib vs dll), but a problem arises when the linker tries to create an import library for "something.dll" named "something.lib", while also trying to link against a static library named "something.lib".

The import library is not needed though; in CMake terminology the DLL is a "module" ie. loaded via DllOpen(). The documentation suggested that calling "add_library()" with "MODULE" was what I needed here. Unfortunately the resulting VS project still contains an import library flag for the linker.

A Stackoverflow answer[1] suggested unsetting "CMAKE_IMPORT_LIBRARY_SUFFIX" because the source indicates[2] this will stop the flag from appearing. But all this seems to do is drop the filename from the generated project; it still contains this now-incorrect flag that references a directory instead of a full path:

<ImportLibrary>C:/Users/heerij/Code/cmake-ex-2/build/Debug/</ImportLibrary>

How do I prevent the import library creation?

- Jason

  [1] https://stackoverflow.com/questions/34575066/how-to-prevent-cmake-from-issuing-implib
  [2] https://gitlab.kitware.com/cmake/cmake/blob/master/Source/cmComputeLinkInformation.cxx#L271

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: Cannot prevent import library from being created with VS generator

J. Caleb Wherry
I’m also interested in this. 

Side note 1: Things like this eventually lead me to have a post process (a python script) on all my VS project files to “fix” any issues like this. If I can’t figure out a way to do something specific in a VS project, I just add it to my post process until I eventually have time to dig in and figure it out. For this specific issue, I just match a regex for the line and remove it. I know this shouldn’t be neccessary but sometimes I just don’t have the time to figure out a specific generator problem.

Side note 2: I also used this process at one point to make relocatable VS solutions/projects. It worked quite well and is a quick way to get around short comings in how CMake creates VS artifacts.

-Caleb

On Mon, Jul 9, 2018 at 6:49 PM Jason Heeris <[hidden email]> wrote:
I'm using CMake 3.12-rc1 on Windows 10. I have the following `CMakeLists.txt`:

cmake_minimum_required(VERSION 3.8)
project(cmake_test)
unset(CMAKE_IMPORT_LIBRARY_SUFFIX)
add_library(main MODULE "main.c")

The generator is Visual Studio 15 2017.

I would like to suppress the "/IMPLIB" argument created for the "main" library. In my real project, I have static and shared libraries named the same. This works fine, because they have different extensions (lib vs dll), but a problem arises when the linker tries to create an import library for "something.dll" named "something.lib", while also trying to link against a static library named "something.lib".

The import library is not needed though; in CMake terminology the DLL is a "module" ie. loaded via DllOpen(). The documentation suggested that calling "add_library()" with "MODULE" was what I needed here. Unfortunately the resulting VS project still contains an import library flag for the linker.

A Stackoverflow answer[1] suggested unsetting "CMAKE_IMPORT_LIBRARY_SUFFIX" because the source indicates[2] this will stop the flag from appearing. But all this seems to do is drop the filename from the generated project; it still contains this now-incorrect flag that references a directory instead of a full path:

<ImportLibrary>C:/Users/heerij/Code/cmake-ex-2/build/Debug/</ImportLibrary>

How do I prevent the import library creation?

- Jason

  [1] https://stackoverflow.com/questions/34575066/how-to-prevent-cmake-from-issuing-implib
  [2] https://gitlab.kitware.com/cmake/cmake/blob/master/Source/cmComputeLinkInformation.cxx#L271
--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake
--
Sent from my iPhone 4s

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: Cannot prevent import library from being created with VS generator

Jason Heeris
On Tue, 10 Jul 2018 at 09:57, J. Caleb Wherry <[hidden email]> wrote:
> Side note 1: Things like this eventually lead me to have a post process (a python script) on all my VS project files to “fix” any issues like this.

It might interest you to know that I've worked around it a bit by tweaking the IMPORT_PREFIX property:

    set_target_properties(
        ${modname_dll}
        PROPERTIES
        OUTPUT_NAME
            ${module_name}
        # Required to work around the fact that we rename our shared libraries
        # to have the same name as our static libraries, so when Visual Studio's
        # linker tries to create an export library, it clashes with an input
        # library.
        IMPORT_PREFIX
            "import_"
    )

Cheers,
Jason

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake