Skip to content

Commit 425673a

Browse files
committed
cmake: optionally build scalar, too
Unlike the `Makefile`-based build, the CMake configuration unfortunately does not let us easily encapsulate Scalar's build definition in the `contrib/scalar/` subdirectory: The `scalar` executable needs to link in `libgit.a` and `common-main.o`, for example. Also, `scalar.c` includes Git's header files, which means that `scalar.c` needs to be compiled with the very same flags as `libgit.a` lest `scalar.o` and `libgit.a` have different ideas of, say, `platform_SHA_CTX`, which would naturally lead to memory corruption, crashes and quite tricky debugging (talking from experience). To alleviate that lack of encapsulation somewhat, we guard the Scalar parts in `CMakeLists.txt` via the `INCLUDE_SCALAR` environment variable. This not only allows the CMake-based build to exclude Scalar by default, but also gives better visual cues as to which sections are related to Scalar. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent 6b74337 commit 425673a

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

contrib/buildsystems/CMakeLists.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -810,6 +810,13 @@ if(CURL_FOUND)
810810
endif()
811811
endif()
812812

813+
if(DEFINED ENV{INCLUDE_SCALAR} AND NOT ENV{INCLUDE_SCALAR} STREQUAL "")
814+
add_executable(scalar ${CMAKE_SOURCE_DIR}/contrib/scalar/scalar.c)
815+
target_link_libraries(scalar common-main)
816+
set_target_properties(scalar PROPERTIES RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/contrib/scalar)
817+
set_target_properties(scalar PROPERTIES RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/contrib/scalar)
818+
endif()
819+
813820
parse_makefile_for_executables(git_builtin_extra "BUILT_INS")
814821

815822
option(SKIP_DASHED_BUILT_INS "Skip hardlinking the dashed versions of the built-ins")
@@ -1037,6 +1044,13 @@ string(REPLACE "@@BUILD_DIR@@" "${CMAKE_BINARY_DIR}" content "${content}")
10371044
string(REPLACE "@@PROG@@" "git-cvsserver" content "${content}")
10381045
file(WRITE ${CMAKE_BINARY_DIR}/bin-wrappers/git-cvsserver ${content})
10391046

1047+
if(DEFINED ENV{INCLUDE_SCALAR} AND NOT ENV{INCLUDE_SCALAR} STREQUAL "")
1048+
file(STRINGS ${CMAKE_SOURCE_DIR}/wrap-for-bin.sh content NEWLINE_CONSUME)
1049+
string(REPLACE "@@BUILD_DIR@@" "${CMAKE_BINARY_DIR}" content "${content}")
1050+
string(REPLACE "@@PROG@@" "contrib/scalar/scalar${EXE_EXTENSION}" content "${content}")
1051+
file(WRITE ${CMAKE_BINARY_DIR}/bin-wrappers/scalar ${content})
1052+
endif()
1053+
10401054
#options for configuring test options
10411055
option(PERL_TESTS "Perform tests that use perl" ON)
10421056
option(PYTHON_TESTS "Perform tests that use python" ON)

0 commit comments

Comments
 (0)