0

I am converting a project to stop using Visual Studio Project Files and switch to using cmake.

The project is already a few years old, and makes use of custom precompiled external libraries, located outside the code tree:

src/
    ... source tree ...
externalLibs/
    Python27/
        include/
            ... header files ...
        libs/
            python27.lib
            python27_d.lib
cmake/
    Modules/
        FindPython2.cmake

What I have done is add the directory cmake/Modules, and inside it the file FindPython2.cmake.

Then, I have created the CMakeLists.txt of one of the project components:

cmake_minimum_required( VERSION 3.17 )
project( ConnectorTests CXX )

include( ../../../../../global.cmake )

set( CMAKE_MODULE_PATH "${ROOT_PATH}/cmake/Modules" ${CMAKE_MODULE_PATH} )

message( "CMAKE_MODULE_PATH:" "${CMAKE_MODULE_PATH}" )

find_package( Python2 REQUIRED )

add_executable( ConnectorTests pch.h pch.cpp Tests.cpp )

target_include_directories( ConnectorTests PRIVATE
  ../../Connector
  ../../MtoUtils
  "${Python2_INCLUDE_DIRS}"
)

target_link_libraries( ConnectorTests PRIVATE Python2 )

The above is just an excerpt with the relevant parts.

I include a global with the path definitions (include( ../../../../../global.cmake), I establish where to look for the modules (set( CMAKE_MODULE_PATH "${ROOT_PATH}/cmake/Modules"$ {CMAKE_MODULE_PATH} )), and I use my custom module (find_package( Python2 REQUIRED ).

I've put a message( ) to see if everything looks fine, and it shows me what I expect:

CMAKE_MODULE_PATH: E:/cmake/Modules

My FindPython2.cmake module is this:

add_library( Python2 SHARED IMPORTED )

if( WIN32 )
  set_target_properties( Python2 PROPERTIES IMPORTED_LOCATION_RELEASE "${ROOT_PATH}/externalLibs/Python27/libs/python27.lib" )
  set_target_properties( Python2 PROPERTIES IMPORTED_LOCATION_DEBUG "${ROOT_PATH}/externalLibs/Python27/libs/python27_d.lib" )
endif( )

set( Python2_FOUND ON )
set( Python2_Development_FOUND ON )
set( Python2_Development.Module_FOUND ON )
set( Python2_Development.Embed_FOUND ON )
set( Python2_INCLUDE_DIRS "${ROOT_PATH}/externalLibs/Python27/include" )

I generate the project without problems:

 cmake -B build -T v141, host = x86 -A win32

But when compiling:

 cmake --build build

LINK : fatal error LNK1104: no se puede abrir el archivo 'Python2-NOTFOUND.obj' [E:\Desarrollo\PATH\build\Test\ConnectorTests\ConnectorTests.vcxproj]

I'm using:

cmake --version
cmake version 3.17.20032601-MSVC_2

  • What am I doing wrong ?
  • How do I solve it ?
Trauma
  • 173
  • 1
  • 9
  • Spanish version: [Creación de archivos de importación de módulos externos](https://es.stackoverflow.com/q/384954/19610) – Trauma Aug 26 '20 at 07:55
  • 1
    For a SHARED IMPORTED library its IMPORTED_LOCATION property should point to the `.dll` file, not to the `.lib` file. See that question: https://stackoverflow.com/questions/14850736/cmake-imported-library-behaviour. – Tsyvarev Aug 26 '20 at 07:58
  • @Tsyvarev Thx, I look at it now. – Trauma Aug 26 '20 at 08:01

0 Answers0