Menu

#335 CMake build fails if the mpg123 is added with add_subdirectory() to existing CMake project

1.29.x
closed-fixed
nobody
None
5
2022-06-26
2022-03-14
Mykola P
No

CMake build fails if the mpg123 is added with add_subdirectory() to existing CMake project. For example, here is how it's done for Conan package manager's CMake project wrapper:

cmake_minimum_required(VERSION 3.4)
project(cmake_wrapper)

include(conanbuildinfo.cmake)
conan_basic_setup()

add_subdirectory(source_subfolder/ports/cmake)

In this case the source_subfolder contains mpg123 repository and for such CMakeLists.txt the
cmake -G "Visual Studio 15 2017 Win64" will produce the error:

CMake Error at source_subfolder/ports/cmake/cmake/read_api_version.cmake:3 (file):
  file failed to open for reading (No such file or directory):

    C:/J/w/prod/BuildSingleReference@5/.conan/data/mpg123/1.29.3/_/_/build/fe37d0493f91b5e4c13e7de0e5f46d3174dff5b9/../../configure.ac

The root cause is that the CMAKE_SOURCE_DIR used in ports/cmake/cmake/read_api_version.cmake points to the parent CMake project folder instead of the mpg123's CMake project folder. In the past the PROJECT_SOURCE_DIR was used instead.
Broken with the commit:

Revision 4887 - (view) (download) (annotate) - [select for diffs]
Modified Thu May 6 11:10:43 2021 UTC (10 months, 1 week ago) by thor
File length: 723 byte(s)
Diff to previous 4717

ports/cmake: also read project version (only the 1.2.3 part)

CMake's regexes suck. And I suck and writing them. So only the
version without any hypothetical suffix.

Discussion

  • Mykola P

    Mykola P - 2022-03-15

    Locally I've tried the CMAKE_CURRENT_SOURCE_DIR instead of CMAKE_SOURCE_DIR and it fixed the issue.

     
  • Thomas Orgis

    Thomas Orgis - 2022-03-15

    So you recommend this variable instead of the project one?

     
  • Mykola P

    Mykola P - 2022-03-15

    Yes, the CMAKE_CURRENT_SOURCE_DIR looks like a more correct change.

     
  • Thomas Orgis

    Thomas Orgis - 2022-03-16

    OK, I hope current trunk is fine. Thanks.

     
    👍
    1
  • Thomas Orgis

    Thomas Orgis - 2022-06-26
    • status: open --> closed-fixed
     

Log in to post a comment.