janbar / openssl-cmake

Build OpenSSL with CMake on MacOS, Win32, Win64 and cross compile for Android, IOS
Other
277 stars 144 forks source link

Is it possible to use target_include_directories instead of include_directories? #8

Closed adepierre closed 4 years ago

adepierre commented 5 years ago

Hi!

Thanks for this project which is quite useful.

Would it be possible to use target_include_directories to link the include folders to the targets? Like that the include directories are automatically linked to any target having ssl and/or crypto as dependency instead of having to set them manually.

janbar commented 5 years ago

Sure. I will try that.

janbar commented 4 years ago

mmm, I don't set any "include_directories" for the project. Currently to setup your target you have to do near the same is done by "find_package(OpenSSL)".

project(MyTarget)
...
# Init submodule openssl (https://github.com/janbar/openssl-cmake.git)
execute_process (COMMAND git submodule update --init --depth 1 -- openssl WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
add_subdirectory(
    ${CMAKE_CURRENT_SOURCE_DIR}/openssl
    ${CMAKE_CURRENT_BINARY_DIR}/openssl
    EXCLUDE_FROM_ALL
)
set(OPENSSL_INCLUDE_DIR "${openssl_BINARY_DIR}/include" "${openssl_BINARY_DIR}")
include_directories(${OPENSSL_INCLUDE_DIR})
...
target_link_libraries(MyTarget crypto ssl)

Do you need I add the following ?

target_include_directories("${OPENSSL_BINARY_DIR}/include" "${OPENSSL_BINARY_DIR}")
adepierre commented 4 years ago

Yes, if you use target_include_directories on crypto and ssl instead of include_directories the setup of a custom target would be simplified to:

project(MyTarget)
...
# Init submodule openssl (https://github.com/janbar/openssl-cmake.git)
execute_process (COMMAND git submodule update --init --depth 1 -- openssl WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
add_subdirectory(
    ${CMAKE_CURRENT_SOURCE_DIR}/openssl
    ${CMAKE_CURRENT_BINARY_DIR}/openssl
    EXCLUDE_FROM_ALL
)
...
target_link_libraries(MyTarget crypto ssl)

as include directories would be automatically linked.

janbar commented 4 years ago

I made a commit to manage this. Can you test it please ?

adepierre commented 4 years ago

It seems to be working like a charm, thank you!