From 4ae9094772a40c9369c998edfd5e24425c5b9b2d Mon Sep 17 00:00:00 2001 From: Naiyang Lin Date: Tue, 30 Aug 2022 20:00:35 +0800 Subject: [PATCH] Fix install dir and warning on MSVC --- .gitignore | 1 + CMakeLists.txt | 39 ++++++++++++++------------------------- 2 files changed, 15 insertions(+), 25 deletions(-) diff --git a/.gitignore b/.gitignore index dd19d69..88126e6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /_build /amalgamation /bin +/build-cmake/ diff --git a/CMakeLists.txt b/CMakeLists.txt index ce6ade1..dd62f7f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,6 +48,9 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bin) if(INSTALL_PROJECT) include(GNUInstallDirs) + if(MSVC) + set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install") + endif() endif() if(BUILD_HEADER_ONLY) @@ -229,33 +232,19 @@ if(INSTALL_PROJECT) endif() if(BUILD_EXAMPLES) - set(EXAMPLE1_SRC_LIST "${CMAKE_CURRENT_SOURCE_DIR}/examples/example1.c") - set(EXAMPLE2_SRC_LIST "${CMAKE_CURRENT_SOURCE_DIR}/examples/example2.c") - set(EXAMPLE3_SRC_LIST "${CMAKE_CURRENT_SOURCE_DIR}/examples/example3.c") - set(EXAMPLE4_SRC_LIST "${CMAKE_CURRENT_SOURCE_DIR}/examples/example4.c") - set(EXAMPLE5_SRC_LIST "${CMAKE_CURRENT_SOURCE_DIR}/examples/example5.c") - set(EXAMPLE6_SRC_LIST "${CMAKE_CURRENT_SOURCE_DIR}/examples/example6.c") - set(MINIZ_TESTER_SRC_LIST - "${CMAKE_CURRENT_SOURCE_DIR}/tests/miniz_tester.cpp" - "${CMAKE_CURRENT_SOURCE_DIR}/tests/timer.cpp") - - add_executable(example1 ${EXAMPLE1_SRC_LIST}) - target_link_libraries(example1 miniz) - add_executable(example2 ${EXAMPLE2_SRC_LIST}) - target_link_libraries(example2 miniz) - add_executable(example3 ${EXAMPLE3_SRC_LIST}) - target_link_libraries(example3 miniz) - add_executable(example4 ${EXAMPLE4_SRC_LIST}) - target_link_libraries(example4 miniz) - add_executable(example5 ${EXAMPLE5_SRC_LIST}) - target_link_libraries(example5 miniz) - add_executable(example6 ${EXAMPLE6_SRC_LIST}) - target_link_libraries(example6 miniz) - if(${UNIX}) - target_link_libraries(example6 m) + foreach(X example1 example2 example3 example4 example5 example6) + add_executable(${X} "examples/${X}.c") + target_link_libraries(${X} miniz) + if(MSVC) + # warning C4996: This function or variable may be unsafe. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. + target_compile_definitions(${X} PRIVATE _CRT_SECURE_NO_WARNINGS) + endif() + endforeach(X) + if(UNIX) + target_link_libraries(example6 m) endif() - # add_executable(miniz_tester ${MINIZ_TESTER_SRC_LIST}) + # add_executable(miniz_tester tests/miniz_tester.cpp tests/timer.cpp) # target_link_libraries(miniz_tester miniz) endif(BUILD_EXAMPLES)