Skip to content

Commit

Permalink
Added versioned install option to cmake install command
Browse files Browse the repository at this point in the history
  • Loading branch information
faressc committed Mar 18, 2024
1 parent 14f213a commit e7ece4f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
14 changes: 13 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,23 @@ project(${PROJECT_NAME} VERSION 0.0.1)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED True)

option(BUILD_TESTS "Build tests" ON)
option(BUILD_TESTS "Build tests" OFF)
option(VERSIONED_INSTALL "Install with version postfix and create symlinks" OFF)

# This disables the default behavior of adding all targets to the CTest dashboard, when adding libraries with the fetchcontent module
set_property(GLOBAL PROPERTY CTEST_TARGETS_ADDED 1)

# Add all source files to file list
file(GLOB_RECURSE SOURCES CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/source/*.cpp ${CMAKE_CURRENT_SOURCE_DIR}/source/*.h)

if (VERSIONED_INSTALL)
set(INSTALL_POSTFIX "-${PROJECT_VERSION}")
else()
set(INSTALL_POSTFIX "")
endif()

message(STATUS "Install postfix: ${INSTALL_POSTFIX}")

# Add excecutables
add_executable(${PROJECT_NAME} ${SOURCES})

Expand Down Expand Up @@ -70,6 +79,9 @@ endif()
# Link all of our libs together
target_link_libraries(${PROJECT_NAME} PUBLIC jack lo yaml-cpp::yaml-cpp)

# Set the output name of the executable
set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME "${PROJECT_NAME}${INSTALL_POSTFIX}")

include(cmake/install.cmake)

# Exclude from all also makes sure that the test libs are not installed
Expand Down
7 changes: 6 additions & 1 deletion cmake/install.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,9 @@ message(STATUS "CMAKE_INSTALL_PREFIX is set to ${CMAKE_INSTALL_PREFIX}")
install(TARGETS ${PROJECT_NAME}
# these get default values from GNUInstallDirs
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
)

# create symlinks for the binary when versioned installation is enabled
if (VERSIONED_INSTALL)
install(CODE "execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/${PROJECT_NAME}${INSTALL_POSTFIX} ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/${PROJECT_NAME})")
endif()

0 comments on commit e7ece4f

Please sign in to comment.