forked from ethereum/solidity
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <[email protected]>
- Loading branch information
Showing
7 changed files
with
12 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
# This will re-generate the headers if any file within src was modified. | ||
set_directory_properties(PROPERTY CMAKE_CONFIGURE_DEPENDS ${CMAKE_SOURCE_DIR}/stdlib/src/) | ||
set_directory_properties(PROPERTY CMAKE_CONFIGURE_DEPENDS ${PROJECT_SOURCE_DIR}/stdlib/src/) | ||
|
||
set(STDLIB stub) | ||
set(GENERATED_STDLIB_HEADERS) | ||
foreach(src IN LISTS STDLIB) | ||
set(STDLIB_FILE ${CMAKE_SOURCE_DIR}/libstdlib/src/${src}.sol) | ||
set(STDLIB_FILE ${PROJECT_SOURCE_DIR}/libstdlib/src/${src}.sol) | ||
file(READ ${STDLIB_FILE} STDLIB_FILE_CONTENT HEX) | ||
string(REGEX MATCHALL ".." STDLIB_FILE_CONTENT "${STDLIB_FILE_CONTENT}") | ||
list(REMOVE_ITEM STDLIB_FILE_CONTENT "0d") | ||
string(REGEX REPLACE ";" ",\n\t0x" STDLIB_FILE_CONTENT "${STDLIB_FILE_CONTENT}") | ||
set(STDLIB_FILE_CONTENT "0x${STDLIB_FILE_CONTENT}") | ||
set(STDLIB_FILE_NAME ${src}) | ||
configure_file("${CMAKE_SOURCE_DIR}/libstdlib/stdlib.src.h.in" ${CMAKE_BINARY_DIR}/include/libstdlib/${src}.h NEWLINE_STYLE LF @ONLY) | ||
configure_file("${PROJECT_SOURCE_DIR}/libstdlib/stdlib.src.h.in" ${CMAKE_BINARY_DIR}/include/libstdlib/${src}.h NEWLINE_STYLE LF @ONLY) | ||
list(APPEND GENERATED_STDLIB_HEADERS ${CMAKE_BINARY_DIR}/include/libstdlib/${src}.h) | ||
endforeach() | ||
|
||
configure_file("${CMAKE_SOURCE_DIR}/libstdlib/stdlib.h.in" ${CMAKE_BINARY_DIR}/include/libstdlib/stdlib.h NEWLINE_STYLE LF @ONLY) | ||
configure_file("${PROJECT_SOURCE_DIR}/libstdlib/stdlib.h.in" ${CMAKE_BINARY_DIR}/include/libstdlib/stdlib.h NEWLINE_STYLE LF @ONLY) |