Skip to content

Commit

Permalink
[#145] Updated build flags and CMakeLists;
Browse files Browse the repository at this point in the history
  • Loading branch information
jlucas9 committed Apr 27, 2023
1 parent d4a40b4 commit bb71561
Show file tree
Hide file tree
Showing 12 changed files with 86 additions and 108 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -B ${{github.workspace}}/build -DDEBUG=1 -DMYSQL=0 -DLIBGCRYPT=1 -DKMCCRYPTO=0
run: cmake -B ${{github.workspace}}/build -DDEBUG=1 -DSA_MARIADB=0 -DCRYPTO_LIBGCRYPT=1 -DCRYPTO_KMC=0

- name: Build
# Build your program with the given configuration
Expand All @@ -49,7 +49,7 @@ jobs:
- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -B ${{github.workspace}}/build -DDEBUG=0 -DMYSQL=0 -DLIBGCRYPT=1 -DKMCCRYPTO=0
run: cmake -B ${{github.workspace}}/build -DDEBUG=0 -DSA_MARIADB=0 -DCRYPTO_LIBGCRYPT=1 -DCRYPTO_KMC=0

- name: Build
# Build your program with the given configuration
Expand All @@ -75,7 +75,7 @@ jobs:
- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -B ${{github.workspace}}/build -DDEBUG=1 -DMYSQL=1 -DLIBGCRYPT=1 -DKMCCRYPTO=0
run: cmake -B ${{github.workspace}}/build -DDEBUG=1 -DSA_MARIADB=1 -DCRYPTO_LIBGCRYPT=1 -DCRYPTO_KMC=0

- name: Build
# Build your program with the given configuration
Expand All @@ -101,7 +101,7 @@ jobs:
- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -B ${{github.workspace}}/build -DDEBUG=0 -DMYSQL=1 -DLIBGCRYPT=1 -DKMCCRYPTO=0
run: cmake -B ${{github.workspace}}/build -DDEBUG=0 -DSA_MARIADB=1 -DCRYPTO_LIBGCRYPT=1 -DCRYPTO_KMC=0

- name: Build
# Build your program with the given configuration
Expand All @@ -127,7 +127,7 @@ jobs:
- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -B ${{github.workspace}}/build -DDEBUG=1 -DMYSQL=1 -DLIBGCRYPT=1 -DKMCCRYPTO=1
run: cmake -B ${{github.workspace}}/build -DDEBUG=1 -DSA_MARIADB=1 -DCRYPTO_LIBGCRYPT=1 -DCRYPTO_KMC=1

- name: Build
# Build your program with the given configuration
Expand All @@ -153,7 +153,7 @@ jobs:
- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -B ${{github.workspace}}/build -DDEBUG=0 -DMYSQL=1 -DLIBGCRYPT=1 -DKMCCRYPTO=1
run: cmake -B ${{github.workspace}}/build -DDEBUG=0 -DSA_MARIADB=1 -DCRYPTO_LIBGCRYPT=1 -DCRYPTO_KMC=1

- name: Build
# Build your program with the given configuration
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/mariadb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -B ${{github.workspace}}/build -DDEBUG=1 -DMYSQL=1 -DLIBGCRYPT=1 -DKMCCRYPTO=0
run: cmake -B ${{github.workspace}}/build -DDEBUG=1 -DSA_MARIADB=1 -DCRYPTO_LIBGCRYPT=1 -DCRYPTO_KMC=0

- name: Build
# Build your program with the given configuration
Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/utest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,3 @@ jobs:
# Execute tests defined by the CMake configuration.
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
run: ${{github.workspace}}/build/bin/ut_crypto_mc



2 changes: 1 addition & 1 deletion .github/workflows/validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DENCTEST=1 -DDEBUG=1 -DCODECOV=1
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} --DTEST_ENC=1 -DDEBUG=1 -DCODECOV=1

- name: Build
# Build your program with the given configuration
Expand Down
93 changes: 40 additions & 53 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,80 +15,67 @@
# NASA IV&V
# [email protected]


#cmake_minimum_required(VERSION 2.6.4)
cmake_minimum_required(VERSION 3.14.0)
project(CRYPTO C)

