Skip to content

Commit

Permalink
Modifies CMake files, with the objective of not modifying output dire…
Browse files Browse the repository at this point in the history
…ctories. Now all files are copied after compilation. I also fiddle with the tests to make them more versatile.
  • Loading branch information
aous72 committed Jan 22, 2024
1 parent 4a4a4d4 commit 4d50eb7
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 90 deletions.
15 changes: 9 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ option(OJPH_ENABLE_TIFF_SUPPORT "Enables input and output support for TIFF files
option(OJPH_BUILD_TESTS "Enables building test code" OFF)
option(OJPH_BUILD_EXECUTABLES "Enables building command line executables" ON)

## specify output directories
set(OJPH_DESTINATION_BINARY ${CMAKE_BINARY_DIR}/../bin)
set(OJPH_DESTINATION_ARCHIVE ${CMAKE_BINARY_DIR}/../lib)

## specify the top directory for TIFF library (only for Micrsoft)
if (MSVC)
set(TIFF_PATH "C:\\Program Files\\tiff")
endif()

## Setting some of the options if EMSCRIPTEN is the compiler
if(EMSCRIPTEN)
set(OJPH_DISABLE_INTEL_SIMD ON)
Expand Down Expand Up @@ -68,12 +77,6 @@ elseif (OJPH_ENABLE_INTEL_AVX512)
add_compile_options(-DOJPH_ENABLE_INTEL_AVX512)
endif()

## specify output directories
## this will be refined further for Debug and Release builds in included CMakeLists.txt
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/../bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/../bin)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/../lib)

## Build library and applications
add_subdirectory(src/core)
if (OJPH_BUILD_EXECUTABLES)
Expand Down
100 changes: 43 additions & 57 deletions src/apps/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,60 +1,46 @@

if(OJPH_BUILD_EXECUTABLES)

# Add tiff library
############################################################
if( OJPH_ENABLE_TIFF_SUPPORT )

if( MSVC )

set(TIFF_PATH "C:\\Program Files\\tiff")
set(TIFF_INCLUDE_DIR "${TIFF_PATH}\\include" CACHE PATH "the directory containing the TIFF headers")
set(TIFF_LIBRARY_DEBUG "${TIFF_PATH}\\lib\\tiffd.lib" CACHE FILEPATH "the path to the TIFF library for debug configurations")
set(TIFF_LIBRARY_RELEASE "${TIFF_PATH}\\lib\\tiff.lib" CACHE FILEPATH "the path to the TIFF library for release configurations")
set(TIFFXX_LIBRARY_DEBUG "${TIFF_PATH}\\lib\\tiffxxd.lib" CACHE FILEPATH "the path to the TIFFXX library for debug configurations")
set(TIFFXX_LIBRARY_RELEASE "${TIFF_PATH}\\lib\\tiffxx.lib" CACHE FILEPATH "the path to the TIFFXX library for release configurations")

message( STATUS "WIN32 detected: Setting CMakeCache TIFF values as follows, use CMake-gui Advanced to modify them" )
message( STATUS " TIFF_INCLUDE_DIR : \"${TIFF_INCLUDE_DIR}\" " )
message( STATUS " TIFF_LIBRARY_DEBUG : \"${TIFF_LIBRARY_DEBUG}\" " )
message( STATUS " TIFF_LIBRARY_RELEASE : \"${TIFF_LIBRARY_RELEASE}\" " )
message( STATUS " TIFFXX_LIBRARY_DEBUG : \"${TIFFXX_LIBRARY_DEBUG}\" " )
message( STATUS " TIFFXX_LIBRARY_RELEASE : \"${TIFFXX_LIBRARY_RELEASE}\" " )

endif( MSVC )

FIND_PACKAGE( TIFF )

if( TIFF_FOUND )
set(USE_TIFF TRUE CACHE BOOL "Add TIFF support")
include_directories( ${TIFF_INCLUDE_DIR} )
add_definitions(-DOJPH_ENABLE_TIFF_SUPPORT)
endif( TIFF_FOUND )

