diff --git a/CMakeLists.txt b/CMakeLists.txt index 341502fd..af40c1a2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) @@ -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) diff --git a/src/apps/CMakeLists.txt b/src/apps/CMakeLists.txt index a4a04df1..19b9bffa 100644 --- a/src/apps/CMakeLists.txt +++ b/src/apps/CMakeLists.txt @@ -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() diff --git a/src/apps/ojph_compress/CMakeLists.txt b/src/apps/ojph_compress/CMakeLists.txt index 3dd3c59a..420c303b 100644 --- a/src/apps/ojph_compress/CMakeLists.txt +++ b/src/apps/ojph_compress/CMakeLists.txt @@ -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 "$" ${OJPH_DESTINATION_BINARY} +) diff --git a/src/apps/ojph_expand/CMakeLists.txt b/src/apps/ojph_expand/CMakeLists.txt index f7b1ed33..5d43239d 100644 --- a/src/apps/ojph_expand/CMakeLists.txt +++ b/src/apps/ojph_expand/CMakeLists.txt @@ -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 "$" ${OJPH_DESTINATION_BINARY} +) diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 1f41da8c..e4591e34 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -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") @@ -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 "$" ${OJPH_DESTINATION_BINARY} + COMMAND ${CMAKE_COMMAND} -E make_directory ${OJPH_DESTINATION_ARCHIVE} + COMMAND ${CMAKE_COMMAND} -E copy "$" ${OJPH_DESTINATION_ARCHIVE} +) +if (MSVC) + add_custom_command(TARGET openjph POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy "$/${OJPH_LIB_NAME_STRING}.exp" ${OJPH_DESTINATION_ARCHIVE} + ) +endif() +if(EMSCRIPTEN) + add_custom_command(TARGET openjphsimd POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy "$" ${OJPH_DESTINATION_BINARY} + ) +endif() diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 08fd2f90..864409e9 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -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 "$" "./" + COMMAND ${CMAKE_COMMAND} -E copy "$" "./" + COMMAND ${CMAKE_COMMAND} -E copy "$" "./" + ) + 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" "./" diff --git a/tests/test_executables.cpp b/tests/test_executables.cpp index 7b16b542..908e6ce1 100644 --- a/tests/test_executables.cpp +++ b/tests/test_executables.cpp @@ -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 "./"