Skip to content

Commit

Permalink
feat(cxx): simplify the output config using generator expression
Browse files Browse the repository at this point in the history
  • Loading branch information
pplmx committed Sep 12, 2024
1 parent 4a0b7d4 commit ffb2ea3
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions template/cxx/{{cookiecutter.project_slug}}/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,20 @@ endif()

# ===================== Output Directories =====================

# Set output directories
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)

# Ensure output directories are set for all configurations
foreach(OUTPUT_CONFIG ${CMAKE_CONFIGURATION_TYPES})
string(TOUPPER ${OUTPUT_CONFIG} OUTPUT_CONFIG)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_${OUTPUT_CONFIG} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_${OUTPUT_CONFIG} ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${OUTPUT_CONFIG} ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY})
endforeach()
# Use generator expressions for output directories
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "$<1:${CMAKE_BINARY_DIR}/bin>")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "$<1:${CMAKE_BINARY_DIR}/lib>")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "$<1:${CMAKE_BINARY_DIR}/lib>")

# ===================== Source Files =====================

# Collect source files
file(GLOB_RECURSE SOURCES
file(GLOB_RECURSE SOURCES CONFIGURE_DEPENDS
${CMAKE_SOURCE_DIR}/src/*.cpp
)
file(GLOB_RECURSE HEADERS ${CMAKE_SOURCE_DIR}/include/*.h)
file(GLOB_RECURSE HEADERS CONFIGURE_DEPENDS
${CMAKE_SOURCE_DIR}/include/*.h
)

# ===================== Library Target =====================

Expand Down

0 comments on commit ffb2ea3

Please sign in to comment.