endif()
############################################################

## change folders but only for Microsoft
if(MSVC)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/../bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/../bin)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/../lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/../bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/../bin)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/../lib)
endif()

## Build executables
add_subdirectory(ojph_expand)
add_subdirectory(ojph_compress)

if (MSVC AND OJPH_ENABLE_TIFF_SUPPORT)
if (CMAKE_BUILD_TYPE MATCHES "Release")
file(COPY "${TIFF_PATH}\\bin\\tiff.dll" DESTINATION "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
file(COPY "${TIFF_PATH}\\bin\\tiffxx.dll" DESTINATION "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
elseif(CMAKE_BUILD_TYPE MATCHES "Debug")
file(COPY "${TIFF_PATH}\\bin\\tiffd.dll" DESTINATION "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
file(COPY "${TIFF_PATH}\\bin\\tiffxxd.dll" DESTINATION "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
endif()
# Add tiff library
############################################################
if( OJPH_ENABLE_TIFF_SUPPORT )

if( MSVC )

set(TIFF_INCLUDE_DIR "${TIFF_PATH}\\include" CACHE PATH "the directory containing the TIFF headers")
set(TIFF_LIBRARY_DEBUG "${TIFF_PATH}\\lib\\tiffd.lib" CACHE FILEPATH "the path to the TIFF library for debug configurations")
set(TIFF_LIBRARY_RELEASE "${TIFF_PATH}\\lib\\tiff.lib" CACHE FILEPATH "the path to the TIFF library for release configurations")
set(TIFFXX_LIBRARY_DEBUG "${TIFF_PATH}\\lib\\tiffxxd.lib" CACHE FILEPATH "the path to the TIFFXX library for debug configurations")
set(TIFFXX_LIBRARY_RELEASE "${TIFF_PATH}\\lib\\tiffxx.lib" CACHE FILEPATH "the path to the TIFFXX library for release configurations")

message( STATUS "WIN32 detected: Setting CMakeCache TIFF values as follows, use CMake-gui Advanced to modify them" )
message( STATUS " TIFF_INCLUDE_DIR : \"${TIFF_INCLUDE_DIR}\" " )
message( STATUS " TIFF_LIBRARY_DEBUG : \"${TIFF_LIBRARY_DEBUG}\" " )
message( STATUS " TIFF_LIBRARY_RELEASE : \"${TIFF_LIBRARY_RELEASE}\" " )
message( STATUS " TIFFXX_LIBRARY_DEBUG : \"${TIFFXX_LIBRARY_DEBUG}\" " )
message( STATUS " TIFFXX_LIBRARY_RELEASE : \"${TIFFXX_LIBRARY_RELEASE}\" " )

endif( MSVC )

FIND_PACKAGE( TIFF )

if( TIFF_FOUND )
set(USE_TIFF TRUE CACHE BOOL "Add TIFF support")
include_directories( ${TIFF_INCLUDE_DIR} )
add_definitions(-DOJPH_ENABLE_TIFF_SUPPORT)
endif( TIFF_FOUND )

endif()
############################################################

## Build executables
add_subdirectory(ojph_expand)
add_subdirectory(ojph_compress)

if (MSVC AND OJPH_ENABLE_TIFF_SUPPORT)
if (CMAKE_BUILD_TYPE MATCHES "Release")
file(COPY "${TIFF_PATH}\\bin\\tiff.dll" DESTINATION "${OJPH_DESTINATION_BINARY}")
file(COPY "${TIFF_PATH}\\bin\\tiffxx.dll" DESTINATION "${OJPH_DESTINATION_BINARY}")
elseif(CMAKE_BUILD_TYPE MATCHES "Debug")
file(COPY "${TIFF_PATH}\\bin\\tiffd.dll" DESTINATION "${OJPH_DESTINATION_BINARY}")
file(COPY "${TIFF_PATH}\\bin\\tiffxxd.dll" DESTINATION "${OJPH_DESTINATION_BINARY}")
endif()
endif()
5 changes: 4 additions & 1 deletion src/apps/ojph_compress/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ else()
endif()

install(TARGETS ojph_compress DESTINATION bin)

endif()

## copy target files to the top bin folder
add_custom_command(TARGET ojph_compress POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy "$<TARGET_FILE:ojph_compress>" ${OJPH_DESTINATION_BINARY}
)
6 changes: 5 additions & 1 deletion src/apps/ojph_expand/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,9 @@ else()
endif()

install(TARGETS ojph_expand DESTINATION bin)

endif()

## copy target files to the top bin folder
add_custom_command(TARGET ojph_expand POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy "$<TARGET_FILE:ojph_expand>" ${OJPH_DESTINATION_BINARY}
)
27 changes: 17 additions & 10 deletions src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@

## change folders but only for Microsoft
if (MSVC)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/../bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/../bin)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/../lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/../bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/../bin)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/../lib)
endif()

include_directories(common)

file(GLOB CODESTREAM "codestream/*.cpp" "codestream/*.h")
Expand Down Expand Up @@ -104,3 +94,20 @@ else()
SOVERSION "${OPENJPH_VERSION_MAJOR}.${OPENJPH_VERSION_MINOR}"
VERSION "${OPENJPH_VERSION}")
endif()

