Skip to content

Commit

Permalink
Refactorizare variabile CMake (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmarius authored Dec 7, 2024
1 parent 84e690d commit 8f72829
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
20 changes: 12 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ cmake_minimum_required(VERSION 3.26)

# NOTE: update executable name in .github/workflows/cmake.yml:25 when changing executable name in this file
# for now, the project name is used as the executable name
project(oop)
set(MAIN_PROJECT_NAME "oop")
set(MAIN_EXECUTABLE_NAME "${MAIN_PROJECT_NAME}")


project(${MAIN_PROJECT_NAME})
# set(CMAKE_PROJECT_VERSION_MAJOR 0)
# set(CMAKE_PROJECT_VERSION_MINOR 0)
# set(CMAKE_PROJECT_VERSION_PATCH 1)
Expand Down Expand Up @@ -42,7 +46,7 @@ include(cmake/Options.cmake)
###############################################################################

# NOTE: update executable name in .github/workflows/cmake.yml:25 when changing name here
add_executable(${PROJECT_NAME}
add_executable(${MAIN_EXECUTABLE_NAME}
main.cpp
generated/src/Helper.cpp
)
Expand All @@ -52,17 +56,17 @@ include(cmake/CompilerFlags.cmake)
###############################################################################

# use SYSTEM so cppcheck and clang-tidy do not report warnings from these directories
target_include_directories(${PROJECT_NAME} SYSTEM PRIVATE generated/include)
# target_include_directories(${PROJECT_NAME} SYSTEM PRIVATE ext/<SomeHppLib>/include)
# target_include_directories(${PROJECT_NAME} SYSTEM PRIVATE ${<SomeLib>_SOURCE_DIR}/include)
# target_link_directories(${PROJECT_NAME} PRIVATE ${<SomeLib>_BINARY_DIR}/lib)
# target_link_libraries(${PROJECT_NAME} <SomeLib>)
target_include_directories(${MAIN_EXECUTABLE_NAME} SYSTEM PRIVATE generated/include)
# target_include_directories(${MAIN_EXECUTABLE_NAME} SYSTEM PRIVATE ext/<SomeHppLib>/include)
# target_include_directories(${MAIN_EXECUTABLE_NAME} SYSTEM PRIVATE ${<SomeLib>_SOURCE_DIR}/include)
# target_link_directories(${MAIN_EXECUTABLE_NAME} PRIVATE ${<SomeLib>_BINARY_DIR}/lib)
# target_link_libraries(${MAIN_EXECUTABLE_NAME} <SomeLib>)

###############################################################################

# copy binaries to "bin" folder; these are uploaded as artifacts on each release
# DESTINATION_DIR is set as "bin" in cmake/Options.cmake:6
install(TARGETS ${PROJECT_NAME} DESTINATION ${DESTINATION_DIR})
install(TARGETS ${MAIN_EXECUTABLE_NAME} DESTINATION ${DESTINATION_DIR})
if(APPLE)
install(FILES launcher.command DESTINATION ${DESTINATION_DIR})
endif()
Expand Down
10 changes: 5 additions & 5 deletions cmake/CompilerFlags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,26 @@

if(GITHUB_ACTIONS)
message("NOTE: GITHUB_ACTIONS defined")
target_compile_definitions(${PROJECT_NAME} PRIVATE GITHUB_ACTIONS)
target_compile_definitions(${MAIN_EXECUTABLE_NAME} PRIVATE GITHUB_ACTIONS)
endif()

###############################################################################

if(PROJECT_WARNINGS_AS_ERRORS)
set_property(TARGET ${PROJECT_NAME} PROPERTY COMPILE_WARNING_AS_ERROR ON)
set_property(TARGET ${MAIN_EXECUTABLE_NAME} PROPERTY COMPILE_WARNING_AS_ERROR ON)
endif()

# custom compiler flags
message("Compiler: ${CMAKE_CXX_COMPILER_ID} version ${CMAKE_CXX_COMPILER_VERSION}")
if(MSVC)
target_compile_options(${PROJECT_NAME} PRIVATE /W4 /permissive- /wd4244 /wd4267 /wd4996 /external:anglebrackets /external:W0 /utf-8 /MP)
target_compile_options(${MAIN_EXECUTABLE_NAME} PRIVATE /W4 /permissive- /wd4244 /wd4267 /wd4996 /external:anglebrackets /external:W0 /utf-8 /MP)
else()
target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra -pedantic)
target_compile_options(${MAIN_EXECUTABLE_NAME} PRIVATE -Wall -Wextra -pedantic)
endif()

###############################################################################

# sanitizers
include(cmake/CustomStdlibAndSanitizers.cmake)

set_custom_stdlib_and_sanitizers(${PROJECT_NAME} true)
set_custom_stdlib_and_sanitizers(${MAIN_EXECUTABLE_NAME} true)
8 changes: 4 additions & 4 deletions cmake/CopyHelper.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ function(copy_files)
# copy files to build dir
foreach(file ${ARG_FILES})
add_custom_command(
TARGET ${PROJECT_NAME} POST_BUILD
TARGET ${MAIN_EXECUTABLE_NAME} POST_BUILD
COMMENT "Copying ${file}..."
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${CMAKE_SOURCE_DIR}/${file} $<TARGET_FILE_DIR:${PROJECT_NAME}>)
${CMAKE_SOURCE_DIR}/${file} $<TARGET_FILE_DIR:${MAIN_EXECUTABLE_NAME}>)
# ${CMAKE_CURRENT_BINARY_DIR})
endforeach()

# copy folders to build dir
foreach(dir ${ARG_DIRECTORY})
add_custom_command(
TARGET ${PROJECT_NAME} POST_BUILD
TARGET ${MAIN_EXECUTABLE_NAME} POST_BUILD
COMMENT "Copying directory ${dir}..."
COMMAND ${CMAKE_COMMAND} -E copy_directory_if_different
${CMAKE_SOURCE_DIR}/${dir} $<TARGET_FILE_DIR:${PROJECT_NAME}>/${dir})
${CMAKE_SOURCE_DIR}/${dir} $<TARGET_FILE_DIR:${MAIN_EXECUTABLE_NAME}>/${dir})
# ${CMAKE_CURRENT_BINARY_DIR}/${dir})
endforeach()

Expand Down

0 comments on commit 8f72829

Please sign in to comment.