#
# Define Build Flags
# The default value is captured in line, change with flag `-DXYZ=1`
# For flags with the same prefix, one or more may be enabled
#
OPTION(DEBUG "Debug" OFF) # Disabled by default, enable with: -DDEBUG=ON
OPTION(MYSQL "Mysql" OFF) # Disabled by default, enable with: -DMYSQL=ON
OPTION(LIBGCRYPT "Libgcrypt" ON) # Enabled by default, disable with: -DLIBGCRYPT=OFF
OPTION(KMCCRYPTO "KmcCrypto" OFF) # Disabled by default, enable with: -DKMCCRYPTO=ON
OPTION(ENCTEST "Encryption-Tests" OFF) # Disabled by default, enable with: -DENCTEST=ON
OPTION(CODECOV "Code-Coverage" OFF) # Disabled by default, enable with: -DCODECOV=ON
OPTION(SYSTEM_INSTALL "SystemInstall" OFF) #Disabled by default, enable with: -DSYSTEM_INSTALL=ON
OPTION(SA_INTERNAL "SA Internal" ON) # Enabled by default, disable with: -DSA_INTERNAL=OFF
OPTION(SUPPORT "Support" OFF) # Disabled by default, enable with: --DSUPPORT=ON
option(CODECOV "Code Coverage" OFF)
option(CRYPTO_LIBGCRYPT "Cryptography Module - Libgcrypt" ON)
option(CRYPTO_KMC "Cryptography Module - KMC" OFF)
option(DEBUG "Debug" OFF)
option(SA_INTERNAL "Security Association - Internal" ON)
option(SA_MARIADB "Security Association - MariaDB" OFF)
option(SUPPORT "Support" OFF)
option(SYSTEM_INSTALL "SystemInstall" OFF)
option(TEST "Test" OFF)
option(TEST_ENC "Tests - Encryption" OFF)

IF(NOT DEFINED CFE_SYSTEM_PSPNAME)
# Not cFE / cFS
set(CMAKE_INSTALL_RPATH "$ORIGIN/../lib")
set(CMAKE_INSTALL_PREFIX ${PROJECT_SOURCE_DIR}/install)
ENDIF()
#
# Build Flag Logic
#
if(CODECOV)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
endif()

IF(CRYPTO_SUBMODULE_INSTALL) #If building CryptoLib as a submodule of another build system (EG, JPL KMC, Nasa NOS3, etc...)
set(CMAKE_INSTALL_PREFIX ${CRYPTO_SUBMODULE_INSTALL})
ENDIF()
if(DEBUG)
add_definitions(-DDEBUG -DOCF_DEBUG -DFECF_DEBUG -DSA_DEBUG -DPDU_DEBUG -DCCSDS_DEBUG -DTC_DEBUG -DMAC_DEBUG -DTM_DEBUG)
add_compile_options(-ggdb)
endif()

IF(SYSTEM_INSTALL)
if(SYSTEM_INSTALL)
set(CMAKE_INSTALL_PREFIX /usr/local)
ENDIF()


IF(DEBUG)
ADD_DEFINITIONS(-DDEBUG -DOCF_DEBUG -DFECF_DEBUG -DSA_DEBUG -DPDU_DEBUG -DCCSDS_DEBUG -DTC_DEBUG -DMAC_DEBUG -DTM_DEBUG)
add_compile_options(-ggdb)
ENDIF(DEBUG)
elseif(NOT DEFINED CFE_SYSTEM_PSPNAME)
# Not cFE / cFS
set(CMAKE_INSTALL_RPATH "$ORIGIN/../lib")
set(CMAKE_INSTALL_PREFIX ${PROJECT_SOURCE_DIR}/install)
endif()

IF(ENCTEST)
ADD_DEFINITIONS(-DENCTEST)
ENDIF(ENCTEST)
if(TEST_ENC)
# Can't run an additional set of tests without `TEST` enabled
set(TEST ON)
endif()

if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
if(TEST)
include(CTest)
enable_testing()
endif()

#
# Project Specifics
#
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Werror -g -O0")

if(CODECOV)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
endif()

include_directories(include)
add_subdirectory(src)

# The shared OSAL and cFE include directories should always be used
# Note that this intentionally does NOT include PSP-specific includes, just the generic
# Only include cFS/NOS3 directories if env var is defined
IF(DEFINED CFE_SYSTEM_PSPNAME)
include_directories(${CFECORE_SOURCE_DIR}/src/inc)
include_directories(${CFEPSP_SOURCE_DIR}/fsw/inc)
ADD_DEFINITIONS(-DNOS3)
endif()

if(NOT DEFINED ${PROJECT_BINARY_DIR})
set(PROJECT_BINARY_DIR ${CMAKE_CURRENT_SOURCE_DIR}/build)
endif()

IF(SUPPORT)
if(SUPPORT)
add_subdirectory(support)
ENDIF()

add_subdirectory(src)
endif()

if((CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME OR MYPROJECT_BUILD_TESTING) AND BUILD_TESTING)
if(TEST)
add_subdirectory(test)
endif()
60 changes: 27 additions & 33 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,66 +18,61 @@
include_directories(../include)

aux_source_directory(core LIB_SRC_FILES)
if(MYSQL)
aux_source_directory(sa/mariadb MARIADB_FILES)
list(APPEND LIB_SRC_FILES ${MARIADB_FILES})
else()
aux_source_directory(sa/mariadb_stub MARIADB_FILES)
list(APPEND LIB_SRC_FILES ${MARIADB_FILES})
endif()

