From a37f49f4155b772346d867420e5a96e2397f849d Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Mon, 30 Jan 2023 16:36:24 +0800 Subject: [PATCH] build: enhance cmake build options --- CMakeLists.txt | 19 ++++++++++--------- src/klotski_core/CMakeLists.txt | 8 +++++++- test/CMakeLists.txt | 33 ++++++++++++++++++++++++--------- test/{ => basic}/all_cases.cc | 0 test/{ => basic}/utils.cc | 0 test/{ => codec}/common_code.cc | 0 test/{ => codec}/raw_code.cc | 0 test/{ => codec}/short_code.cc | 0 8 files changed, 41 insertions(+), 19 deletions(-) rename test/{ => basic}/all_cases.cc (100%) rename test/{ => basic}/utils.cc (100%) rename test/{ => codec}/common_code.cc (100%) rename test/{ => codec}/raw_code.cc (100%) rename test/{ => codec}/short_code.cc (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index ae8ac65..2d06c59 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,6 @@ cmake_minimum_required(VERSION 3.0) project(klotski) -#set(CMAKE_CXX_STANDARD 14) if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Release) @@ -9,6 +8,8 @@ endif() set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra") +################################################################################ + set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin) @@ -18,15 +19,15 @@ file( FOLLOW_SYMLINK_CHAIN ) -# TODO: only in libklotski.so -add_compile_options(-fPIC) - add_subdirectory(src) -################################################ +################################################################################ -include_directories(third_party/googletest/googletest/include) -add_subdirectory(third_party/googletest EXCLUDE_FROM_ALL) -add_subdirectory(test) +option(CORE_TEST "build test for klotski core" ON) +#if (CORE_TEST) + include_directories(third_party/googletest/googletest/include) + add_subdirectory(third_party/googletest EXCLUDE_FROM_ALL) + add_subdirectory(test) +#endif() -################################################ +################################################################################ diff --git a/src/klotski_core/CMakeLists.txt b/src/klotski_core/CMakeLists.txt index 628f908..56adcb1 100644 --- a/src/klotski_core/CMakeLists.txt +++ b/src/klotski_core/CMakeLists.txt @@ -6,6 +6,13 @@ project(klotski-core VERSION 0.1.2 LANGUAGES CXX) ################################################################################ +option(BUILD_DYN "build shared klotski core library" OFF) +if (BUILD_DYN) + add_compile_options(-fPIC) +endif() + +################################################################################ + macro(git_tag _tag) find_package(Git QUIET) if (GIT_FOUND) @@ -122,7 +129,6 @@ list(APPEND OBJS $) ################################################################################ -option(BUILD_DYN "build shared klotski core library" OFF) if (BUILD_DYN) add_library(klotski SHARED ${OBJS}) else() diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index fb7085d..2701fc0 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,32 +1,47 @@ cmake_minimum_required(VERSION 3.0) -################################################################ +################################################################################ enable_testing() set(TEST_DEPS gtest gtest_main klotski) -################################################################ +################################################################################ unset(CMAKE_ARCHIVE_OUTPUT_DIRECTORY) include_directories(../third_party/md5) add_library(md5 STATIC ../third_party/md5/md5.cpp) -################################################################ +################################################################################ include_directories(../src/klotski_core/utils) include_directories(../src/klotski_core/all_cases) +set(TEST_BASIC_SRC utils.cc all_cases.cc) +list(TRANSFORM TEST_BASIC_SRC PREPEND "basic/") +add_executable(test_basic ${TEST_BASIC_SRC}) +#add_executable(test_basic +# basic/utils.cc +# basic/all_cases.cc +#) +target_link_libraries(test_basic PUBLIC ${TEST_DEPS} md5) +add_test(NAME basic COMMAND test_basic) + +################################################################################ + include_directories(../src/klotski_core/raw_code) include_directories(../src/klotski_core/short_code) include_directories(../src/klotski_core/common_code) -add_executable(test_basic utils.cc all_cases.cc) -target_link_libraries(test_basic PUBLIC ${TEST_DEPS} md5) -add_test(NAME basic COMMAND test_basic) - -add_executable(test_codec short_code.cc raw_code.cc common_code.cc) +set(TEST_CODEC_SRC short_code.cc raw_code.cc common_code.cc) +list(TRANSFORM TEST_CODEC_SRC PREPEND "codec/") +add_executable(test_codec ${TEST_CODEC_SRC}) +#add_executable(test_codec +# codec/short_code.cc +# codec/common_code.cc +# codec/raw_code.cc +#) target_link_libraries(test_codec ${TEST_DEPS}) add_test(NAME codec COMMAND test_codec) -################################################################ +################################################################################ diff --git a/test/all_cases.cc b/test/basic/all_cases.cc similarity index 100% rename from test/all_cases.cc rename to test/basic/all_cases.cc diff --git a/test/utils.cc b/test/basic/utils.cc similarity index 100% rename from test/utils.cc rename to test/basic/utils.cc diff --git a/test/common_code.cc b/test/codec/common_code.cc similarity index 100% rename from test/common_code.cc rename to test/codec/common_code.cc diff --git a/test/raw_code.cc b/test/codec/raw_code.cc similarity index 100% rename from test/raw_code.cc rename to test/codec/raw_code.cc diff --git a/test/short_code.cc b/test/codec/short_code.cc similarity index 100% rename from test/short_code.cc rename to test/codec/short_code.cc