Skip to content

Commit

Permalink
Merge pull request #86 from arkedge/feature/refactor-cmake-option
Browse files Browse the repository at this point in the history
Pre Release (v4.0.0-beta.2): Refactor cmake option
  • Loading branch information
sksat authored Oct 10, 2023
2 parents 964c8f4 + 6a32752 commit 46a8495
Show file tree
Hide file tree
Showing 30 changed files with 89 additions and 63 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build_with_s2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ jobs:
with:
path: s2e-user
repository: ut-issl/s2e-user-for-c2a-core
ref: ae-v3.0.0 # TODO: import s2e-user-for-c2a-core to c2a-core
fetch-depth: 1

- name: checkout C2A user
Expand Down
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,19 @@
- import したバージョン: [ut-issl/c2a-enum-loader ae-v2.0.0](https://github.com/ut-issl/c2a-enum-loader/releases/tag/ae-v2.0.0)
- [ut-issl/c2a-tlm-cmd-code-generator](https://github.com/ut-issl/c2a-tlm-cmd-code-generator) を c2a-core リポジトリで管理するように変更: [#111](https://github.com/arkedge/c2a-core/pull/111)
- import したバージョン: [ut-issl/c2a-tlm-cmd-code-generator ae-v2.0.0](https://github.com/ut-issl/c2a-tlm-cmd-code-generator/releases/tag/ae-v2.0.0)
- CMake option の整理: [#86](https://github.com/arkedge/c2a-core/pull/86)
- `C2A_` prefix に統一した(これはコーディング規約にも追加)
- 意味が分かりにくい命名の変更,今後 optional としていく挙動を default OFF とした
- `option()` の挙動はユーザ指定によってかなり変わるため,該当する変更は単なるビルドチェックなどではなくすべて grep して変更すること
- `BUILD_C2A_AS_UTF8` -> `C2A_BUILD_AS_UTF8`
- `BUILD_C2A_AS_C99` -> `C2A_BUILD_AS_C99`
- `BUILD_C2A_AS_CXX` -> `C2A_BUILD_AS_CXX`
- `(NOT USE_32BIT_COMPILER)` -> `C2A_BUILD_FOR_32BIT`: `ON` の時に明示的に 32bit ターゲットとしてビルドする(`-m32` をつける)
- `(NOT C2A_USE_STDINT_WRAPPER)` -> `C2A_USE_STDINT_WRAPPER`: C89 ターゲットでビルドする際に `ON` にすることでユーザ定義の `stdint.h` を使う
- `BUILD_C2A_AS_SILS_FW` -> `C2A_BUILD_FOR_SILS`
- `USE_ALL_C2A_CORE_APPS` -> `C2A_USE_ALL_CORE_APPS`
- `USE_ALL_C2A_CORE_TEST_APPS` -> `C2A_USE_ALL_CORE_TEST_APPS`
- `USE_ALL_C2A_CORE_LIB` -> `C2A_USE_ALL_CORE_LIB`


### Enhancements
Expand Down
40 changes: 23 additions & 17 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,25 @@ cmake_minimum_required(VERSION 3.13)

project(C2A_CORE)

# user config
option(USE_ALL_C2A_CORE_APPS "use C2A-core all Applications" ON)
option(USE_ALL_C2A_CORE_TEST_APPS "use C2A-core all Test Applications" ON)
option(USE_ALL_C2A_CORE_LIB "use C2A-core all library" ON)
option(USE_32BIT_COMPILER "use 32bit compiler" OFF)
# Build option
## C2A compile config
option(C2A_BUILD_AS_UTF8 "Build C2A as UTF-8" ON)
option(C2A_BUILD_AS_C99 "Build C2A as C99" OFF)
option(C2A_BUILD_AS_CXX "Build C2A as C++" OFF)

option(C2A_USE_SIMPLE_LIBC "use C2A-core hosted simple libc implementation" OFF)
option(C2A_USE_C99_STDINT "use C99 standard stdint.h" ON)
option(C2A_BUILD_FOR_32BIT "Build C2A for 32bit target(this will add -m32 option)" ON)

option(BUILD_C2A_AS_SILS_FW "build C2A as SILS firmware" ON)
option(BUILD_C2A_AS_C99 "build C2A as C99" OFF)
option(BUILD_C2A_AS_CXX "build C2A as C++" OFF)
option(BUILD_C2A_AS_UTF8 "build C2A as UTF-8" ON)
## C2A
option(C2A_USE_STDINT_WRAPPER "Use stdint.h wrapper for C89" OFF)

option(C2A_BUILD_FOR_SILS "Build C2A for SILS target" ON)

## C2A core library select
option(C2A_USE_ALL_CORE_APPS "Use C2A-core all Applications" ON)
option(C2A_USE_ALL_CORE_TEST_APPS "Use C2A-core all Test Applications" ON)
option(C2A_USE_ALL_CORE_LIB "Use C2A-core all library" ON)

option(C2A_USE_SIMPLE_LIBC "Use C2A-core hosted simple libc (c2a-core/library/libc) implementation" OFF)

set(C2A_CORE_DIR ${CMAKE_CURRENT_SOURCE_DIR})

Expand Down Expand Up @@ -52,8 +58,8 @@ set(C2A_SRCS
tlm_cmd/ccsds/tlm_space_packet.c
)

if(NOT C2A_USE_C99_STDINT)
message("Use stdint.h wrapper")
if(C2A_USE_STDINT_WRAPPER)
message("Use stdint.h wrapper for C89")
include_directories(library/stdint_wrapper)
endif()

Expand All @@ -72,23 +78,23 @@ execute_process(
add_definitions("-DGIT_REVISION_C2A_CORE=\"${GIT_REVISION_C2A_CORE}\"")
add_definitions("-DGIT_REVISION_C2A_CORE_SHORT=0x${GIT_REVISION_C2A_CORE_SHORT}")

if(BUILD_C2A_AS_CXX)
if(C2A_BUILD_AS_CXX)
set_source_files_properties(${C2A_SRCS} PROPERTIES LANGUAGE CXX) # C++
endif()

add_library(${PROJECT_NAME} OBJECT ${C2A_SRCS})

if(USE_ALL_C2A_CORE_APPS)
if(C2A_USE_ALL_CORE_APPS)
add_subdirectory(applications)
target_sources(${PROJECT_NAME} PUBLIC $<TARGET_OBJECTS:C2A_CORE_APPS>)
endif()

if(USE_ALL_C2A_CORE_TEST_APPS)
if(C2A_USE_ALL_CORE_TEST_APPS)
add_subdirectory(applications/test_app)
target_sources(${PROJECT_NAME} PUBLIC $<TARGET_OBJECTS:C2A_CORE_TEST_APPS>)
endif()

if(USE_ALL_C2A_CORE_LIB)
if(C2A_USE_ALL_CORE_LIB)
add_subdirectory(library)
target_sources(${PROJECT_NAME} PUBLIC $<TARGET_OBJECTS:C2A_CORE_LIB>)
endif()
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace.package]
version = "4.0.0-beta.1"
version = "4.0.0-beta.2"

[workspace]
resolver = "2"
Expand Down
2 changes: 1 addition & 1 deletion applications/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ set(C2A_SRCS
telemetry_manager.c
)

if(BUILD_C2A_AS_CXX)
if(C2A_BUILD_AS_CXX)
set_source_files_properties(${C2A_SRCS} PROPERTIES LANGUAGE CXX) # C++
endif()

Expand Down
2 changes: 1 addition & 1 deletion applications/test_app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ set(C2A_SRCS
test_ccp_util.c
)

if(BUILD_C2A_AS_CXX)
if(C2A_BUILD_AS_CXX)
set_source_files_properties(${C2A_SRCS} PROPERTIES LANGUAGE CXX) # C++
endif()

Expand Down
2 changes: 1 addition & 1 deletion c2a_core_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ void C2A_core_main(void);
#define C2A_CORE_VER_MAJOR (4)
#define C2A_CORE_VER_MINOR (0)
#define C2A_CORE_VER_PATCH (0)
#define C2A_CORE_VER_PRE ("beta.1")
#define C2A_CORE_VER_PRE ("beta.2")

#endif
12 changes: 6 additions & 6 deletions common.cmake
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
if(BUILD_C2A_AS_CXX)
if(C2A_BUILD_AS_CXX)
# memo: set_source_files_properties() must be set before add_library/add_executable on Visual Studio CMake
set_source_files_properties(${C2A_SRCS} PROPERTIES LANGUAGE CXX) # C++
else()
if(BUILD_C2A_AS_C99)
if(C2A_BUILD_AS_C99)
set_target_properties(${PROJECT_NAME} PROPERTIES C_STANDARD 99) # C99
else()
if (CMAKE_C_COMPILER_ID STREQUAL "Clang")
Expand All @@ -20,18 +20,18 @@ else()
endif()
endif()

if(BUILD_C2A_AS_SILS_FW)
if(C2A_BUILD_FOR_SILS )
target_compile_definitions(${PROJECT_NAME} PUBLIC SILS_FW)
endif()

# Build option
if(MSVC)
target_compile_options(${PROJECT_NAME} PUBLIC "/W4")
target_compile_options(${PROJECT_NAME} PUBLIC "/MT")
if(BUILD_C2A_AS_CXX)
if(C2A_BUILD_AS_CXX)
target_compile_options(${PROJECT_NAME} PUBLIC "/TP") # Compile C codes as C++
endif()
if(BUILD_C2A_AS_UTF8)
if(C2A_BUILD_AS_UTF8)
target_compile_options(${PROJECT_NAME} PUBLIC "/source-charset:utf-8")
endif()

Expand All @@ -45,7 +45,7 @@ else()
# endif()

# 32bit
if(NOT USE_32BIT_COMPILER)
if(C2A_BUILD_FOR_32BIT)
target_compile_options(${PROJECT_NAME} PUBLIC "-m32")
target_link_options(${PROJECT_NAME} PRIVATE "-m32")
endif()
Expand Down
6 changes: 6 additions & 0 deletions docs/general/coding_rule.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,12 @@ typedef uint32_t flash_block_t;


## 個別箇所についての命名など [M]
### CMake option
- 大文字の snake case
- 接頭辞は `C2A_` で統一する
- 特定の C2A user 固有のものや,C2A 以外の文脈が含まれる場合は必須ではない


### applications/user_defined
- ファイル名と AppInfo 構造体名を一致させる(スタイルを除く)
- AppInfo 構造体名とそのインスタンス名を一致させる(スタイルを除く)
Expand Down
6 changes: 3 additions & 3 deletions docs/sils/s2e_integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ C2A 標準 SILS として, S2E (FIXME: 公開後にリンクを貼る) とい
これにより,フライトソフトウェアである C2A を S2E 内部で動かすことが可能である.
詳細はS2Eドキュメント (TBA) を参照のこと.

現行の S2E では C2A を C++ としてビルドしなければならないため,その際は `BUILD_C2A_AS_CXX` というオプションを使用してビルドする.
現行の S2E では C2A を C++ としてビルドしなければならないため,その際は `C2A_BUILD_AS_CXX` というオプションを使用してビルドする.
[オプションの追加経緯](https://github.com/ut-issl/c2a-core/pull/35)

具体的には, S2E 側の `CMakeLists.txt` を次のようにする.
```
set(BUILD_C2A_AS_CXX ON)
add_subdirectory(${C2A_DIR} C2A_CORE)
set(C2A_BUILD_AS_CXX ON)
add_subdirectory(${C2A_DIR} C2A)
```
10 changes: 5 additions & 5 deletions examples/mobc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ option(USE_SCI_COM_UART "Use SCI_COM_UART" OFF)

option(USE_SILS_MOCKUP "Use SILS mockup for build C2A with minimal user in C89 only" OFF)

option(BUILD_C2A_AS_SILS_FW "Build C2A as SILS firmware" ON)
option(C2A_BUILD_FOR_SILS "Build C2A for SILS target" ON)

if(USE_SILS_MOCKUP)
set(BUILD_C2A_AS_CXX OFF)
set(C2A_BUILD_AS_CXX OFF)
endif()

if(BUILD_C2A_AS_CXX)
message("build C2A as C++!")
if(C2A_BUILD_AS_CXX)
message("Build C2A as C++!")
endif()

set(C2A_CORE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src/src_core)
Expand Down Expand Up @@ -69,7 +69,7 @@ set(C2A_SRCS
${C2A_USER_DIR}/c2a_main.c
)

if(BUILD_C2A_AS_CXX)
if(C2A_BUILD_AS_CXX)
message("Build as C++!!!")
set_source_files_properties(${C2A_SRCS} PROPERTIES LANGUAGE CXX) # C++
endif()
Expand Down
6 changes: 3 additions & 3 deletions examples/mobc/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ fn main() {
let mut c2a_cmake = cmake::Config::new(".");
let libc2a = c2a_cmake
.very_verbose(true)
.define("USE_32BIT_COMPILER", "ON")
.define("BUILD_C2A_AS_C99", "ON")
.define("BUILD_C2A_AS_SILS_FW", "ON")
.define("C2A_BUILD_FOR_32BIT", "OFF")
.define("C2A_BUILD_AS_C99", "ON")
.define("C2A_BUILD_FOR_SILS", "ON")
.define("USE_SCI_COM_WINGS", "OFF")
.build_target("C2A");

Expand Down
2 changes: 1 addition & 1 deletion examples/mobc/src/s2e_mockup/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ set(C2A_DIR ../..)
# include_directories
include_directories(${C2A_DIR}/src)
# add subdirectory
set(BUILD_C2A_AS_CXX ON) # Build C2A as C++
set(C2A_BUILD_AS_CXX ON) # Build C2A as C++
add_subdirectory(${C2A_DIR} C2A)

add_executable(${PROJECT_NAME} main.cpp)
Expand Down
2 changes: 1 addition & 1 deletion examples/mobc/src/src_user/Drivers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ set(C2A_SRCS
Etc/uart_test.c
)

if(BUILD_C2A_AS_CXX)
if(C2A_BUILD_AS_CXX)
set_source_files_properties(${C2A_SRCS} PROPERTIES LANGUAGE CXX) # C++
endif()

Expand Down
2 changes: 1 addition & 1 deletion examples/mobc/src/src_user/Settings/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ set(C2A_SRCS
tlm_cmd/ccsds/apid_define.c
)

if(BUILD_C2A_AS_CXX)
if(C2A_BUILD_AS_CXX)
set_source_files_properties(${C2A_SRCS} PROPERTIES LANGUAGE CXX) # C++
endif()

Expand Down
2 changes: 1 addition & 1 deletion examples/mobc/src/src_user/applications/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ set(C2A_SRCS
user_defined/debug_apps.c
)

if(BUILD_C2A_AS_CXX)
if(C2A_BUILD_AS_CXX)
set_source_files_properties(${C2A_SRCS} PROPERTIES LANGUAGE CXX) # C++
endif()

Expand Down
2 changes: 1 addition & 1 deletion examples/mobc/src/src_user/hal/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ set(C2A_SRCS
${C2A_HAL_IMPL_SRCS}
)

if(BUILD_C2A_AS_CXX)
if(C2A_BUILD_AS_CXX)
set_source_files_properties(${C2A_SRCS} PROPERTIES LANGUAGE CXX) # C++
endif()

Expand Down
2 changes: 1 addition & 1 deletion examples/mobc/src/src_user/library/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ set(C2A_SRCS
vt100.c
)

if(BUILD_C2A_AS_CXX)
if(C2A_BUILD_AS_CXX)
set_source_files_properties(${C2A_SRCS} PROPERTIES LANGUAGE CXX) # C++
endif()

Expand Down
2 changes: 1 addition & 1 deletion examples/mobc/src/src_user/tlm_cmd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ set(C2A_SRCS
ccsds/vcdu.c
)

if(BUILD_C2A_AS_CXX)
if(C2A_BUILD_AS_CXX)
set_source_files_properties(${C2A_SRCS} PROPERTIES LANGUAGE CXX) # C++
endif()

Expand Down
12 changes: 6 additions & 6 deletions examples/subobc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ option(USE_SCI_COM_WINGS "Use SCI_COM_WINGS" ON)

option(USE_SILS_MOCKUP "Use SILS mockup for build C2A with minimal user in C89 only" OFF)

option(BUILD_C2A_AS_SILS_FW "Build C2A as SILS firmware" ON)
option(C2A_BUILD_FOR_SILS "Build C2A for SILS target" ON)

set(USE_ALL_C2A_CORE_APPS OFF)
# Core App のターゲット追加は src_user/applications/CMakeLists.txt で行う
set(USE_ALL_C2A_CORE_TEST_APPS OFF)
set(C2A_USE_ALL_CORE_APPS OFF)
set(C2A_USE_ALL_CORE_TEST_APPS OFF)

if(USE_SILS_MOCKUP)
set(BUILD_C2A_AS_CXX OFF)
set(C2A_BUILD_AS_CXX OFF)
endif()

if(BUILD_C2A_AS_CXX)
if(C2A_BUILD_AS_CXX)
message("build C2A as C++!")
endif()

Expand Down Expand Up @@ -67,7 +67,7 @@ set(C2A_SRCS
${C2A_USER_DIR}/c2a_main.c
)

if(BUILD_C2A_AS_CXX)
if(C2A_BUILD_AS_CXX)
message("Build as C++!!!")
set_source_files_properties(${C2A_SRCS} PROPERTIES LANGUAGE CXX) # C++
endif()
Expand Down
6 changes: 3 additions & 3 deletions examples/subobc/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ fn main() {
let mut c2a_cmake = cmake::Config::new(".");
let libc2a = c2a_cmake
.very_verbose(true)
.define("USE_32BIT_COMPILER", "ON")
.define("BUILD_C2A_AS_C99", "ON")
.define("BUILD_C2A_AS_SILS_FW", "ON")
.define("C2A_BUILD_FOR_32BIT", "ON")
.define("C2A_BUILD_AS_C99", "ON")
.define("C2A_BUILD_FOR_SILS ", "ON")
.define("USE_SCI_COM_WINGS", "OFF")
.build_target("C2A");

Expand Down
2 changes: 1 addition & 1 deletion examples/subobc/src/s2e_mockup/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ set(C2A_DIR ../..)
# include_directories
include_directories(${C2A_DIR}/src)
# add subdirectory
set(BUILD_C2A_AS_CXX ON) # Build C2A as C++
set(C2A_BUILD_AS_CXX ON) # Build C2A as C++
add_subdirectory(${C2A_DIR} C2A)

add_executable(${PROJECT_NAME} main.cpp)
Expand Down
2 changes: 1 addition & 1 deletion examples/subobc/src/src_user/Drivers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ set(C2A_SRCS
Etc/mobc.c
)

if(BUILD_C2A_AS_CXX)
if(C2A_BUILD_AS_CXX)
set_source_files_properties(${C2A_SRCS} PROPERTIES LANGUAGE CXX) # C++
endif()

Expand Down
2 changes: 1 addition & 1 deletion examples/subobc/src/src_user/Settings/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ set(C2A_SRCS
tlm_cmd/ccsds/apid_define.c
)

if(BUILD_C2A_AS_CXX)
if(C2A_BUILD_AS_CXX)
set_source_files_properties(${C2A_SRCS} PROPERTIES LANGUAGE CXX) # C++
endif()

Expand Down
2 changes: 1 addition & 1 deletion examples/subobc/src/src_user/applications/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ set(C2A_SRCS
${C2A_CORE_DIR}/applications/timeline_command_dispatcher.c
)

if(BUILD_C2A_AS_CXX)
if(C2A_BUILD_AS_CXX)
set_source_files_properties(${C2A_SRCS} PROPERTIES LANGUAGE CXX) # C++
endif()

Expand Down
Loading

0 comments on commit 46a8495

Please sign in to comment.