if(SA_INTERNAL)
aux_source_directory(sa/internal SA_INTERNAL_FILES)
list(APPEND LIB_SRC_FILES ${SA_INTERNAL_FILES})
else()
aux_source_directory(sa/internal_stub SA_INTERNAL_FILES)
list(APPEND LIB_SRC_FILES ${SA_INTERNAL_FILES})
endif()

if(LIBGCRYPT)
if(CRYPTO_LIBGCRYPT)
aux_source_directory(crypto/libgcrypt LIBGCRYPT_FILES)
list(APPEND LIB_SRC_FILES ${LIBGCRYPT_FILES})
else()
aux_source_directory(crypto/libgcrypt_stub LIBGCRYPT_FILES)
list(APPEND LIB_SRC_FILES ${LIBGCRYPT_FILES})
endif()

if(KMCCRYPTO)
if(CRYPTO_KMC)
aux_source_directory(crypto/kmc KMC_FILES)
list(APPEND LIB_SRC_FILES ${KMC_FILES})
else()
aux_source_directory(crypto/kmc_stub KMC_FILES)
list(APPEND LIB_SRC_FILES ${KMC_FILES})
endif()

if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
include(CTest)
enable_testing()
if(SA_INTERNAL)
aux_source_directory(sa/internal SA_INTERNAL_FILES)
list(APPEND LIB_SRC_FILES ${SA_INTERNAL_FILES})
else()
aux_source_directory(sa/internal_stub SA_INTERNAL_FILES)
list(APPEND LIB_SRC_FILES ${SA_INTERNAL_FILES})
endif()

if(SA_MARIADB)
aux_source_directory(sa/mariadb MARIADB_FILES)
list(APPEND LIB_SRC_FILES ${MARIADB_FILES})
else()
aux_source_directory(sa/mariadb_stub MARIADB_FILES)
list(APPEND LIB_SRC_FILES ${MARIADB_FILES})
endif()

# Create the app module
IF(DEFINED CFE_SYSTEM_PSPNAME)
if(DEFINED CFE_SYSTEM_PSPNAME)
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/cpu${TGTSYS_${SYSVAR}}/${INSTALL_SUBDIR}")
add_cfe_app(Crypto ${LIB_SRC_FILES})
ELSE()
else()
# Standalone build
add_library(Crypto SHARED ${LIB_SRC_FILES})
ENDIF()
endif()

if(LIBGCRYPT)
if(CRYPTO_LIBGCRYPT)
target_link_libraries(Crypto gcrypt)
endif()

if(KMCCRYPTO)
if(CRYPTO_KMC)
target_link_libraries(Crypto curl)
endif()

if(MYSQL)
if(SA_MARIADB)
execute_process(COMMAND mysql_config --cflags
OUTPUT_VARIABLE MYSQL_CFLAGS OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND mysql_config --libs
OUTPUT_VARIABLE MYSQL_LIBS OUTPUT_STRIP_TRAILING_WHITESPACE)

target_compile_options(Crypto PUBLIC ${MYSQL_CFLAGS})
target_link_libraries(Crypto ${MYSQL_LIBS})
endif()
Expand All @@ -89,21 +84,20 @@ add_custom_command(TARGET Crypto POST_BUILD
COMMENT "Created ${PROJECT_BINARY_DIR}/lib/libCrypto.so"
)


IF(DEFINED CFE_SYSTEM_PSPNAME)
if(DEFINED CFE_SYSTEM_PSPNAME)
install(TARGETS Crypto
DESTINATION ${CMAKE_INSTALL_PREFIX}/cpu${TGTSYS_${SYSVAR}}/${INSTALL_SUBDIR})
ELSE()
else()
install(TARGETS Crypto
DESTINATION ${CMAKE_INSTALL_PREFIX}/lib
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_PREFIX}/include)
ENDIF()
endif()

