-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow relative paths for ip_sources() and ip_include_directories(), r…
…elative paths are converted to absolute relative to ${CMAKE_CURRENT_SOURCE_DIR} resolve #93
- Loading branch information
Showing
25 changed files
with
232 additions
and
43 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#[[[ | ||
# This function converts relative paths to absolute paths relative to ${CMAKE_CURRENT_SOURCE_DIR} | ||
# It replicates the behaviour of target_sources() CMake Function | ||
# | ||
# :param OUTPUT_LIST: The variable to store the output file list | ||
# :type OUTPUT_LIST: string | ||
# :param ARGN: list of files to convert | ||
# :type ARGN: path | ||
# | ||
#]] | ||
function(convert_paths_to_absolute OUTPUT_LIST) | ||
unset(output_list) | ||
foreach(path ${ARGN}) | ||
cmake_path(ABSOLUTE_PATH path | ||
BASE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} NORMALIZE | ||
OUTPUT_VARIABLE path | ||
) | ||
list(APPEND output_list ${path} ) | ||
endforeach() | ||
|
||
set(${OUTPUT_LIST} ${output_list} PARENT_SCOPE) | ||
endfunction() |
15 changes: 15 additions & 0 deletions
15
...include_directories/ip_include_directories_rel_path/ip_include_directories_rel_path.cmake
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Test relative include directories paths, the behaviour is matching the CMake behaviour of target_include_directories(): | ||
# Changed in version 3.13: Relative source file paths are interpreted as being relative to the current source directory (i.e. CMAKE_CURRENT_SOURCE_DIR). See policy CMP0076. | ||
|
||
include("${CMAKE_CURRENT_LIST_DIR}/../../../../CMakeLists.txt") | ||
set(THIS_DIR ${CMAKE_CURRENT_LIST_DIR}) | ||
|
||
set(TEST_NAME ip_include_directories_rel_path) | ||
ct_add_test(NAME ${TEST_NAME}) | ||
function(${${TEST_NAME}}) | ||
execute_process( | ||
COMMAND cmake -S ${THIS_DIR}/test | ||
-B ${CMAKE_BINARY_DIR}/${TEST_NAME}/build | ||
COMMAND_ERROR_IS_FATAL ANY | ||
) | ||
endfunction() |
31 changes: 31 additions & 0 deletions
31
tests/tests/ip_include_directories/ip_include_directories_rel_path/test/CMakeLists.txt
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Test relative include directories paths, the behaviour is matching the CMake behaviour of target_include_directories(): | ||
# Changed in version 3.13: Relative source file paths are interpreted as being relative to the current source directory (i.e. CMAKE_CURRENT_SOURCE_DIR). See policy CMP0076. | ||
|
||
cmake_minimum_required(VERSION 3.25) | ||
project(ip_include_directories_rel_path NONE) | ||
|
||
include("../../../../../SoCMakeConfig.cmake") | ||
|
||
add_ip(ip) | ||
|
||
set(SV_INCDIRS | ||
. | ||
justdir | ||
) | ||
ip_include_directories(ip SYSTEMVERILOG | ||
${SV_INCDIRS} | ||
) | ||
|
||
add_subdirectory(otherdir) | ||
include(incdir/incdir.cmake_) | ||
|
||
get_ip_include_directories(SV_ABS_INCDIRS ip SYSTEMVERILOG) | ||
|
||
foreach(abspath relpath IN ZIP_LISTS SV_ABS_INCDIRS SV_INCDIRS) | ||
# If there is only . at the end, remove it, otherwise it wont match | ||
string(REGEX REPLACE "\\.$" "" relpath ${relpath}) | ||
if(NOT "${CMAKE_CURRENT_SOURCE_DIR}/${relpath}" PATH_EQUAL ${abspath}) | ||
message(FATAL_ERROR "NOT EQUAL: ${CMAKE_CURRENT_SOURCE_DIR}/${relpath} - ${abspath}") | ||
endif() | ||
|
||
endforeach() |
10 changes: 10 additions & 0 deletions
10
tests/tests/ip_include_directories/ip_include_directories_rel_path/test/incdir/incdir.cmake_
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
list(APPEND SV_INCDIRS | ||
incdir/ | ||
incdir/incdir2 | ||
) | ||
ip_include_directories(ip SYSTEMVERILOG | ||
incdir/ | ||
incdir/incdir2 | ||
) | ||
|
||
set(SV_INCDIRS ${SV_INCDIRS} PARENT_SCOPE) |
10 changes: 10 additions & 0 deletions
10
...tests/ip_include_directories/ip_include_directories_rel_path/test/otherdir/CMakeLists.txt
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
list(APPEND SV_INCDIRS | ||
otherdir/. | ||
otherdir/incdir | ||
) | ||
ip_include_directories(ip SYSTEMVERILOG | ||
. | ||
incdir | ||
) | ||
|
||
set(SV_INCDIRS ${SV_INCDIRS} PARENT_SCOPE) |
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
15 changes: 15 additions & 0 deletions
15
tests/tests/ip_sources/ip_sources_rel_path/ip_sources_rel_path.cmake
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Test relative source file paths, the behaviour is matching the CMake behaviour of target_sources: | ||
# Changed in version 3.13: Relative source file paths are interpreted as being relative to the current source directory (i.e. CMAKE_CURRENT_SOURCE_DIR). See policy CMP0076. | ||
|
||
include("${CMAKE_CURRENT_LIST_DIR}/../../../../CMakeLists.txt") | ||
set(THIS_DIR ${CMAKE_CURRENT_LIST_DIR}) | ||
|
||
set(TEST_NAME ip_sources_rel_path) | ||
ct_add_test(NAME ${TEST_NAME}) | ||
function(${${TEST_NAME}}) | ||
execute_process( | ||
COMMAND cmake -S ${THIS_DIR}/test | ||
-B ${CMAKE_BINARY_DIR}/${TEST_NAME}/build | ||
COMMAND_ERROR_IS_FATAL ANY | ||
) | ||
endfunction() |
Oops, something went wrong.