Skip to content

Commit

Permalink
Overwrite gtests property specific output dirs
Browse files Browse the repository at this point in the history
  • Loading branch information
ptheywood committed Sep 21, 2021
1 parent 1173aee commit 6989add
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
3 changes: 3 additions & 0 deletions cmake/dependencies/googletest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@ if(NOT googletest_POPULATED)
CMAKE_SET_TARGET_FOLDER("gtest" "Tests/Dependencies")
# Suppress warnigns from this target.
include(${CMAKE_CURRENT_LIST_DIR}/../warnings.cmake)
# Set output directories
include(${CMAKE_CURRENT_LIST_DIR}/../set_output_directories.cmake)
if(TARGET gtest)
DisableCompilerWarnings(TARGET gtest)
OverwriteOutputDirectoryProperties(TARGET gtest)
endif()
endif()

33 changes: 32 additions & 1 deletion cmake/set_output_directories.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Set the locations of ARCHIVE (.lib/.a), LIBRARY (MODULE .dll/.so, SHARED.so) and BINARY (.dll,.exe/binary)
# Set CMake variables which influence the location of otuput artifacts such as executables, .so, .dll, .lib files.
# Do this by controlling the default variables, and also providing a function to reset per-target properties to the current global variables.

# Only set these if they have not already been set.
# Set them to be relative to the Project Source directory, i.e. the location of the first call to CMake
Expand All @@ -12,3 +13,33 @@ endif()
if(NOT CMAKE_RUNTIME_OUTPUT_DIRECTORY)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/$<CONFIG>)
endif()
if(NOT CMAKE_PDB_OUTPUT_DIRECTORY)
set(CMAKE_PDB_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/$<CONFIG>)
endif()

# Provide a target specific method to overwrite the values set on a target to the current values of the global CMAKE variables.
# This is to overwrite per target setting such as in gtest when using add_subdirectory.
function(OverwriteOutputDirectoryProperties)
# Parse the expected arguments, prefixing variables.
cmake_parse_arguments(
OODP
""
"TARGET"
""
${ARGN}
)
# Ensure that a target has been passed, and that it is a valid target.
if(NOT OODP_TARGET)
message( FATAL_ERROR "OverwriteOutputDirectoryProperties: 'TARGET' argument required." )
elseif(NOT TARGET ${OODP_TARGET} )
message( FATAL_ERROR "OverwriteOutputDirectoryProperties: TARGET '${OVERWRITE_OUTPUT_DIRECTORY_PROPERTIES_TARGET}' is not a valid target" )
endif()
# Set the various target properties to current cmake global variable
set_target_properties(${OODP_TARGET}
PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}"
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}"
PDB_OUTPUT_DIRECTORY "${CMAKE_PDB_OUTPUT_DIRECTORY}"
)
endfunction()

0 comments on commit 6989add

Please sign in to comment.