Skip to content

Conversation

@ItchyTrack
Copy link

@ItchyTrack ItchyTrack commented Aug 21, 2025

Replacing CMAKE_SOURCE_DIR will allow it to be using as a library in other CMake projects

This is because when yosys-slang is included/added as a subdirectory CMAKE_SOURCE_DIR will point to the wrong directory (The top CMakeLists.txt) causing the config to fail.

CMAKE_CURRENT_SOURCE_DIR will point to the directory that the current CMake is in and so should not change functionality when building regularly.

Edit:
Also swapped ${CMAKE_SOURCE_DIR}/cmake" and ${CMAKE_MODULE_PATH} because this allows other libs to override where find_package looks by setting CMAKE_MODULE_PATH.

This should pr should probably have a different name

This is because when using yosys-slang as a library in other CMake projects CMAKE_SOURCE_DIR will point to the wrong directory causing the config to fail. CMAKE_CURRENT_SOURCE_DIR will point to the directory that the current CMake is in.
Did this to allow other libs to override where find_package looks by setting CMAKE_MODULE_PATH
@povik povik requested a review from whitequark August 21, 2025 07:31
@povik
Copy link
Owner

povik commented Aug 21, 2025

Thanks, I'll let @whitequark take a look

@codecov

This comment was marked as off-topic.

@@ -1,4 +1,4 @@
if (CMAKE_BINARY_DIR STREQUAL CMAKE_SOURCE_DIR)
if (CMAKE_BINARY_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't look right to me.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This says that if the CMAKE_BINARY_DIR is the directory of yosys-slang then you cant build. This makes sense because you could have
./top/CMakeLists.txt # user cmake
./top/yosys-slang/CMakeLists.txt # yosys-slang cmake

when in top/yosys-slang/CMakeLists.txt
CMAKE_SOURCE_DIR is set to "./top"
CMAKE_CURRENT_SOURCE_DIR is set to "./top/yosys-slang"

if they set CMAKE_BINARY_DIR to "./top/yosys-slang" and we are comparing CMAKE_SOURCE_DIR then it would allow the build to be "In-tree". Which is not supported according to the fatal error.

Comparing CMAKE_CURRENT_SOURCE_DIR instead the makes the STREQUAL true and calls the FATAL_ERROR stopping the build from being "In-tree".

When CMAKE_SOURCE_DIR is equal to CMAKE_CURRENT_SOURCE_DIR this will have the same behavior as before the change.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should be CMAKE_CURRENT_BINARY_DIR, since we don't support in-tree builds as a subproject either

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, I'll leave the change in.


project(yosys-slang CXX)
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we want the modules to be overridden; this makes accidental name collisions possible where previously they were not

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need it because the default FindYosys.cmake does not work for me. If you think swapping them could break other projects I will remove it from the PR.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it doesn't work for you then that should be fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants