Skip to content

Commit

Permalink
Isolate samples, unittests, coverage and overall build to PROJECT_BIN…
Browse files Browse the repository at this point in the history
…ARY_DIR
  • Loading branch information
kamiccolo authored and neheb committed Jul 21, 2023
1 parent 3dea23f commit 6f5b1c9
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 35 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ if (EXIV2_BUILD_DOC)
generate_documentation("${PROJECT_SOURCE_DIR}/cmake/Doxyfile.in")
endif()

include_directories(${CMAKE_BINARY_DIR}) # Make the exv_conf.h file visible for the full project
include_directories(${PROJECT_BINARY_DIR}) # Make the exv_conf.h file visible for the full project

if( EXIV2_ENABLE_XMP )
add_subdirectory( xmpsdk )
Expand Down
8 changes: 4 additions & 4 deletions cmake/exiv2_uninstall.cmake
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
IF(NOT EXISTS "${CMAKE_BINARY_DIR}/install_manifest.txt")
MESSAGE(FATAL_ERROR "Cannot find install manifest: ${CMAKE_BINARY_DIR}/install_manifest.txt")
ENDIF(NOT EXISTS "${CMAKE_BINARY_DIR}/install_manifest.txt")
IF(NOT EXISTS "${PROJECT_BINARY_DIR}/install_manifest.txt")
MESSAGE(FATAL_ERROR "Cannot find install manifest: ${PROJECT_BINARY_DIR}/install_manifest.txt")
ENDIF(NOT EXISTS "${PROJECT_BINARY_DIR}/install_manifest.txt")

FILE(READ "${CMAKE_BINARY_DIR}/install_manifest.txt" files)
FILE(READ "${PROJECT_BINARY_DIR}/install_manifest.txt" files)
STRING(REGEX REPLACE "\n" ";" files "${files}")
FOREACH(file ${files})
MESSAGE(STATUS "Uninstalling: ${file}")
Expand Down
14 changes: 7 additions & 7 deletions cmake/findDependencies.cmake
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
if (CONAN_AUTO_INSTALL)
# Download automatically the cmake-conan integration file
if(NOT EXISTS "${CMAKE_BINARY_DIR}/conan.cmake")
if(NOT EXISTS "${PROJECT_BINARY_DIR}/conan.cmake")
message(STATUS "Downloading conan.cmake from https://github.com/conan-io/cmake-conan")
file(DOWNLOAD "https://raw.githubusercontent.com/conan-io/cmake-conan/master/conan.cmake"
"${CMAKE_BINARY_DIR}/conan.cmake"
"${PROJECT_BINARY_DIR}/conan.cmake"
TLS_VERIFY ON)
endif()

include(${CMAKE_BINARY_DIR}/conan.cmake)
include(${PROJECT_BINARY_DIR}/conan.cmake)

conan_cmake_autodetect(settings)
conan_cmake_install(PATH_OR_REFERENCE ..
Expand All @@ -19,13 +19,13 @@ endif()

if (APPLE)
# On Apple, we use the conan cmake_paths generator
if (EXISTS ${CMAKE_BINARY_DIR}/conan_paths.cmake)
include(${CMAKE_BINARY_DIR}/conan_paths.cmake)
if (EXISTS ${PROJECT_BINARY_DIR}/conan_paths.cmake)
include(${PROJECT_BINARY_DIR}/conan_paths.cmake)
endif()
else()
# Otherwise, we rely on the conan cmake_find_package generator
list(APPEND CMAKE_MODULE_PATH ${CMAKE_BINARY_DIR})
list(APPEND CMAKE_PREFIX_PATH ${CMAKE_BINARY_DIR})
list(APPEND CMAKE_MODULE_PATH ${PROJECT_BINARY_DIR})
list(APPEND CMAKE_PREFIX_PATH ${PROJECT_BINARY_DIR})
endif()

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/")
Expand Down
6 changes: 3 additions & 3 deletions cmake/gcovr.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ if(BUILD_WITH_COVERAGE)
find_program (GCOVR gcovr)

if(GCOVR)
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/coverage_output )
file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/coverage_output )
add_custom_command(OUTPUT _run_gcovr_parser
POST_BUILD
COMMAND ${GCOVR} --root ${CMAKE_SOURCE_DIR} --object-dir=${CMAKE_BINARY_DIR} --html --html-details -o coverage_output/coverage.html
COMMAND ${GCOVR} --root ${PROJECT_SOURCE_DIR} --object-dir=${PROJECT_BINARY_DIR} --html --html-details -o coverage_output/coverage.html
--exclude-directories xmpsdk --exclude-directories unitTests --exclude-directories samples
--exclude '.*xmpsdk.*' --exclude '.*unitTests.*' --exclude '.*samples.*'
--exclude-unreachable-branches --exclude-throw-branches

WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
)
add_custom_target (coverage DEPENDS _run_gcovr_parser)
endif()
Expand Down
2 changes: 1 addition & 1 deletion cmake/generateConfigFile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ int main() {
set(EXV_ENABLE_NLS ${EXIV2_ENABLE_NLS})
set(EXV_ENABLE_VIDEO ${EXIV2_ENABLE_VIDEO})

configure_file(cmake/config.h.cmake ${CMAKE_BINARY_DIR}/exv_conf.h @ONLY)
configure_file(cmake/config.h.cmake ${PROJECT_BINARY_DIR}/exv_conf.h @ONLY)
10 changes: 5 additions & 5 deletions cmake/mainSetup.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ include(CTest)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})

Expand All @@ -33,6 +33,6 @@ endif()

# Prevent conflicts when exiv2 is consumed in multiple-subdirectory projects.
if (NOT TARGET uninstall)
configure_file(cmake/exiv2_uninstall.cmake ${CMAKE_BINARY_DIR}/cmake_uninstall.cmake COPYONLY)
add_custom_target(uninstall "${CMAKE_COMMAND}" -P "${CMAKE_BINARY_DIR}/cmake_uninstall.cmake")
configure_file(cmake/exiv2_uninstall.cmake ${PROJECT_BINARY_DIR}/cmake_uninstall.cmake COPYONLY)
add_custom_target(uninstall "${CMAKE_COMMAND}" -P "${PROJECT_BINARY_DIR}/cmake_uninstall.cmake")
endif()
2 changes: 1 addition & 1 deletion cmake/printSummary.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function(printList items)
endforeach()
endfunction()

get_property(COMPILER_OPTIONS DIRECTORY ${CMAKE_SOURCE_DIR} PROPERTY COMPILE_OPTIONS)
get_property(COMPILER_OPTIONS DIRECTORY ${PROJECT_SOURCE_DIR} PROPERTY COMPILE_OPTIONS)

message( STATUS "Install prefix: ${CMAKE_INSTALL_PREFIX}")
message( STATUS "------------------------------------------------------------------" )
Expand Down
14 changes: 7 additions & 7 deletions samples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ foreach(entry ${SAMPLES})
set_target_properties(${target} PROPERTIES
COMPILE_FLAGS ${EXTRA_COMPILE_FLAGS})
list(APPEND APPLICATIONS ${target})
target_include_directories(${target} PRIVATE ${CMAKE_SOURCE_DIR}/src) # To find unused.h
target_include_directories(${target} PRIVATE ${PROJECT_SOURCE_DIR}/src) # To find unused.h
if ( NOT ${target} MATCHES ".*test.*") # don't install tests
install( TARGETS ${target} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()
Expand All @@ -54,20 +54,20 @@ endif()
add_executable( getopt-test getopt-test.cpp ../app/getopt.cpp)
list(APPEND APPLICATIONS getopt-test)
target_include_directories(getopt-test PRIVATE
${CMAKE_SOURCE_DIR}/app
${PROJECT_SOURCE_DIR}/app
) # To find getopt.hpp

add_executable( metacopy metacopy.cpp metacopy.hpp ../app/getopt.cpp)
list(APPEND APPLICATIONS metacopy)
target_include_directories(metacopy PRIVATE
${CMAKE_SOURCE_DIR}/app
${PROJECT_SOURCE_DIR}/app
) # To find getopt.hpp

add_executable( path-test path-test.cpp ../app/getopt.cpp)
list(APPEND APPLICATIONS path-test)
set_target_properties( path-test PROPERTIES OUTPUT_NAME path-test )
target_include_directories(path-test PRIVATE
${CMAKE_SOURCE_DIR}/app
${PROJECT_SOURCE_DIR}/app
) # To find getopt.hpp

install( TARGETS metacopy RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
Expand All @@ -85,10 +85,10 @@ if( EXPAT_FOUND )
exiv2-xmp
${EXPAT_LIBRARIES}
)
target_include_directories(geotag PRIVATE ${CMAKE_BINARY_DIR}) # exv_conf.h
target_include_directories(geotag PRIVATE ${CMAKE_SOURCE_DIR}/include) # <exiv2/exiv2.hpp>
target_include_directories(geotag PRIVATE ${PROJECT_BINARY_DIR}) # exv_conf.h
target_include_directories(geotag PRIVATE ${PROJECT_SOURCE_DIR}/include) # <exiv2/exiv2.hpp>
target_include_directories(geotag PRIVATE ${EXPAT_INCLUDE_DIR})
target_include_directories(geotag PRIVATE ${CMAKE_SOURCE_DIR}/src) # To find unused.h
target_include_directories(geotag PRIVATE ${PROJECT_SOURCE_DIR}/src) # To find unused.h

if (WIN32)
target_compile_definitions(geotag PRIVATE XML_STATIC)
Expand Down
8 changes: 4 additions & 4 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ add_library( exiv2lib

generate_export_header(exiv2lib
EXPORT_MACRO_NAME EXIV2API
EXPORT_FILE_NAME ${CMAKE_BINARY_DIR}/exiv2lib_export.h
EXPORT_FILE_NAME ${PROJECT_BINARY_DIR}/exiv2lib_export.h
STATIC_DEFINE exiv2lib_STATIC
)

Expand Down Expand Up @@ -291,11 +291,11 @@ install(TARGETS exiv2lib EXPORT exiv2Config

install(FILES
${PUBLIC_HEADERS}
${CMAKE_BINARY_DIR}/exv_conf.h
${CMAKE_BINARY_DIR}/exiv2lib_export.h
${PROJECT_BINARY_DIR}/exv_conf.h
${PROJECT_BINARY_DIR}/exiv2lib_export.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/exiv2)

install(EXPORT exiv2Config DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/exiv2")

install(FILES ${CMAKE_CURRENT_BINARY_DIR}/exiv2ConfigVersion.cmake DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/exiv2")
install(FILES ${PROJECT_BINARY_DIR}/exiv2ConfigVersion.cmake DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/exiv2")

3 changes: 1 addition & 2 deletions unitTests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ if( EXIV2_ENABLE_PNG )
endif()

target_include_directories(unit_tests
PRIVATE
${CMAKE_SOURCE_DIR}/src
PRIVATE ${PROJECT_SOURCE_DIR}/src
)

set_target_properties(unit_tests PROPERTIES
Expand Down

0 comments on commit 6f5b1c9

Please sign in to comment.