Re: [PATCH v7 05/17] cmake: optionally build `scalar`, too
From: Matt Rogers <hidden>
Date: 2021-11-17 21:13:03
On Wed, Nov 17, 2021 at 9:49 AM Johannes Schindelin via GitGitGadget [off-list ref] wrote:
From: Johannes Schindelin <redacted> The CMake configuration unfortunately does not let us encapsulate all (or at least the vast majority) of Scalar's build definition in the `contrib/scalar/` subdirectory.
I believe that this isn't fully correct in that you could call add_subdirectory() with a directory that isn't a subdirectory so long as you provide it an explicit binary directory which is part of what we're doing here anyways. (at least it works fine for me with cmake version 3.21)
quoted hunk ↗ jump to hunk
To alleviate that somewhat, we guard the inclusion of Scalar via the `INCLUDE_SCALAR` environment variable. Signed-off-by: Johannes Schindelin <redacted> --- contrib/buildsystems/CMakeLists.txt | 14 ++++++++++++++ 1 file changed, 14 insertions(+)diff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt index fd1399c440f..dd7496b0322 100644 --- a/contrib/buildsystems/CMakeLists.txt +++ b/contrib/buildsystems/CMakeLists.txt@@ -729,6 +729,13 @@ if(CURL_FOUND) endif() endif() +if(DEFINED ENV{INCLUDE_SCALAR} AND NOT ENV{INCLUDE_SCALAR} STREQUAL "") + add_executable(scalar ${CMAKE_SOURCE_DIR}/contrib/scalar/scalar.c) + target_link_libraries(scalar common-main) + set_target_properties(scalar PROPERTIES RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/contrib/scalar) + set_target_properties(scalar PROPERTIES RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/contrib/scalar) +endif()
Would it make sense to just mark this with EXCLUDE_FROM_ALL so that
way you don't have to have
the INCLUDE_SCALAR environment variable just for this? This way
people who don't want
to build scalar can still run `cmake --build .` and not have scalar
built and people who do want
it built can just run `cmake --build . --target scalar`, alternatively
you could also do something like
if(DEFINED ENV{INCLUDE_SCALAR} AND NOT ENV{INCLUDE_SCALAR} STREQUAL "")
add_executable(scalar ${CMAKE_SOURCE_DIR}/contrib/scalar/scalar.c)
else()
add_executable(scalar EXCLUDE_FROM_ALL
${CMAKE_SOURCE_DIR}/contrib/scalar/scalar.c)
endif()
Just some food for thought,
Matthew Rogers