try to fix MacOS build failure at appveyor
[mfgtools.git] / uuu / CMakeLists.txt
blob820e99cecea950b200b2ba945434c95dfd4f45e3
1 cmake_minimum_required(VERSION 3.4)
3 set(CMAKE_CXX_STANDARD 14)
4 set(CMAKE_CXX_STANDARD_REQUIRED ON)
5 set(CMAKE_SKIP_RPATH ON)
7 find_package(PkgConfig REQUIRED)
8 pkg_check_modules(LIBUSB REQUIRED libusb-1.0>=1.0.16)
9 pkg_check_modules(LIBZ REQUIRED zlib)
10 pkg_check_modules(LIBZSTD REQUIRED libzstd)
11 find_package(Threads)
13 if (STATIC)
14 set(OPENSSL_USE_STATIC_LIBS TRUE)
15 endif()
17 find_package(OpenSSL)
19 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread -O2")
21 if (STATIC)
22 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libstdc++ -static-libgcc")
23 endif()
25 set(LSTS
26         uuu.lst
27         emmc_burn_loader.lst
28         emmc_burn_all.lst
29         fat_write.lst
30         qspi_burn_loader.lst
31         sd_burn_loader.lst
32         spl_boot.lst
33         sd_burn_all.lst
34         nand_burn_loader.lst
37 link_directories(${CMAKE_CURRENT_SOURCE_DIR}/libuuu ${LIBUSB_LIBRARY_DIRS} ${LIBZSTD_LIBRARY_DIRS} ${LIBZ_LIBRARY_DIRS})
39 set(CLIST_EXECUTABLE ${CMAKE_CURRENT_SOURCE_DIR}/gen_txt_include.sh)
40 set(generated_files_dir "${CMAKE_BINARY_DIR}/uuu/gen")
42 function(preprocess_clst out_var)
43         set(result)
44         foreach(in_f ${ARGN})
45                 set(out_f "${generated_files_dir}/${in_f}")
46                 string(REPLACE ".lst" ".clst" out_f ${out_f})
47                 add_custom_command(OUTPUT ${out_f}
48                         PRE_BUILD
49                                 COMMAND mkdir -p ${generated_files_dir}
50                         COMMAND ${CLIST_EXECUTABLE} ${in_f} ${out_f}
51                         DEPENDS ${in_f}
52                         WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
53                         COMMENT "Creating preprocessed clst file ${out_f}"
54                         VERBATIM
55                 )
56                 list(APPEND result ${out_f})
57         endforeach()
58         set(${out_var} "${result}" PARENT_SCOPE)
59 endfunction()
61 preprocess_clst(CLSTS ${LSTS})
63 include_directories(${generated_files_dir})
65 set(SOURCES
66         uuu.cpp
67         buildincmd.cpp
68         autocomplete.cpp
69         ${CLSTS}
72 add_executable(uuu ${SOURCES})
73 target_link_libraries(uuu uuc_s ${OPENSSL_LIBRARIES} ${LIBUSB_LIBRARIES} ${LIBZ_LIBRARIES} ${LIBZSTD_LIBRARIES}  dl bz2)
75 install(TARGETS uuu DESTINATION bin)
76 target_compile_definitions(uuu
77     PRIVATE "TARGET_PATH=\"${CMAKE_INSTALL_PREFIX}/bin/uuu\""