Skip to content

Commit

Permalink
temp save
Browse files Browse the repository at this point in the history
  • Loading branch information
yobeonline committed Aug 13, 2024
1 parent 050b93d commit dcfe9b8
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 78 deletions.
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
[submodule "unit_test_for_cmake"]
path = unit_test_for_cmake
url = ../unit_test_for_cmake.git
15 changes: 15 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
cmake_minimum_required(VERSION 3.19)

project(test_add_target)

include(add_target.cmake)

include(FetchContent)
FetchContent_Declare(
cmake_test
GIT_REPOSITORY https://github.com/CMakePP/CMakeTest
)
FetchContent_MakeAvailable(cmake_test)
include(cmake_test/cmake_test)

ct_add_dir("${CMAKE_CURRENT_SOURCE_DIR}/test")
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ endif()

```cmake
add_target(<name>
STATIC|SHARED|HEADER_ONLY|EXECUTABLE <source> …
STATIC|SHARED|HEADER_ONLY|EXECUTABLE|WIN32_EXECUTABLE <source> …
[INCLUDES <folder> … ]
[DEPENDENCIES <target> <lib> … ]
[OPTIONS <flag> … ]
Expand All @@ -82,7 +82,9 @@ The target `<name>` is created as if the following commands were called.
- `add_library(<name> STATIC <source> …)` for `STATIC`,
- `add_library(<name> SHARED <source> …)` for `SHARED`,
- `add_library(<name> INTERFACE <source> …)` for `HEADER_ONLY`,
- `add_executable(<name> <source> …)` for `EXECUTABLE`.
- `add_executable(<name> <source> …)` for `EXECUTABLE`,
- `add_executable(<name> WIN32 <source> …)` for `WIN32_EXECUTABLE`,
- `add_library(<name> <source> …)` if no type is provided.

### Target Configuration

Expand Down
12 changes: 7 additions & 5 deletions add_target.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.18)
include_guard()

if(COMMAND add_target)
message(
Expand All @@ -16,7 +16,7 @@ function(add_target target_name)
)
endif()

set(options "STATIC;SHARED;EXECUTALBE;HEADER_ONLY")
set(options "STATIC;SHARED;EXECUTALBE;WIN32_EXECUTABLE;HEADER_ONLY")
set(multivalue_keywords
"INCLUDES;DEPENDENCIES;OPTIONS;DEFINITIONS;FEATURES;BOOST_TEST;GOOGLE_TEST"
)
Expand All @@ -32,9 +32,7 @@ function(add_target target_name)
endif()
endforeach()
list(LENGTH found_option found_option_count)
if(found_option_count EQUAL 0)
message(FATAL_ERROR "${CMAKE_CURRENT_FUNCTION}: missing target type.")
elseif(NOT found_option_count EQUAL 1)
if(NOT found_option_count LESS_EQUAL 1)
message(
FATAL_ERROR
"${CMAKE_CURRENT_FUNCTION}: cannot define multiple target types.")
Expand All @@ -52,6 +50,10 @@ function(add_target target_name)
add_executable(${target_name} ${sources})
elseif(io1_HEADER_ONLY)
add_library(${target_name} INTERFACE ${sources})
elseif (io1_WIN32_EXECUTABLE)
add_executable(${target_name} WIN32 ${sources})
else()
add_library(${target_name} ${sources})
endif()

# apply source files properties and groups
Expand Down
64 changes: 64 additions & 0 deletions test/parse_file_options.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
ct_add_test(NAME main)
function(${CMAKETEST_TEST})
parse_file_options("test.cpp" file options)
ct_assert_equal(file "test.cpp")
ct_assert_not_defined(options)

parse_file_options("test.cpp:toto" file options)
ct_assert_equal(file "test.cpp")
ct_assert_equal(options, "toto")

parse_file_options("test.cpp:toto,tata" file options)
ct_assert_equal(file "test.cpp")
ct_assert_equal(options, "toto;tata")

parse_file_options("test.cpp" file options)
ct_assert_equal(file "test.cpp")
ct_assert_not_defined(options)

parse_file_options("" file options)
ct_assert_not_defined(file)
ct_assert_not_defined(options)

parse_file_options(":" file options)
ct_assert_not_defined(file)
ct_assert_not_defined(options)

parse_file_options("test.cpp:" file options)
ct_assert_equal(file "test.cpp")
ct_assert_not_defined(options)

parse_file_options(":toto" file options)
ct_assert_not_defined(file)
ct_assert_not_defined(options)
endfunction()


# Using same variable names as in function definition because some
# implementations may break in this case.
ct_add_test(NAME same_variable_names)
function(${CMAKETEST_TEST})
parse_file_options("test.cpp" out_file out_options)
ct_assert_equal(out_file "test.cpp")
ct_assert_not_defined(out_options)

parse_file_options("test.cpp:toto" out_file out_options)
ct_assert_equal(out_file "test.cpp")
ct_assert_equal(out_options "toto")

parse_file_options("test.cpp" out_file out_options)
ct_assert_equal(out_file "test.cpp")
ct_assert_not_defined(out_options "toto")

parse_file_options(":" out_file out_options)
ct_assert_not_defined(out_file)
ct_assert_not_defined(out_options)

parse_file_options("test.cpp:" out_file out_options)
ct_assert_equal(out_file "test.cpp")
ct_assert_not_defined(out_options)

parse_file_options(":toto" out_file out_options)
ct_assert_not_defined(out_file)
ct_assert_not_defined(out_options)
endfunction()
67 changes: 0 additions & 67 deletions test_parse_file_options.cmake

This file was deleted.

1 change: 0 additions & 1 deletion unit_test_for_cmake
Submodule unit_test_for_cmake deleted from 59c4f8

0 comments on commit dcfe9b8

Please sign in to comment.