Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

Problem with CMake Generation

Programming languages, Coding, Executables, Package Creation, and Scripting.
Post Reply
Message
Author
MultiplexLayout
Posts: 56
Joined: 2020-09-23 19:21
Has thanked: 7 times

Problem with CMake Generation

#1 Post by MultiplexLayout »

I am working on a project that looks like this:

./
CMakeLists.txt

externals/
|---CMakeLists.txt
|---boost/
|---dynatmic/
|---|---CMakeLists.txt

Note that the boost directory doesn't have a CMakeLists.txt. Its sources are set in externals/CMakeLists.txt.

Relevant part of root CMakeLists.txt

Code: Select all

add_subdirectory(externals)
add_library(Boost::boost ALIAS boost)
Relevant part of externals/CMakelists.txt

Code: Select all

set(BOOST_ROOT "${CMAKE_SOURCE_DIR}/externals/boost" CACHE STRING "")
set(Boost_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/externals/boost" CACHE STRING "")
set(Boost_NO_SYSTEM_PATHS ON CACHE BOOL "")
add_library(boost INTERFACE)
target_include_directories(boost SYSTEM INTERFACE ${Boost_INCLUDE_DIR})
The problem:
What I want is to move the ALIAS line from the root CMakeLists.txt to the one in externals/. However when I move this line and run cmake I get:

Code: Select all

-- Configuring done (1.2s)
CMake Error: install(EXPORT "dynarmicTargets" ...) includes target "dynarmic" which requires target "boost" that is not in any export set.
-- Generating done (0.2s)
CMake Generate step failed.  Build files cannot be regenerated correctly.
Relevant part of externals/dynarmic/CMakeLists.txt

Code: Select all

install(TARGETS dynarmic EXPORT dynarmicTargets)
install(EXPORT dynarmicTargets
    NAMESPACE dynarmic::
    DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/dynarmic"
)
I just don't understand how dynarmic can "see" the ALIAS line when it's in the root CMakeLists (2 levels above it), but not when it's in externals/ (1 level above it). I have tried adding EXCLUDE_FROM_ALL to add_library(boost INTERFACE) and removing it from add_subdirectory(dynarmic EXCLUDE_FROM_ALL). I just don't know what else to try. Any help would be greatly appreciated.

User avatar
mrnordio2
Posts: 26
Joined: 2023-03-29 14:53
Has thanked: 1 time
Been thanked: 6 times

Re: Problem with CMake Generation

#2 Post by mrnordio2 »

Hello MultiplexLayout,

The issue seems to be related to the scope of the Boost::boost alias. When you define an alias in the root CMakeLists.txt, it becomes available to all subdirectories, making it visible to dynarmic. However, if you move it to externals/CMakeLists.txt, its scope becomes limited to externals and its subdirectories, but not to dynarmic.

Method 1:
Use add_subdirectory for dynarmic inside externals/CMakeLists.txt

If you add dynarmic as a subdirectory inside externals/CMakeLists.txt, after defining the alias, the alias will be in scope for dynarmic. Modify externals/CMakeLists.txt like this:

Code: Select all

set(BOOST_ROOT "${CMAKE_SOURCE_DIR}/externals/boost" CACHE STRING "")
set(Boost_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/externals/boost" CACHE STRING "")
set(Boost_NO_SYSTEM_PATHS ON CACHE BOOL "")
add_library(boost INTERFACE)
add_library(Boost::boost ALIAS boost)
target_include_directories(boost SYSTEM INTERFACE ${Boost_INCLUDE_DIR})

add_subdirectory(dynarmic)
Method 2:
Use target_link_libraries in dynarmic/CMakeLists.txt

Another way is to explicitly link dynarmic to boost in dynarmic/CMakeLists.txt:

Code: Select all

target_link_libraries(dynarmic PRIVATE Boost::boost)
Ensure that Boost::boost is defined before this line. This makes sure that dynarmic knows about Boost::boost.



Either method should resolve the issue you're facing. I hope this helps!

Best regards,
MrNordio

MultiplexLayout
Posts: 56
Joined: 2020-09-23 19:21
Has thanked: 7 times

Re: Problem with CMake Generation

#3 Post by MultiplexLayout »

Thank you for responding.

externals/CMakeLists.txt already adds the dynarmic submodule. I'm sorry for not being clearer

Code: Select all

set(DYNARMIC_TESTS OFF CACHE BOOL "")
set(DYNARMIC_FRONTENDS "A32" CACHE STRING "")
set(DYNARMIC_USE_PRECOMPILED_HEADERS ${CITRA_USE_PRECOMPILED_HEADERS} CACHE BOOL "")
add_subdirectory(dynarmic EXCLUDE_FROM_ALL)
I have tried it without the EXCLUDE_FROM_ALL with no effect.

This is what I don't understand. The Boost::boost target should be in scope, but just isn't for some reason. As for method 2, the dynarmic directory is an external submodule, so I don't have any control over it. I'm going to try moving the submodule one directory down and having a new CMakeLists.txt on the level where it used to be.

Post Reply