mimalloc/test/CMakeLists.txt
Pei-Hsuan Hung 4486efa01b Avoid system environment path in find_package
If the project root directory lies in user's home directory,
`find_package` will search the project directory instead of the
installed path.

For example, if one's project directory is /home/user1/mimalloc,
`find_package` will first search the prefix `$PATH`, then search
`CMAKE_INSTALL_PREFIX` if no file is found in previous path.

If one clones the project in `${HOME}` and added `${HOME}/bin` to
`${PATH}` (which is common), the error could happen.

To avoid this, we could simply add NO_SYSTEM_ENVIONMENT_PATH to
the end of `find_package`.
2019-07-07 10:12:09 +08:00

29 lines
973 B
CMake

cmake_minimum_required(VERSION 3.0)
project(mimalloc-test C CXX)
# Set default build type
if (NOT CMAKE_BUILD_TYPE)
if ("${CMAKE_BINARY_DIR}" MATCHES ".*(D|d)ebug$")
message(STATUS "No build type selected, default to *** Debug ***")
set(CMAKE_BUILD_TYPE "Debug")
else()
message(STATUS "No build type selected, default to *** Release ***")
set(CMAKE_BUILD_TYPE "Release")
endif()
endif()
# Import mimalloc (if installed)
find_package(mimalloc 1.0 REQUIRED NO_SYSTEM_ENVIRONMENT_PATH)
# Tests
add_executable(static-override main-override.c)
target_link_libraries(static-override PUBLIC mimalloc-static)
add_executable(static-override-cxx main-override.cpp)
target_link_libraries(static-override-cxx PUBLIC mimalloc-static)
add_executable(dynamic-override main-override.c)
target_link_libraries(dynamic-override PUBLIC mimalloc)
add_executable(dynamic-override-cxx main-override.cpp)
target_link_libraries(dynamic-override-cxx PUBLIC mimalloc)