## copy target files to the top bin folder
add_custom_command(TARGET openjph POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy "$<TARGET_FILE:openjph>" ${OJPH_DESTINATION_BINARY}
COMMAND ${CMAKE_COMMAND} -E make_directory ${OJPH_DESTINATION_ARCHIVE}
COMMAND ${CMAKE_COMMAND} -E copy "$<TARGET_LINKER_FILE:openjph>" ${OJPH_DESTINATION_ARCHIVE}
)
if (MSVC)
add_custom_command(TARGET openjph POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy "$<TARGET_LINKER_FILE_DIR:openjph>/${OJPH_LIB_NAME_STRING}.exp" ${OJPH_DESTINATION_ARCHIVE}
)
endif()
if(EMSCRIPTEN)
add_custom_command(TARGET openjphsimd POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy "$<TARGET_FILE:openjphsimd>" ${OJPH_DESTINATION_BINARY}
)
endif()
33 changes: 22 additions & 11 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,28 @@ include(GoogleTest)
gtest_add_tests(TARGET test_executables)

if (MSVC)
if(CMAKE_BUILD_TYPE MATCHES "Debug")
add_custom_command(TARGET test_executables POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy "../bin/Debug/gtest.dll" "./Debug/"
COMMAND ${CMAKE_COMMAND} -E copy "../bin/Debug/gtest_main.dll" "./Debug/"
)
elseif(CMAKE_BUILD_TYPE MATCHES "Release")
add_custom_command(TARGET test_executables POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy "../bin/Release/gtest.dll" "./Release/"
COMMAND ${CMAKE_COMMAND} -E copy "../bin/Release/gtest_main.dll" "./Release/"
)
endif()
add_custom_command(TARGET test_executables POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy "../bin/\$(Configuration)/gtest.dll" "./"
COMMAND ${CMAKE_COMMAND} -E copy "../bin/\$(Configuration)/gtest_main.dll" "./"
COMMAND ${CMAKE_COMMAND} -E copy "$<TARGET_FILE:ojph_compress>" "./"
COMMAND ${CMAKE_COMMAND} -E copy "$<TARGET_FILE:ojph_expand>" "./"
COMMAND ${CMAKE_COMMAND} -E copy "$<TARGET_FILE:openjph>" "./"
)
add_custom_command(TARGET compare_files POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy "./\$(Configuration)/compare_files.exe" "./"
)
add_custom_command(TARGET mse_pae POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy "./\$(Configuration)/mse_pae.exe" "./"
)
if (MSVC AND OJPH_ENABLE_TIFF_SUPPORT)
if (CMAKE_BUILD_TYPE MATCHES "Release")
file(COPY "${TIFF_PATH}\\bin\\tiff.dll" DESTINATION "./")
file(COPY "${TIFF_PATH}\\bin\\tiffxx.dll" DESTINATION "./")
elseif(CMAKE_BUILD_TYPE MATCHES "Debug")
file(COPY "${TIFF_PATH}\\bin\\tiffd.dll" DESTINATION "./")
file(COPY "${TIFF_PATH}\\bin\\tiffxxd.dll" DESTINATION "./")
endif()
endif()
elseif(MSYS)
add_custom_command(TARGET test_executables POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy "../bin/msys-gtest.dll" "./"
Expand Down
8 changes: 4 additions & 4 deletions tests/test_executables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ int execute(const std::string& cmd, std::string& result)
#define SRC_FILE_DIR ".\\jp2k_test_codestreams\\openjph\\"
#define OUT_FILE_DIR ".\\"
#define REF_FILE_DIR ".\\jp2k_test_codestreams\\openjph\\references\\"
#define MSE_PAE_PATH ".\\Release\\mse_pae"
#define COMPARE_FILES_PATH ".\\Release\\compare_files"
#define EXPAND_EXECUTABLE "..\\..\\bin\\ojph_expand.exe"
#define COMPRESS_EXECUTABLE "..\\..\\bin\\ojph_compress.exe"
#define MSE_PAE_PATH ".\\mse_pae"
#define COMPARE_FILES_PATH ".\\compare_files"
#define EXPAND_EXECUTABLE ".\\ojph_expand.exe"
#define COMPRESS_EXECUTABLE ".\\ojph_compress.exe"
#else
#define SRC_FILE_DIR "./jp2k_test_codestreams/openjph/"
#define OUT_FILE_DIR "./"
Expand Down

5 comments on commit 4d50eb7

@kmilos
Copy link

@kmilos kmilos commented on 4d50eb7 Feb 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use the regular CMake install command instead of explicitly copying, and please remove the hard-coded OJPH_DESTINATION_{BINARY,ARCHIVE} variables. Thank you.

@aous72
Copy link
Owner Author

@aous72 aous72 commented on 4d50eb7 Feb 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been done in version 0.10.5.
I find these requirements very restrictive.

@kmilos
Copy link

@kmilos kmilos commented on 4d50eb7 Feb 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find these requirements very restrictive.

I don't understand why that would be, and these are not strictly Linux-centric. There are a plethora of cross-platform libraries out there you can study that are just fine w/ CMake best practices and don't need all this special casing for MSVC...

Edit: For example, instead of hard coding and special casing all the TIFF stuff for MSVC, you'd pass -DCMAKE_PREFIX_PATH=C:\Program Files\tiff when you run cmake (as this is specific to your machine, not MSVC necessarily), and then all the rest works the same on all platforms. CMake is smart enough to look into include, lib, pick debug version if required, etc.

But you're the owner and it's ultimately your prerogative how you want to proceed.

@kmilos
Copy link

@kmilos kmilos commented on 4d50eb7 Feb 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you'd pass -DCMAKE_PREFIX_PATH=C:\Program Files\tiff when you run cmake

Even better, you can have your own CMAKE_PREFIX_PATH environment variable with not just path to tiff, but any other Windows locally installed libraries as well.

Note that if you use a more integrated development environment on Windows like vcpkg, it takes care of all of this automatically. (So does MSYS2 + MinGW, but it doesn't use MSVC like vcpkg does.)

@aous72
Copy link
Owner Author

@aous72 aous72 commented on 4d50eb7 Feb 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Milos,

Thank you for the feedback. You know way more than I do about CMake.
CMake is a large package with a lot to learn.

CMAKE_PREFIX_PATH seems to be a magic variable that helps with a lot of things.
I will see how to incorporate it in the next release.

Kind regards,
Aous.

Please sign in to comment.