restructure for cmake build.

This commit is contained in:
2025-05-05 10:59:23 -04:00
parent 0d1a549eeb
commit 52a4511116
6 changed files with 66 additions and 38 deletions

View File

@@ -1,18 +1,13 @@
# CMakeList.txt : CMake project for xtfs, include source and define # CMakeList.txt : CMake project for xtfs, include source and define
# project specific logic here. # project specific logic here.
# #
cmake_minimum_required (VERSION 3.16) cmake_minimum_required (VERSION 3.16)
project ("primetest") project (primetest VERSION 1.0 LANGUAGES CXX)
# Add source to this project's executable.s set_property(TARGET PROPERTY CXX_STANDARD 21)
set_property(TARGET PROPERTY CXX_STANDARD_REQUIRED ON)
add_executable (primetest "src/primetest.cpp") set_property(TARGET PROPERTY CXX_EXTENSIONS OFF)
set_property(TARGET primetest PROPERTY CXX_STANDARD 17) add_subdirectory(src)
set_property(TARGET primetest PROPERTY CXX_STANDARD_REQUIRED ON)
set_property(TARGET primetest PROPERTY CXX_EXTENSIONS OFF)
# TODO: Add tests and install targets if needed.

8
src/CMakeLists.txt Normal file
View File

@@ -0,0 +1,8 @@
# CMakeList.txt
add_executable(primetest primetest.cpp)
add_subdirectory(prime)
target_link_libraries( primetest PRIVATE prime )

16
src/prime/CMakeLists.txt Normal file
View File

@@ -0,0 +1,16 @@
# CMakeList.txt
add_library(prime "")
target_sources(prime
PRIVATE
${CMAKE_CURRENT_LIST_DIR}/prime.cpp
PUBLIC
${CMAKE_CURRENT_LIST_DIR}/prime.hpp
)
target_include_directories(prime
PUBLIC
${CMAKE_CURRENT_LIST_DIR}
)

17
src/prime/prime.cpp Normal file
View File

@@ -0,0 +1,17 @@
#include "prime.hpp"
int Prime::count(int n){
int cntout = 0;
for( int icnt = 2; ( icnt <= n ); icnt++ ){
int ts = 0;
for ( int it=icnt; it > 1; --it ){
if( (icnt % it) == 0 ) {
ts = ts + 1;
}
}
if( ts==1 ){
cntout = cntout + 1;
}
}
return cntout;
}

9
src/prime/prime.hpp Normal file
View File

@@ -0,0 +1,9 @@
#ifndef PRIME_HPP
#define PRIME_HPP
class Prime {
public:
static int count(int n);
};
#endif

View File

@@ -1,27 +1,10 @@
#include<iostream> #include<iostream>
#include<prime.hpp>
using std::cout; using std::cout;
using std::endl;
class Solution {
public:
static int countPrime(int n){
int cntout = 0;
for( int icnt = 2; ( icnt <= n ); icnt++ ){
int ts = 0;
for ( int it=icnt; it > 1; --it ){
if( (icnt % it) == 0 ) {
ts = ts + 1;
}
}
if( ts==1 ){
cntout = cntout + 1;
}
}
return cntout;
}
};
int main(int argc, char** argv){ int main(int argc, char** argv){
std::cout << Solution::countPrime(50000) << std::endl; std::cout << Prime::count(50000) << std::endl;
} }