Fix incorrect CMAKE_SOURCE_DIR usage

When using solidity as a third-party library (include it into our
project using FetchContent), we encountered a strange compilation error.
For some reason, cmake considers the root directory of the project as
the root directory of the dependency (solidity). This is because
solidity is incorrectly using CMAKE_SOURCE_DIR variable, which should be
PROJECT_SOURCE_DIR (The former one refers to the top-level source
directory that contains a CMakeLists.txt, while the latter refers to the
source directory of the most recent project() command)

I've created a repo for demonstration (https://github.com/junaire/test-solidity-fetch-content)

Signed-off-by: Jun Zhang <jun@junz.org>
This commit is contained in:
Jun Zhang
2023-06-08 19:17:34 +08:00
parent facc38097d
commit 74a38fc3d8
7 changed files with 12 additions and 12 deletions
+1 -1
View File
@@ -46,7 +46,7 @@ set(sources
add_library(solutil ${sources})
target_link_libraries(solutil PUBLIC jsoncpp Boost::boost Boost::filesystem Boost::system range-v3 fmt::fmt-header-only)
target_include_directories(solutil PUBLIC "${CMAKE_SOURCE_DIR}")
target_include_directories(solutil PUBLIC "${PROJECT_SOURCE_DIR}")
add_dependencies(solutil solidity_BuildInfo.h)
if(SOLC_LINK_STATIC)