IF(MYSQL)
if(SA_MARIADB)
file(GLOB MYSQL_SCRIPTS sa/sadb_mariadb_sql/*.sql)
file(GLOB MYSQL_TEST_SCRIPTS sa/test_sadb_mariadb_sql/*.sql)
install(FILES ${MYSQL_SCRIPTS}
DESTINATION ${CMAKE_INSTALL_PREFIX}/etc/sadb_mariadb_sql)
install(FILES ${MYSQL_TEST_SCRIPTS}
DESTINATION ${CMAKE_INSTALL_PREFIX}/test/test_sadb_mariadb_sql)
endif()
endif()
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ static CryptographyInterfaceStruct cryptography_if;

CryptographyInterface get_cryptography_interface_libgcrypt(void)
{
fprintf(stderr,"ERROR: Loading libgcrypt cryptography interface stub source code. Rebuild CryptoLib with -DLIBGCRYPT=ON to use proper libgcrypt implementation.\n");
fprintf(stderr,"ERROR: Loading libgcrypt cryptography interface stub source code. Rebuild CryptoLib with -DCRYPTO_LIBGCRYPT=ON to use proper libgcrypt implementation.\n");
return &cryptography_if;
}
2 changes: 1 addition & 1 deletion src/sa/internal_stub/sadb_routine_inmemory.stub.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ static SadbRoutineStruct sadb_routine;

SadbRoutine get_sadb_routine_inmemory(void)
{
fprintf(stderr,"ERROR: Loading internal stub source code. Rebuild CryptoLib with -DMYSQL=OFF to use proper internal implementation.\n");
fprintf(stderr,"ERROR: Loading internal stub source code. Rebuild CryptoLib with -DSA_MARIADB=OFF to use proper internal implementation.\n");
return &sadb_routine;
}
2 changes: 1 addition & 1 deletion src/sa/mariadb_stub/sadb_routine_mariadb.stub.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ static SadbRoutineStruct sadb_routine;

SadbRoutine get_sadb_routine_mariadb(void)
{
fprintf(stderr,"ERROR: Loading mariadb stub source code. Rebuild CryptoLib with -DMYSQL=ON to use proper MariaDB implementation.\n");
fprintf(stderr,"ERROR: Loading mariadb stub source code. Rebuild CryptoLib with -DSA_MARIADB=ON to use proper MariaDB implementation.\n");
return &sadb_routine;
}
12 changes: 6 additions & 6 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ add_test(NAME UT_TM_PROCESS
# COMMAND ${PROJECT_BINARY_DIR}/bin/ut_mariadb
# WORKING_DIRECTORY ${PROJECT_TEST_DIR})

if(${ENCTEST})
if(TEST_ENC)
add_test(NAME ET_DT_VALIDATION
COMMAND ${PROJECT_BINARY_DIR}/bin/et_dt_validation
WORKING_DIRECTORY ${PROJECT_TEST_DIR})
Expand All @@ -66,13 +66,13 @@ endif()
include_directories(include)
include_directories(../include)

if(${ENCTEST})
if(TEST_ENC)
find_package (Python3 REQUIRED COMPONENTS Interpreter Development)
execute_process(COMMAND pip3 show pycryptodome RESULT_VARIABLE EXIT_CODE OUTPUT_QUIET)
if(NOT ${EXIT_CODE} EQUAL 0)
message(FATAL_ERROR "The \"pycryptodome\" Python3 package is not installed, and is required for ENCTEST.")
message(FATAL_ERROR "The \"pycryptodome\" Python3 package is not installed, and is required for TEST_ENC.")
endif()
endif(${ENCTEST})
endif()

aux_source_directory(core UTIL_SRC_FILES)
aux_source_directory(tests APP_SRC_FILES)
Expand All @@ -81,15 +81,15 @@ file( GLOB SOURCE_FILES tests/*.c)
foreach(SOURCE_PATH ${SOURCE_FILES})
get_filename_component(EXECUTABLE_NAME ${SOURCE_PATH} NAME_WE)

if((NOT ${ENCTEST}) AND ${EXECUTABLE_NAME} STREQUAL et_dt_validation)
if((NOT TEST_ENC) AND ${EXECUTABLE_NAME} STREQUAL et_dt_validation)
continue()
else()
add_executable(${EXECUTABLE_NAME} ${SOURCE_PATH})
target_sources(${EXECUTABLE_NAME} PRIVATE core/shared_util.c)
target_link_libraries(${EXECUTABLE_NAME} LINK_PUBLIC Crypto pthread)
endif()

if(${ENCTEST} AND ${EXECUTABLE_NAME} STREQUAL et_dt_validation)
if(TEST_ENC AND ${EXECUTABLE_NAME} STREQUAL et_dt_validation)
target_link_libraries(${EXECUTABLE_NAME} PUBLIC ${Python3_LIBRARIES})
target_include_directories(${EXECUTABLE_NAME} PUBLIC ${Python3_INCLUDE_DIRS})
find_library(${Python3_LIBRARIES} pycryptodome)
Expand Down
2 changes: 1 addition & 1 deletion test/tests/ut_mysql_m_tls_connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
i) ssl_cert=/etc/pki/tls/certs/local-test-cert.pem
ii) ssl_key=/etc/pki/tls/private/local-test-key.pem
iii) ssl_ca=/etc/pki/tls/certs/ammos-ca-bundle.crt
3)IMPORTANT:Build with "cmake -DMYSQL=ON ."
3)IMPORTANT:Build with "cmake -DSA_MARIADB=ON ."
*
IMPORTANT:The database must have similar configuration for this test to succeed:
MariaDB server to use the standard host-based <your_server_hots_name>.
Expand Down
Loading

0 comments on commit bb71561

Please sign in to comment.