Skip to content

Commit

Permalink
cmake: add format file
Browse files Browse the repository at this point in the history
Helps to keep the CMake stuff consistent.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
  • Loading branch information
neheb committed Sep 20, 2023
1 parent 590f615 commit 0f85d5a
Show file tree
Hide file tree
Showing 9 changed files with 554 additions and 538 deletions.
17 changes: 17 additions & 0 deletions .cmake-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
with section("format"):

# How wide to allow formatted cmake files
line_width = 150

# How many spaces to tab for indent
tab_size = 2

# If true, separate flow control names from their parentheses with a space
separate_ctrl_name_with_space = False

# If true, separate function names from parentheses with a space
separate_fn_name_with_space = False

# If a statement is wrapped to more than one line, than dangle the closing
# parenthesis on its own line.
dangle_parens = True
177 changes: 95 additions & 82 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
# Minimum version imposed by Ubuntu:20.04
cmake_minimum_required( VERSION 3.16.3 )

project(exiv2 # use TWEAK to categorize the build
VERSION 1.00.0.9 # 1.00.0 = GM (tagged and released)
# 1.00.0.9 = 1.00.0 Development
# 1.00.0.00 = GM Preview
# 1.00.0.2 = RC2 (tagged and released)
# 1.00.0.20 = RC2 Preview
# 1.00.0.29 = RC2 Development
DESCRIPTION "Exif/IPTC/Xmp C++ metadata library and tools plus ICC Profiles, Previews and more."
LANGUAGES C CXX
cmake_minimum_required(VERSION 3.16.3)

# use TWEAK to categorize the build:
#
# * 1.00.0 = GM (tagged and released)
# * 1.00.0.9 = 1.00.0 Development
# * 1.00.0.00 = GM Preview
# * 1.00.0.2 = RC2 (tagged and released)
# * 1.00.0.20 = RC2 Preview
# * 1.00.0.29 = RC2 Development
#
project(
exiv2
VERSION 1.00.0.9
DESCRIPTION "Exif/IPTC/Xmp C++ metadata library and tools plus ICC Profiles, Previews and more."
LANGUAGES C CXX
)

# Shared Object versioning (SemVer-like: must bump major on API breakage)
Expand All @@ -22,88 +27,84 @@ else()
endif()

if(NOT CMAKE_BUILD_TYPE)
set (CMAKE_BUILD_TYPE Release)
set(CMAKE_BUILD_TYPE Release)
endif()

include(cmake/mainSetup.cmake REQUIRED)
include(cmake/mainSetup.cmake)

# options and their default values
option( BUILD_SHARED_LIBS "Build exiv2lib as a shared library" ON )
option( EXIV2_ENABLE_XMP "Build with XMP metadata support" ON )
option( EXIV2_ENABLE_EXTERNAL_XMP "Use external version of XMP" OFF )
option( EXIV2_ENABLE_PNG "Build with PNG support (requires zlib)" ON )
option( EXIV2_ENABLE_NLS "Build native language support (requires gettext)" OFF )
option( EXIV2_ENABLE_LENSDATA "Build including Nikon lens data" ON )
option( EXIV2_ENABLE_DYNAMIC_RUNTIME "Use dynamic runtime (used for static libs)" ON )
option( EXIV2_ENABLE_WEBREADY "Build webready support into library" OFF )
option( EXIV2_ENABLE_CURL "Use libcurl for HttpIo (WEBREADY)" OFF )
option( EXIV2_ENABLE_BMFF "Build with BMFF support" ON )
option( EXIV2_ENABLE_BROTLI "Use Brotli for JPEG XL compressed boxes (BMFF)" ON )
option( EXIV2_ENABLE_VIDEO "Build with video support" ON )
option( EXIV2_ENABLE_INIH "Use inih library" ON )

option( EXIV2_BUILD_SAMPLES "Build sample applications" OFF )
option( EXIV2_BUILD_EXIV2_COMMAND "Build exiv2 command-line executable" ON )
option( EXIV2_BUILD_UNIT_TESTS "Build unit tests" OFF )
option( EXIV2_BUILD_FUZZ_TESTS "Build fuzz tests (libFuzzer)" OFF )
option( EXIV2_BUILD_DOC "Add 'doc' target to generate documentation" OFF )
option(BUILD_SHARED_LIBS "Build exiv2lib as a shared library" ON)
option(EXIV2_ENABLE_XMP "Build with XMP metadata support" ON)
option(EXIV2_ENABLE_EXTERNAL_XMP "Use external version of XMP" OFF)
option(EXIV2_ENABLE_PNG "Build with PNG support (requires zlib)" ON)
option(EXIV2_ENABLE_NLS "Build native language support (requires gettext)" OFF)
option(EXIV2_ENABLE_LENSDATA "Build including Nikon lens data" ON)
option(EXIV2_ENABLE_DYNAMIC_RUNTIME "Use dynamic runtime (used for static libs)" ON)
option(EXIV2_ENABLE_WEBREADY "Build webready support into library" OFF)
option(EXIV2_ENABLE_CURL "Use libcurl for HttpIo (WEBREADY)" OFF)
option(EXIV2_ENABLE_BMFF "Build with BMFF support" ON)
option(EXIV2_ENABLE_BROTLI "Use Brotli for JPEG XL compressed boxes (BMFF)" ON)
option(EXIV2_ENABLE_VIDEO "Build with video support" ON)
option(EXIV2_ENABLE_INIH "Use inih library" ON)

option(EXIV2_BUILD_SAMPLES "Build sample applications" OFF)
option(EXIV2_BUILD_EXIV2_COMMAND "Build exiv2 command-line executable" ON)
option(EXIV2_BUILD_UNIT_TESTS "Build unit tests" OFF)
option(EXIV2_BUILD_FUZZ_TESTS "Build fuzz tests (libFuzzer)" OFF)
option(EXIV2_BUILD_DOC "Add 'doc' target to generate documentation" OFF)

# Only intended to be used by Exiv2 developers/contributors
option( EXIV2_TEAM_EXTRA_WARNINGS "Add more sanity checks using compiler flags" OFF )
option( EXIV2_TEAM_WARNINGS_AS_ERRORS "Treat warnings as errors" OFF )
option( EXIV2_TEAM_USE_SANITIZERS "Enable ASAN and UBSAN when available" OFF )
option(EXIV2_TEAM_EXTRA_WARNINGS "Add more sanity checks using compiler flags" OFF)
option(EXIV2_TEAM_WARNINGS_AS_ERRORS "Treat warnings as errors" OFF)
option(EXIV2_TEAM_USE_SANITIZERS "Enable ASAN and UBSAN when available" OFF)

# The EXIV2_TEAM_OSS_FUZZ option is used by the OSS-Fuzz build script:
# https://github.com/google/oss-fuzz/tree/master/projects/exiv2/build.sh
option( EXIV2_TEAM_OSS_FUZZ "Build config for OSS-Fuzz" OFF )
#
# * https://github.com/google/oss-fuzz/tree/master/projects/exiv2/build.sh
#
option(EXIV2_TEAM_OSS_FUZZ "Build config for OSS-Fuzz" OFF)

option( EXIV2_TEAM_PACKAGING "Additional stuff for generating packages" OFF )
option(EXIV2_TEAM_PACKAGING "Additional stuff for generating packages" OFF)
set(EXTRA_COMPILE_FLAGS " ")

mark_as_advanced(
EXIV2_TEAM_EXTRA_WARNINGS
EXIV2_TEAM_WARNINGS_AS_ERRORS
EXIV2_ENABLE_EXTERNAL_XMP
EXTRA_COMPILE_FLAGS
EXIV2_TEAM_USE_SANITIZERS
)
mark_as_advanced(EXIV2_TEAM_EXTRA_WARNINGS EXIV2_TEAM_WARNINGS_AS_ERRORS EXIV2_ENABLE_EXTERNAL_XMP EXTRA_COMPILE_FLAGS EXIV2_TEAM_USE_SANITIZERS)

option( BUILD_WITH_STACK_PROTECTOR "Build with stack protector" ON )
option( BUILD_WITH_CCACHE "Use ccache to speed up compilations" OFF )
option( BUILD_WITH_COVERAGE "Add compiler flags to generate coverage stats" OFF )
option(BUILD_WITH_STACK_PROTECTOR "Build with stack protector" ON)
option(BUILD_WITH_CCACHE "Use ccache to speed up compilations" OFF)
option(BUILD_WITH_COVERAGE "Add compiler flags to generate coverage stats" OFF)
include(cmake/gcovr.cmake REQUIRED)

set( PACKAGE_URL "https://exiv2.org")
set(PACKAGE_URL "https://exiv2.org")

if ( EXIV2_ENABLE_EXTERNAL_XMP )
if(EXIV2_ENABLE_EXTERNAL_XMP)
set(EXIV2_ENABLE_XMP OFF)
endif()

include(cmake/findDependencies.cmake REQUIRED)
include(cmake/compilerFlags.cmake REQUIRED)
include(cmake/findDependencies.cmake REQUIRED)
include(cmake/compilerFlags.cmake REQUIRED)
include(cmake/generateConfigFile.cmake REQUIRED)

if (EXIV2_BUILD_DOC)
include(cmake/generateDoc.cmake REQUIRED)
if(EXIV2_BUILD_DOC)
include(cmake/generateDoc.cmake REQUIRED)
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(${CMAKE_BINARY_DIR}) # Make the exv_conf.h file visible for the full project

if( EXIV2_ENABLE_XMP )
add_subdirectory( xmpsdk )
if(EXIV2_ENABLE_XMP)
add_subdirectory(xmpsdk)
endif()

include(cmake/compilerFlagsExiv2.cmake REQUIRED)

add_subdirectory( src )
add_subdirectory(src)

if(BUILD_TESTING AND EXIV2_BUILD_UNIT_TESTS)
add_subdirectory ( unitTests )
add_subdirectory(unitTests)
endif()

if( EXIV2_BUILD_FUZZ_TESTS )
add_subdirectory ( fuzz )
if(EXIV2_BUILD_FUZZ_TESTS)
add_subdirectory(fuzz)
endif()

if(EXIV2_BUILD_EXIV2_COMMAND)
Expand All @@ -114,58 +115,70 @@ if(EXIV2_BUILD_EXIV2_COMMAND)
get_directory_property(SAMPLES DIRECTORY samples DEFINITION APPLICATIONS)

if(BUILD_TESTING AND Python3_Interpreter_FOUND)
add_test(NAME bashTests
add_test(
NAME bashTests
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/tests
COMMAND cmake -E env EXIV2_BINDIR=${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${Python3_EXECUTABLE} runner.py --verbose bash_tests)
COMMAND cmake -E env EXIV2_BINDIR=${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${Python3_EXECUTABLE} runner.py --verbose bash_tests
)
endif()
endif()

if(BUILD_TESTING AND Python3_Interpreter_FOUND)
add_test(NAME bugfixTests
add_test(
NAME bugfixTests
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/tests
COMMAND cmake -E env EXIV2_BINDIR=${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${Python3_EXECUTABLE} runner.py --verbose bugfixes)
add_test(NAME lensTests
COMMAND cmake -E env EXIV2_BINDIR=${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${Python3_EXECUTABLE} runner.py --verbose bugfixes
)
add_test(
NAME lensTests
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/tests
COMMAND cmake -E env EXIV2_BINDIR=${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${Python3_EXECUTABLE} runner.py --verbose lens_tests)
add_test(NAME tiffTests
COMMAND cmake -E env EXIV2_BINDIR=${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${Python3_EXECUTABLE} runner.py --verbose lens_tests
)
add_test(
NAME tiffTests
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/tests
COMMAND cmake -E env EXIV2_BINDIR=${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${Python3_EXECUTABLE} runner.py --verbose tiff_test)
add_test(NAME versionTests
COMMAND cmake -E env EXIV2_BINDIR=${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${Python3_EXECUTABLE} runner.py --verbose tiff_test
)
add_test(
NAME versionTests
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/tests
COMMAND cmake -E env EXIV2_BINDIR=${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${Python3_EXECUTABLE} runner.py --verbose bash_tests/version_test.py )
add_test(NAME regressionTests
COMMAND cmake -E env EXIV2_BINDIR=${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${Python3_EXECUTABLE} runner.py --verbose bash_tests/version_test.py
)
add_test(
NAME regressionTests
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/tests
COMMAND cmake -E env EXIV2_BINDIR=${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${Python3_EXECUTABLE} runner.py --verbose regression_tests)
COMMAND cmake -E env EXIV2_BINDIR=${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${Python3_EXECUTABLE} runner.py --verbose regression_tests
)
endif()
endif()

if( EXIV2_ENABLE_NLS )
add_subdirectory( po )
if(EXIV2_ENABLE_NLS)
add_subdirectory(po)
endif()

if (EXIV2_TEAM_PACKAGING)
if(EXIV2_TEAM_PACKAGING)
include(cmake/packaging.cmake)
endif()

# Handle both relative and absolute paths (e.g. NixOS) for a relocatable package
if(IS_ABSOLUTE "${CMAKE_INSTALL_LIBDIR}")
set(libdir_for_pc_file "${CMAKE_INSTALL_LIBDIR}")
set(libdir_for_pc_file "${CMAKE_INSTALL_LIBDIR}")
else()
join_paths(libdir_for_pc_file "\${exec_prefix}" "${CMAKE_INSTALL_LIBDIR}")
join_paths(libdir_for_pc_file "\${exec_prefix}" "${CMAKE_INSTALL_LIBDIR}")
endif()
if(IS_ABSOLUTE "${CMAKE_INSTALL_INCLUDEDIR}")
set(includedir_for_pc_file "${CMAKE_INSTALL_INCLUDEDIR}")
set(includedir_for_pc_file "${CMAKE_INSTALL_INCLUDEDIR}")
else()
join_paths(includedir_for_pc_file "\${prefix}" "${CMAKE_INSTALL_INCLUDEDIR}")
join_paths(includedir_for_pc_file "\${prefix}" "${CMAKE_INSTALL_INCLUDEDIR}")
endif()
configure_file(cmake/exiv2.pc.in exiv2.pc @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/exiv2.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)

# ******************************************************************************
# Man page
install( FILES ${PROJECT_SOURCE_DIR}/man/man1/exiv2.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1 )
install(FILES ${PROJECT_SOURCE_DIR}/man/man1/exiv2.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1)

include(cmake/printSummary.cmake)

# That's all Folks!
##
#
73 changes: 39 additions & 34 deletions app/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,57 +1,62 @@
add_executable( exiv2
exiv2.cpp
exiv2app.hpp
actions.cpp actions.hpp
getopt.cpp getopt.hpp
app_utils.cpp app_utils.hpp
add_executable(
exiv2
exiv2.cpp
exiv2app.hpp
actions.cpp
actions.hpp
getopt.cpp
getopt.hpp
app_utils.cpp
app_utils.hpp
)

target_include_directories(exiv2 PRIVATE ${PROJECT_SOURCE_DIR}/src) # To find i18n.hpp

set_target_properties( exiv2 PROPERTIES
COMPILE_FLAGS ${EXTRA_COMPILE_FLAGS}
XCODE_ATTRIBUTE_GCC_GENERATE_DEBUGGING_SYMBOLS[variant=Debug] "YES"
)
if (MSVC)
set_target_properties(exiv2 PROPERTIES LINK_FLAGS "/ignore:4099") # Ignore missing PDBs
set_target_properties(exiv2 PROPERTIES COMPILE_FLAGS ${EXTRA_COMPILE_FLAGS} XCODE_ATTRIBUTE_GCC_GENERATE_DEBUGGING_SYMBOLS[variant=Debug] "YES")
if(MSVC)
set_target_properties(exiv2 PROPERTIES LINK_FLAGS "/ignore:4099") # Ignore missing PDBs
endif()

target_link_libraries( exiv2 PRIVATE exiv2lib )
target_link_libraries(exiv2 PRIVATE exiv2lib)

if( EXIV2_ENABLE_NLS )
target_link_libraries(exiv2 PRIVATE ${Intl_LIBRARIES})
target_include_directories(exiv2 PRIVATE ${Intl_INCLUDE_DIRS})
if(EXIV2_ENABLE_NLS)
target_link_libraries(exiv2 PRIVATE ${Intl_LIBRARIES})
target_include_directories(exiv2 PRIVATE ${Intl_INCLUDE_DIRS})
endif()

target_link_libraries(exiv2 PRIVATE std::filesystem)

if(MSVC OR MINGW)
# Trick to get properly UTF-8 encoded argv
# More info at: https://github.com/huangqinjin/wmain
add_library(wmain STATIC wmain.cpp)
target_link_libraries(exiv2 PRIVATE wmain)
# Trick to get properly UTF-8 encoded argv More info at: https://github.com/huangqinjin/wmain
add_library(wmain STATIC wmain.cpp)
target_link_libraries(exiv2 PRIVATE wmain)
endif()

if (MSVC)
target_link_options(wmain INTERFACE /WHOLEARCHIVE:$<TARGET_FILE:wmain>)
target_link_options(exiv2 PRIVATE "/ENTRY:wWinMainCRTStartup")
if(MSVC)
target_link_options(wmain INTERFACE /WHOLEARCHIVE:$<TARGET_FILE:wmain>)
target_link_options(exiv2 PRIVATE "/ENTRY:wWinMainCRTStartup")
endif()

if (MINGW)
target_compile_options(exiv2 PRIVATE -municode)
target_link_options(exiv2 PRIVATE -municode)
if(MINGW)
target_compile_options(exiv2 PRIVATE -municode)
target_link_options(exiv2 PRIVATE -municode)
endif()

if (USING_CONAN AND WIN32 AND EXISTS ${PROJECT_BINARY_DIR}/conanDlls)
# In case of using conan recipes with their 'shared' option turned on, we will have dlls of
# the 3rd party dependencies in the conanDlls folder.
if(USING_CONAN
AND WIN32
AND EXISTS ${PROJECT_BINARY_DIR}/conanDlls
)
# In case of using conan recipes with their 'shared' option turned on, we will have dlls of the 3rd party dependencies in the conanDlls folder.

# Copy 3rd party DLLs the bin folder. [build step]
add_custom_command(TARGET exiv2 POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory ${PROJECT_BINARY_DIR}/conanDlls ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
add_custom_command(
TARGET exiv2
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory ${PROJECT_BINARY_DIR}/conanDlls ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
COMMENT "Copy 3rd party DLLs the bin folder"
)

# Copy 3rd party DLLs the bin folder. [install step]
install(DIRECTORY ${PROJECT_BINARY_DIR}/conanDlls/ DESTINATION bin)
# Copy 3rd party DLLs the bin folder. [install step]
install(DIRECTORY ${PROJECT_BINARY_DIR}/conanDlls/ DESTINATION bin)
endif()

install(TARGETS exiv2 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
Loading

0 comments on commit 0f85d5a

Please sign in to comment.