cmake: FetchContent/add_subdirectory compatibility improvements#170
cmake: FetchContent/add_subdirectory compatibility improvements#170hn-sl wants to merge 6 commits intointel:masterfrom
Conversation
|
@hn-sl Thanks for this PR. Could you sign off the commit? Thanks! |
Replace CMAKE_SOURCE_DIR with CMAKE_CURRENT_SOURCE_DIR throughout CMake configuration files to enable proper path resolution when the project is consumed via FetchContent or add_subdirectory(). When used as a subdirectory, CMAKE_SOURCE_DIR points to the parent project's root, causing incorrect path resolution for include directories, configure_file inputs, and other paths. Signed-off-by: hsshin <hsshinmail@gmail.com>
Updated PR ScopeThis PR now includes two changes for FetchContent/add_subdirectory compatibility: 1. CMAKE_CURRENT_SOURCE_DIR fix (original)Replaces CMAKE_SOURCE_DIR with CMAKE_CURRENT_SOURCE_DIR for correct path resolution. 2. Header restructuring (new commit)Moves headers to // Now works for both FetchContent and installed usage
#include <isa-l_crypto/md5_mb.h>Verified:
Resolves: #171 |
3e011ce to
85b676c
Compare
This enables users to include headers with the standard pattern: #include <isa-l_crypto/md5_mb.h> Changes: - Move all public headers from include/ to include/isa-l_crypto/ - Update CMakeLists.txt and cmake modules for new header paths - Add include/isa-l_crypto to private include paths for internal builds Resolves: intel#171 Signed-off-by: hsshin <hsshinmail@gmail.com>
|
Thanks for these updates. I am thinking that include/isa-l_crypto / should only include header files with public API, which are: Could you move the rest outside include/isa-l_crypto/ ? Thanks! |
|
Thanks for the feedback! I analyzed the header dependencies: Headers included by public API headers (must stay in
Headers used only by source files (.c): Single module usage (can move to that module directory):
Multiple module usage (need shared location):
Proposed structure:
Does this approach work for you? |
Makes sense, thanks for looking into it! |
- Move multi-module internal headers to internal/ - Move single-module internal headers to their module directories (md5_mb_internal.h -> md5_mb/, sm3_mb_internal.h -> sm3_mb/) - Update CMake, Autotools, and Makefile.unx build systems - Keep only public API headers in include/isa-l_crypto/ - Remove internal headers from umbrella header isa-l_crypto.h Signed-off-by: hsshin <hsshinmail@gmail.com>
|
Windows build is failing because internal/ is not in part of INCLUDES in Makefile.nmake. Anyway, I think this internal folder can be moved inside "include/". Also, I think for consistency, we should move sm3_mb_internal.h and sha512_mb_internal.h inside the internal/ folder. And, is it necessary the Makefile.am file inside internal/? |
- Move internal/ to include/internal/ - Move md5_mb_internal.h and sm3_mb_internal.h to include/internal/ - Add include/internal/ to Makefile.nmake INCLUDES (fixes Windows build) - Remove internal/Makefile.am (not needed) - Update all build systems (CMake, Autotools, make.inc) Signed-off-by: hsshin <hsshinmail@gmail.com>
|
Addressed feedback:
|
|
Thanks for the update. I'm getting some warnings when compiling on aarch64 on our internal CI. mh_sha1/aarch64/mh_sha1_aarch64_dispatcher.c: In function '_mh_sha1_update_dispatcher': |
The header move in commit f6d2306 introduced formatting changes that broke GCC pragma warning options: - "-W"#x became "-W" #x (space breaks string concatenation) - -Wnested-externs became -Wnested - externs (invalid warning option) This caused compiler warnings on aarch64 builds. Added clang-format off/on comments to protect these pragma macros from being reformatted by clang-format. Signed-off-by: hsshin <hsshinmail@gmail.com>
|
Fixed the aarch64 pragma warning. The issue was that clang-format reformatted Added |
pablodelara
left a comment
There was a problem hiding this comment.
A few comments, thanks for the work!
| DIGNOSTIC_POP() \ | ||
| _func_entry; \ | ||
| }) | ||
| /* clang-format on */ |
There was a problem hiding this comment.
Better to leave the files as they were and change the path of aarch64_multibinary.h and riscv64_multibinary.h in .clang-format-ignore to the new path.
aes/Makefile.am
Outdated
| src_include += -I $(srcdir)/intel-ipsec-mb/lib | ||
|
|
||
| extern_hdrs += include/aes_gcm.h include/aes_cbc.h include/aes_xts.h include/aes_keyexp.h include/isal_crypto_api.h | ||
| extern_hdrs += include/isa-l_crypto/aes_keyexp.h include/isa-l_crypto/isal_crypto_api.h |
There was a problem hiding this comment.
Any reason to remove these extra header files?
fips/Makefile.am
Outdated
|
|
||
| src_include += -I $(srcdir)/fips | ||
| extern_hdrs += include/isal_crypto_api.h include/aes_xts.h include/aes_keyexp.h include/sha1_mb.h include/sha256_mb.h | ||
| extern_hdrs += include/isa-l_crypto/sha256_mb.h |
There was a problem hiding this comment.
Any reason to remove these extra header files?
- Use .clang-format-ignore instead of clang-format off guards for multibinary headers - Restore accidentally dropped headers in other_src sections across all module Makefile.am files (memcpy_inline.h, intrinreg.h, test.h, aes_keyexp_internal.h, aes_cbc_internal.h) - Update header paths to reflect new directory structure (include/isa-l_crypto/ for public, include/internal/ for internal) - Fix isa-l_crypto.h generation to avoid duplicate path prefix (was generating isa-l_crypto/isa-l_crypto/xxx.h instead of isa-l_crypto/xxx.h) Signed-off-by: hsshin <hsshinmail@gmail.com>
|
Addressed the review feedback:
Regarding the dropped headers - there was no specific reason. They were accidentally removed during the header path reorganization. Sorry for the oversight. Also fixed a bug in Makefile.am where the generated All tests pass (autotools + cmake). |
|
@hn-sl overall it looks mainly ok except for the isa-l_crypto.h. It currently shows a wrong path when compiling with CMake and Makefile.unx. I'm leaving some comments to fix it. |
| # Generate isa-l_crypto.h header | ||
| set(ISAL_CRYPTO_HEADER "${CMAKE_BINARY_DIR}/isa-l_crypto.h") | ||
| configure_file(${CMAKE_SOURCE_DIR}/cmake/isa-l_crypto.h.in ${ISAL_CRYPTO_HEADER} @ONLY) | ||
| configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/isa-l_crypto.h.in ${ISAL_CRYPTO_HEADER} @ONLY) |
There was a problem hiding this comment.
Adding the following lines fix the path problem
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -249,6 +249,14 @@ target_include_directories(isal_crypto
# Generate isa-l_crypto.h header
set(ISAL_CRYPTO_HEADER "${CMAKE_BINARY_DIR}/isa-l_crypto.h")
+list(REMOVE_DUPLICATES EXTERN_HEADERS)
+list(SORT EXTERN_HEADERS)
+set(ISAL_CRYPTO_INCLUDES "")
+foreach(HEADER ${EXTERN_HEADERS})
+ string(REPLACE "include/" "" HEADER_PATH ${HEADER})
+ string(APPEND ISAL_CRYPTO_INCLUDES "#include <${HEADER_PATH}>\n")
+endforeach()
+
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/isa-l_crypto.h.in ${ISAL_CRYPTO_HEADER} @ONLY)
| #include <isa-l_crypto/test.h> | ||
| #include <isa-l_crypto/types.h> | ||
| #include <isa-l_crypto/endian_helper.h> | ||
|
|
There was a problem hiding this comment.
All these includes could be replaced by:
+@ISAL_CRYPTO_INCLUDES@
| @echo '#ifndef _ISAL_CRYPTO_H_' >> $@ | ||
| @echo '#define _ISAL_CRYPTO_H_' >> $@ | ||
| @echo '' >> $@ | ||
| @for unit in $(sort $(extern_hdrs)); do echo "#include <isa-l_crypto/$$unit>" | sed -e 's;include/;;' >> $@; done |
There was a problem hiding this comment.
This should fix the path:
--- a/make.inc
+++ b/make.inc
@@ -288,7 +288,7 @@ isa-l_crypto.h:
@echo '#ifndef ISAL_CRYPTO_H' >> $@
@echo '#define ISAL_CRYPTO_H' >> $@
@echo '' >> $@
-
@for unit in $(sort $(extern_hdrs)); do echo "#include <isa-l_crypto/$$unit>" | sed -e 's;include/;;' >> $@; done
-
@for unit in $(sort $(extern_hdrs)); do echo "#include <$$unit>" | sed -e 's;include/;;' >> $@; done
|
@hn-sl I can also make these changes myself, if you are OK with it. I will also condense the commits to 2 or 3. |
|
Sure, that would be great. Thanks! |
|
This is now merged, thanks for the work! |
Summary
This PR replaces
CMAKE_SOURCE_DIRwithCMAKE_CURRENT_SOURCE_DIRthroughout CMake configuration files to enable proper path resolution when the project is consumed viaFetchContentoradd_subdirectory().Problem
When isa-l_crypto is used as a subdirectory (via FetchContent or add_subdirectory),
CMAKE_SOURCE_DIRpoints to the parent project's root, not isa-l_crypto's source directory. This causes incorrect path resolution for:configure_file()inputsExample Error (FetchContent)
Solution
Replace all occurrences of
CMAKE_SOURCE_DIRwithCMAKE_CURRENT_SOURCE_DIR, which always refers to the directory containing the current CMakeLists.txt.Files Changed
CMakeLists.txtcmake/*.cmake(all module files)Testing
Verified that the project builds successfully when consumed via:
FetchContent_MakeAvailable()add_subdirectory()