From 00b0d95058c274cddbc3d5853db193f5edf842c3 Mon Sep 17 00:00:00 2001 From: manuelk Date: Fri, 3 Jan 2014 13:39:48 -0800 Subject: [PATCH] Remove CMake compiling redundancies - set OBJECT targets for osd cpu & gpu libs, and use the obj target for static and dynamic linking - add a new examples_common_obj OBJECT target - replace direct source dependencies to obj target in all examples CMakeLists This change makes it possible to not re-compile the same source files multiple times when they are used in multiple targets. Thanks to jcowles for uncovering the CMake functionality. Note: it seems that multi-process build is working again (gmake -j ) --- examples/CMakeLists.txt | 14 +++++++-- examples/dxPtexViewer/CMakeLists.txt | 4 +-- examples/dxViewer/CMakeLists.txt | 4 +-- examples/glBatchViewer/CMakeLists.txt | 5 +--- examples/glStencilViewer/CMakeLists.txt | 4 +-- examples/glViewer/CMakeLists.txt | 5 +--- examples/limitEval/CMakeLists.txt | 4 +-- examples/paintTest/CMakeLists.txt | 4 +-- examples/ptexViewer/CMakeLists.txt | 12 +++----- examples/uvViewer/CMakeLists.txt | 4 +-- opensubdiv/osd/CMakeLists.txt | 38 ++++++++++++++----------- 11 files changed, 45 insertions(+), 53 deletions(-) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index afbc20ad..a593385a 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -23,23 +23,31 @@ # if( OPENGL_FOUND AND (GLEW_FOUND AND GLFW_FOUND) OR (APPLE AND GLFW_FOUND)) + + add_subdirectory(common) + add_subdirectory(glViewer) add_subdirectory(glBatchViewer) add_subdirectory(glStencilViewer) add_subdirectory(simpleCpu) add_subdirectory(limitEval) add_subdirectory(tessellateObjFile) + if (NOT APPLE) add_subdirectory(uvViewer) endif() + if(OPENGL_4_3_FOUND AND (NOT APPLE)) # the paintTest example requires GL functionality not available on OSX add_subdirectory(paintTest) endif() + if(PTEX_FOUND) add_subdirectory(ptexViewer) endif() + else() + set(MISSING "") if (NOT OPENGL_FOUND) @@ -70,6 +78,7 @@ if(DXSDK_FOUND) if(PTEX_FOUND) add_subdirectory(dxPtexViewer) endif() + endif() @@ -79,8 +88,7 @@ if(MAYA_FOUND) # manuelk: the following plugins are disabled until further notice #add_subdirectory(mayaViewer) - - if(PTEX_FOUND) + #if(PTEX_FOUND) #add_subdirectory(mayaPtexViewer) - endif() + #endif() endif() diff --git a/examples/dxPtexViewer/CMakeLists.txt b/examples/dxPtexViewer/CMakeLists.txt index 85441418..5275f2d0 100644 --- a/examples/dxPtexViewer/CMakeLists.txt +++ b/examples/dxPtexViewer/CMakeLists.txt @@ -42,9 +42,6 @@ include_directories( ) set(SOURCE_FILES - ../common/font_image.cpp - ../common/hud.cpp - ../common/d3d11_hud.cpp dxPtexViewer.cpp ) @@ -74,6 +71,7 @@ _add_possibly_cuda_executable(dxPtexViewer WIN32 ${SOURCE_FILES} ${SHADER_FILES} ${INC_FILES} + $ ) target_link_libraries(dxPtexViewer diff --git a/examples/dxViewer/CMakeLists.txt b/examples/dxViewer/CMakeLists.txt index 46215d97..e9b965a1 100644 --- a/examples/dxViewer/CMakeLists.txt +++ b/examples/dxViewer/CMakeLists.txt @@ -40,9 +40,6 @@ include_directories( ) set(SOURCE_FILES - ../common/font_image.cpp - ../common/hud.cpp - ../common/d3d11_hud.cpp dxViewer.cpp ) @@ -72,6 +69,7 @@ _add_possibly_cuda_executable(dxViewer WIN32 ${SOURCE_FILES} ${SHADER_FILES} ${INC_FILES} + $ ) target_link_libraries(dxViewer diff --git a/examples/glBatchViewer/CMakeLists.txt b/examples/glBatchViewer/CMakeLists.txt index 9a34a838..ff52b2ec 100644 --- a/examples/glBatchViewer/CMakeLists.txt +++ b/examples/glBatchViewer/CMakeLists.txt @@ -73,12 +73,9 @@ _add_glfw_executable(glBatchViewer delegate.cpp effect.cpp effectRegistry.cpp - ../common/font_image.cpp - ../common/hud.cpp - ../common/patchColors.cpp - ../common/gl_hud.cpp ${SHADER_FILES} ${INC_FILES} + $ ) target_link_libraries(glBatchViewer diff --git a/examples/glStencilViewer/CMakeLists.txt b/examples/glStencilViewer/CMakeLists.txt index 6e87d490..939ee424 100644 --- a/examples/glStencilViewer/CMakeLists.txt +++ b/examples/glStencilViewer/CMakeLists.txt @@ -42,10 +42,8 @@ endif() _add_glfw_executable(glStencilViewer main.cpp - ../common/font_image.cpp - ../common/hud.cpp - ../common/gl_hud.cpp ${INC_FILES} + $ ) target_link_libraries(glStencilViewer diff --git a/examples/glViewer/CMakeLists.txt b/examples/glViewer/CMakeLists.txt index 70054e64..7d55d1ec 100644 --- a/examples/glViewer/CMakeLists.txt +++ b/examples/glViewer/CMakeLists.txt @@ -70,12 +70,9 @@ endforeach() _add_glfw_executable(glViewer viewer.cpp - ../common/font_image.cpp - ../common/hud.cpp - ../common/gl_hud.cpp - ../common/patchColors.cpp ${SHADER_FILES} ${INC_FILES} + $ ) target_link_libraries(glViewer diff --git a/examples/limitEval/CMakeLists.txt b/examples/limitEval/CMakeLists.txt index d80d0b6b..0379e15e 100644 --- a/examples/limitEval/CMakeLists.txt +++ b/examples/limitEval/CMakeLists.txt @@ -42,10 +42,8 @@ endif() _add_glfw_executable(limitEval main.cpp - ../common/font_image.cpp - ../common/hud.cpp - ../common/gl_hud.cpp ${INC_FILES} + $ ) target_link_libraries(limitEval diff --git a/examples/paintTest/CMakeLists.txt b/examples/paintTest/CMakeLists.txt index ac2bbf66..1b45b3c6 100644 --- a/examples/paintTest/CMakeLists.txt +++ b/examples/paintTest/CMakeLists.txt @@ -67,11 +67,9 @@ endforeach() _add_glfw_executable(paintTest main.cpp - ../common/font_image.cpp - ../common/hud.cpp - ../common/gl_hud.cpp ${SHADER_FILES} ${INC_FILES} + $ ) target_link_libraries(paintTest diff --git a/examples/ptexViewer/CMakeLists.txt b/examples/ptexViewer/CMakeLists.txt index 4ec36b9a..400512ce 100644 --- a/examples/ptexViewer/CMakeLists.txt +++ b/examples/ptexViewer/CMakeLists.txt @@ -78,14 +78,10 @@ endforeach() #------------------------------------------------------------------------------- _add_glfw_executable(ptexViewer - viewer.cpp - ../common/font_image.cpp - ../common/hud.cpp - ../common/patchColors.cpp - ../common/gl_hud.cpp - ../common/hdr_reader.cpp - ${SHADER_FILES} - ${INC_FILES} + viewer.cpp + ${SHADER_FILES} + ${INC_FILES} + $ ) target_link_libraries(ptexViewer diff --git a/examples/uvViewer/CMakeLists.txt b/examples/uvViewer/CMakeLists.txt index b2137102..4130954b 100644 --- a/examples/uvViewer/CMakeLists.txt +++ b/examples/uvViewer/CMakeLists.txt @@ -69,11 +69,9 @@ endforeach() _add_glfw_executable(uvViewer viewer.cpp - ../common/font_image.cpp - ../common/hud.cpp - ../common/gl_hud.cpp ${SHADER_FILES} ${INC_FILES} + $ ) target_link_libraries(uvViewer diff --git a/opensubdiv/osd/CMakeLists.txt b/opensubdiv/osd/CMakeLists.txt index cd94f660..a8b05ade 100644 --- a/opensubdiv/osd/CMakeLists.txt +++ b/opensubdiv/osd/CMakeLists.txt @@ -466,15 +466,25 @@ source_group("Inc" FILES ${INC_FILES}) if (NOT NO_LIB) - add_library(osd_static_cpu_obj + # Compile objs first for both the CPU and GPU libs ----- + add_library(osd_cpu_obj OBJECT ${CPU_SOURCE_FILES} ${PRIVATE_HEADER_FILES} ${PUBLIC_HEADER_FILES} ) + + add_library(osd_gpu_obj + OBJECT + ${GPU_SOURCE_FILES} + ${PRIVATE_HEADER_FILES} + ${PUBLIC_HEADER_FILES} + ) + + # Build static libs ------------------------------------ add_library(osd_static_cpu STATIC - $ + $ ) set_target_properties(osd_static_cpu PROPERTIES OUTPUT_NAME osdCPU CLEAN_DIRECT_OUTPUT 1) @@ -482,11 +492,11 @@ if (NOT NO_LIB) ${PLATFORM_CPU_LIBRARIES} ) + # this macro uses FindCUDA.cmake to compile .cu kernel files + # the target then adds the other obj dependencies and include files _add_possibly_cuda_library(osd_static_gpu STATIC - ${GPU_SOURCE_FILES} - ${PRIVATE_HEADER_FILES} - ${PUBLIC_HEADER_FILES} + $ ${KERNEL_FILES} ${INC_FILES} ) @@ -499,22 +509,20 @@ if (NOT NO_LIB) install( TARGETS osd_static_cpu DESTINATION ${CMAKE_LIBDIR_BASE} ) install( TARGETS osd_static_gpu DESTINATION ${CMAKE_LIBDIR_BASE} ) + # Build dynamic libs ---------------------------------- if (NOT WIN32 AND NOT IOS) # Evaluate 'soname' from OSD version + # replace '_' with '.' + string(REGEX REPLACE "(_)" "." OSD_SONAME ${OpenSubdiv_VERSION}) - # replace '_' with '.' - string(REGEX REPLACE "(_)" "." OSD_SONAME ${OpenSubdiv_VERSION}) - - # remove starting 'v' character - string(REGEX REPLACE "^v" "" OSD_SONAME ${OSD_SONAME}) + # remove starting 'v' character + string(REGEX REPLACE "^v" "" OSD_SONAME ${OSD_SONAME}) # generate dynamic-link targets add_library(osd_dynamic_cpu SHARED - ${CPU_SOURCE_FILES} - ${PRIVATE_HEADER_FILES} - ${PUBLIC_HEADER_FILES} + $ ) set_target_properties(osd_dynamic_cpu @@ -530,9 +538,7 @@ if (NOT NO_LIB) _add_possibly_cuda_library(osd_dynamic_gpu SHARED - ${GPU_SOURCE_FILES} - ${PRIVATE_HEADER_FILES} - ${PUBLIC_HEADER_FILES} + $ ${KERNEL_FILES} ${INC_FILES} )