Skip to content

Commit

Permalink
feat: Implement debug postfix handling in CMake and add corresponding…
Browse files Browse the repository at this point in the history
… tests
  • Loading branch information
zchrissirhcz committed Nov 23, 2024
1 parent 6f578a0 commit ba97f7b
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 2 deletions.
24 changes: 24 additions & 0 deletions rocbuild.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -125,5 +125,29 @@ function(rocbuild_copy_opencv_videoio_plugin_dlls target)
endfunction()


function(rocbuild_set_debug_postfix TARGET)
# determine TARGET type
get_target_property(TYPE ${TARGET} TYPE)
if(NOT TYPE)
message(FATAL_ERROR "rocbuild_define_package() called with non-existent target: ${TARGET}")
endif()

# determine if TARGET is imported
get_target_property(IMPORTED ${TARGET} IMPORTED)
if(IMPORTED)
return()
endif()

# Don't treat for single config generators
if(NOT CMAKE_CONFIGURATION_TYPES)
return()
endif()

if(TYPE MATCHES "^(STATIC_LIBRARY|SHARED_LIBRARY|EXECUTABLE)$")
set_target_properties(${TARGET} PROPERTIES DEBUG_POSTFIX "_d")
endif()
endfunction()


rocbuild_set_artifacts_path()
rocbuild_enable_ninja_colorful_output()
53 changes: 52 additions & 1 deletion test.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def test_artifact_path(self):
self.assertTrue(os.path.exists('build/artifacts_path/subhello.exe'))
shutil.rmtree('build/artifacts_path')

self.check_generate('artifacts_path', args='-G "Visual Studio 17 2022" -A x64')
self.check_generate('artifacts_path')
self.check_build('artifacts_path', '--config Release')
self.assertTrue(os.path.exists('build/artifacts_path/Release/foo_static.lib'))
self.assertTrue(os.path.exists('build/artifacts_path/Release/foo_shared.dll'))
Expand Down Expand Up @@ -103,6 +103,57 @@ def test_artifact_path(self):

shutil.rmtree('build/artifacts_path')

def test_debug_postfix(self):
if os_name == 'windows':
# msbuild
self.check_generate('debug_postfix')
self.check_build('debug_postfix', '--config Debug')
self.assertTrue(os.path.exists('build/debug_postfix/Debug/foo_d.lib'))
self.assertTrue(os.path.exists('build/debug_postfix/Debug/hello_d.exe'))
shutil.rmtree('build/debug_postfix')

ret, out = check_output('cl')
if ret == 0:
# ninja
self.check_generate('debug_postfix', args='-G Ninja')
self.check_build('debug_postfix')
self.assertTrue(os.path.exists('build/debug_postfix/foo.lib'))
self.assertTrue(os.path.exists('build/debug_postfix/hello.exe'))
shutil.rmtree('build/debug_postfix')

self.check_generate('debug_postfix', args='-G Ninja -DCMAKE_BUILD_TYPE=Debug')
self.check_build('debug_postfix')
self.assertTrue(os.path.exists('build/debug_postfix/foo.lib'))
self.assertTrue(os.path.exists('build/debug_postfix/hello.exe'))
shutil.rmtree('build/debug_postfix')

# Ninja Multi-Config
self.check_generate('debug_postfix', args='-G "Ninja Multi-Config"')
self.check_build('debug_postfix', '--config Debug')
self.assertTrue(os.path.exists('build/debug_postfix/Debug/foo_d.lib'))
self.assertTrue(os.path.exists('build/debug_postfix/Debug/hello_d.exe'))
shutil.rmtree('build/debug_postfix')
else:
# Ninja Multi-Config
self.check_generate('debug_postfix', args='-G "Ninja Multi-Config"')
self.check_build('debug_postfix')
self.assertTrue(os.path.exists('build/debug_postfix/Debug/libfoo_d.a'))
self.assertTrue(os.path.exists('build/debug_postfix/Debug/hello_d'))
shutil.rmtree('build/debug_postfix')

# make
self.check_generate('debug_postfix')
self.check_build('debug_postfix')
self.assertTrue(os.path.exists('build/debug_postfix/libfoo.a'))
self.assertTrue(os.path.exists('build/debug_postfix/hello'))
shutil.rmtree('build/debug_postfix')

self.check_generate('debug_postfix', args='-DCMAKE_BUILD_TYPE=Debug')
self.check_build('debug_postfix')
self.assertTrue(os.path.exists('build/debug_postfix/libfoo.a'))
self.assertTrue(os.path.exists('build/debug_postfix/hello'))
shutil.rmtree('build/debug_postfix')


if __name__ == "__main__":
unittest.main()
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ project(test_postfix)
include(../../rocbuild.cmake)

add_library(foo STATIC ../src/foo.c)
rocbuild_define_package(foo)
rocbuild_set_debug_postfix(foo)

add_executable(hello ../src/hello.c)
rocbuild_set_debug_postfix(hello)

0 comments on commit ba97f7b

Please sign in to comment.